Re: How do you make an associative array in C?
Originally Posted by
Pithikos
Code:
array[8407130567]="Athens"
array[597153027]="Sparta"
That ofcourse is not practical as it needs an enormous array. So how do we implement this? Is there some flaw in my thinking?
Choose your array size first, and perform all hash calculations modulo array_size.
When the number of items in your hashtable reaches a certain limit (75% is a common percentage), you grow your hashtable (usually by creating a new larger hash table, re-hashing all the elements in your original into the new, and then discarding the old). Similarly, when the load in your table drops below a certain percentage (e.g 25%), shrink the hashtable in a similar manner.
Here we are, trapped in the amber of the moment. There is no why.
Bookmarks