I'm learning C now coming from knowing perl and a bit python. I did a quick search and found there is no explicit hash/dictionary as in perl/python and I saw people were saying you need a function to look up a hash table. So the fact is C doesn't provide an inherent hash structure and you have to write some function to be able to use hash in C?
Types of Hashing Function in C In this method, the hash function is dependent upon the remainder of a division. Example: elements to be placed in a hash table are 42,78,89,64 and let's take table size as 10.
Section 6.6 of The C Programming Language presents a simple dictionary (hashtable) data structure. I don't think a useful dictionary implementation could get any simpler than this. For your convenience, I reproduce the code here. Note that if the hashes of two strings collide, it may lead to an O(n) lookup time.
The standard C library doesn't include any large, persistent data structures - neither lists, nor trees, nor stacks, nor hashtables.
A data dictionary is a collection of descriptions of the data objects or items in a data model for the benefit of programmers and others who need to refer to them.
Basically, the only data structure that C has are arrays, structs (which is kind of like a map, but the keys must be known at compile time) and unions. Everything else must be coded manually or provided by a library.
It's not part of standard C libraries. Use a library such as Glib.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With