Developing a hash table in Go
Strictly speaking, a hash table is a data structure that stores one or more key and value pairs and uses the hashFunction
of the key to compute an index into an array of buckets or slots, from which the correct value can be retrieved. Ideally, the hashFunction
should assign each key to a unique bucket, provided that you have the required number of buckets.
A good hashFunction
must be able to produce a uniform distribution of hash values because it is inefficient to have unused buckets or big differences in the cardinalities of the buckets. Additionally, the hashFunction
should work consistently and output the same hash value for identical keys because otherwise it would be impossible to find the information you want! If you think that hash tables are not that useful, handy, or clever, you should consider the following: when a hash table has n keys and k buckets, its search speed goes from O (n) for a linear search to O (n/k)! Although the improvement might look...