散列日志
散列表的工作原理
散列表将数据存储在 桶中。 散列函数 通过取模将每个键映射到桶索引。
A 冲突 发生在两个键落入同一个桶时。好的散列函数均匀分布键;差的(如用字符串长度)会聚集。
试试这些实验:
-
Switch to
lengthhash and add words of different lengths -- see how same-length words always collide -
Switch to
charSumand add anagrams (listen, silent) -- they collide because they have the same character sum - Slide the bucket count down to 2 and watch collisions pile up
- Compare
djb2vsFNV-1adistribution on the same words