lua-users home
lua-l archive

Re: 【lua table】Different hashes are chained together,is it bug?

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


to Javier:

Here is simplified processing, hash_value = hash% size

we set t = {[8] = 1, [16] = 2, [24] = 3, [32] = 4, [14] = 5}

8 16 24 32 mainposition is node[0]
14 mainposition is node[6]

so they will be:   [0]8    [1]nil    [2]nil    [3]nil    [4]24    [5]32    [6]14   [7]16

[0]8 --> [5]32 --> [4]24 --> [7]16 --> NULL
[6]14 --> NULL

then set a[32] = nil
then set a[13] = 6   (13 mainposition is node[5])

it will be 
[0]8 --> [5]13 --> [4]24 --> [7]16 --> NULL  ( Different hashes are chained together, but we can still find 8 13 24 16. It looks normal. )
[6]14 --> NULL

Now the keys of hash_value = 0 and hash_value = 5 will be linked together. Although it does not affect the use, the length of the conflict chain becomes longer  

Does this situation meet the original intention of lua table design?


AltStyle によって変換されたページ (->オリジナル) /