Hash Array Mapped Trie (HAMT)

前端 未结 4 1017
生来不讨喜
生来不讨喜 2020-12-23 14:40

I am trying to get my head around the details of a HAMT. I\'d have implemented one myself in Java just to understand. I am familiar with Tries and I think I get the main con

4条回答
  •  轮回少年
    2020-12-23 14:58

    There's two sections of the paper I think you might of missed. The first is the bit immediately preceding the bit you quoted:

    Or the key will collide with an existing one. In which case the existing key must be replaced with a sub-hash table and the next 5 bit hash of the existing key computed. If there is still a collision then this process is repeated until no collision occurs.

    So if you have object A in the table and you add object B which clashes, the cell at which their keys clashed will be a pointer to another subtable (where they don't clash).

    Next, Section 3.7 of the paper you linked describes the method for generating a new hash when you run off the end of your first 32 bits:

    The hash function was tailored to give a 32 bit hash. The algorithm requires that the hash can be extended to an arbitrary number of bits. This was accomplished by rehashing the key combined with an integer representing the trie level, zero being the root. Hence if two keys do give the same initial hash then the rehash has a probability of 1 in 2^32 of a further collision.

    If this doesn't seem to explain anything, say and I'll extend this answer with more detail.

提交回复
热议问题