vimwiki/tech/hash_table.wiki

27 lines
901 B
Plaintext

= Hash table =
The almighty O(1) accessing data structure. Uses a hash function so really its
only as fast as your hash function. Comes in associate and non-associate
flavors.
== Good For ==
* Crazy fast look ups
== Bad for ==
* Non basic data types (unless you create a really good hash function)
* also see [[quadratic_probing]]
== Optimize ==
One of the ways I like to use these is to hold pointers. That's basically the
idea behind a LRUCache and other types of data-structure caches. They are also
usually an array of linked list buckets. If you can get a perfect hash function
(gperf) then its a wonderful choice, as it will never collide and always only
take O(1) time. Also if you're willing to test a set of common sets of data, you
can choose to not have a linked list set of buckets, however depending on how
you deal with collisions it can get very bad very fast.
[[algorithms]]