2021-09-23 17:54:24 +00:00
|
|
|
= 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 ==
|
|
|
|
|
2021-10-11 03:22:53 +00:00
|
|
|
* Crazy fast look ups
|
2021-09-23 17:54:24 +00:00
|
|
|
|
|
|
|
== Bad for ==
|
|
|
|
|
|
|
|
* Non basic data types (unless you create a really good hash function)
|
|
|
|
|
|
|
|
== 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]]
|