问题
How does google's sparse hash table handle collisions? i.e. when 2 elements map to the same bucket, how does it decide where to put the new (colliding) element? I'm reading What is the main implementation idea behind sparse hash table? but that answer doesn't cover the collision idea.
回答1:
Your question is answered in the documentation here, specifically:
2c) If
t.sparsetable[i % 32]
is assigned, but to a value other than foo, look att.sparsetable[(i+1) % 32]
. If that also fails, tryt.sparsetable[(i+3) % 32]
, thent.sparsetable[(i+6) % 32]
. In general, keep trying the next triangular number.
You can read about triangular numbers here.
来源:https://stackoverflow.com/questions/31412796/how-does-googles-sparse-hash-table-handle-collisions