这是indexloc提供的服务,不要输入任何密码
Skip to content

Hash table

busterwood edited this page Jun 20, 2018 · 5 revisions

Hash tables are data structures that store values with keys using hash codes of the keys. Hash codes are then used as index into an array of entires (key/value pairs).

Chained Hash Tables

A classic way to store entries with the same has code is a linked list. This is not great for modern CPUs as it involves chasing points.

Open-address hashing

Another way to handle storing entries with the same has code is linear probing the array of entries, i.e. check entry N+1 in a loop. This is proven to be faster than chained hash tables on modern CPUs.

Robin Hood Hashing

Robin Hood hashing which is a varient of open-address hashing that gives preference to entries closer to there ideal position in the hash table, minimizing the number of probes that are needed to find the correct entry. There are some interesting articals on Robin Hood Hashing and how to handle deletion. There is an MIT licensed C# implementation available, based on the implementation in Rust.

Robin Hood Hashing also tolerates higher load factors, meaning hash tables tend to be faster, have more constant performance (less variation), use less memory and create less garbage.

Clone this wiki locally