dhruvbird
dhruvbird

Reputation: 6189

How does google's sparse hash table handle collisions?

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.

Upvotes: 1

Views: 646

Answers (1)

Tony Delroy
Tony Delroy

Reputation: 106196

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 at t.sparsetable[(i+1) % 32]. If that also fails, try t.sparsetable[(i+3) % 32], then t.sparsetable[(i+6) % 32]. In general, keep trying the next triangular number.

You can read about triangular numbers here.

Upvotes: 3

Related Questions