I want to create a hash table that relies on an independent vector data structure in C99. I can do this in C++ with the help of OO, but I’m unsure how to approach this using structs and unions.
I would prefer that any linked examples do not include hash table implementations that have highly complex hashing functions. I do not particularly care about collisions or efficiency of storage. I just want either advice as to how to proceed or a simple example that exemplifies the form rather than function of the respective data structures.
If I infer correctly that you want to implement growing hash tables in a fully generic way, then you’ll need a lot of
voidpointers. A vector isn’t too hard, it just takes a lot of typing:Keep in mind that a generic hash function would have prototype
size_t hash(void const *, size_t), i.e. you need to pass in the size.(Side note: it’s not C++’s OOP features that you’re going to miss; it’s templates, the type safety that they buy, and syntactic sugar such as operator overloading. Take a look at OpenBSD’s
ohashlibrary for more examples.)