3 ms·
> Closed hashing (aka open addressing, yes it's confusing) hashtables take hash(input) and just do it again to get a second location, and put it there. Repeat N
by thomasahle 4y ago
> Closed hashing (aka open addressing, yes it's confusing) hashtables take hash(input) and just do it again to get a second location, and put it there. Repeat N times for N hash(hash(hash(...))) collisions. Dense, but needs more complex logic to figure out when to stop looking / what to do when deleting because anything could be at location X due to a collision with something else.
That's not really the common way to do open addressing [1].
Normally you either use (1) linear probing, where you look at `h(input)`, then `h(input)+1`, ... and so on. This is nice because of data locality. Though you need a good hash function for it to work well. Or (2) Double hashing, where you first look at `h_1(input)` then `h_1(input) + h_2(input)` then `h_1(input) + 2*h_2(input)` and so on. I'm not saying repeatedly hashing `hash(hash(hash(...)))` doesn't work, but it's more expensive to call the hash function so many times.
[1]: https://en.wikipedia.org/wiki/Open_addressing https://en.wikipedia.org/wiki/Open_addressing
- Groxx 4y agoyea, I should probably use the "you just take the value and push it over there (idx+1)!" as an intro, it's a simpler concept too. thanks!