0
条目
0
冲突
0
最大深度
0
负载因子

散列日志

散列表的工作原理

散列表将数据存储在 中。 散列函数 通过取模将每个键映射到桶索引。

A 冲突 发生在两个键落入同一个桶时。好的散列函数均匀分布键;差的(如用字符串长度)会聚集。

试试这些实验:

  • Switch to length hash and add words of different lengths -- see how same-length words always collide
  • Switch to charSum and 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 djb2 vs FNV-1a distribution on the same words