lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Thu, 16 Apr 2020 at 22:31, 彭健 <bzijiang@gmail.com> wrote:
>
> sorry, i will describe the problem again.
>
> we set  t = {[8] = 1, [16] = 2, [24] = 3, [32] = 4, [14] = 5}
> then t[32] = nil
> then t[13] = 6
>
> here we simply calculate hash_value = hash % size (size = 8)
>
> we found that
> 8 16 24 hash_value = 0, 13 hash_value = 5
> but they are chained together
> 8 --> 13 --> 24 --> 16

I haven't checked the math, but you do realize that when you have hash
slot collisions (8, 16 & 24 all want to go to the same slot), only one
key can go to the "main" slot, the others go to somewhere else....
which could be the main slot for some other key.  you've found a
non-optimal case, but it's not clear if you've made it misbehave.

can you still get all values from the respective keys?

-- 
Javier