Skip to content

vchuravy/HashArrayMappedTries.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HashArrayMappedTries.jl

A HashArrayMappedTrie or HAMT for short, is a data-structure that can be used efficient persistent hash tables.

Usage

dict = HAMT{Int, Int}()
dict[1] = 1
delete!(dict, 1)

Persitency

dict = HAMT{Int, Int}()
dict = insert(dict, 1, 1)
dict = delete(dict, 1)

Robustness against hash collisions

The HAMT is robust to hash collision as long as they are not collection. As an example of a devious hash take.

mutable struct CollidingHash
end
Base.hash(::CollidingHash, h::UInt) = hash(UInt(0), h)

ch1 = CollidingHash()
ch2 = CollidingHash()

For all h hash(ch1, h) == hash(ch2, h). Base.Dict is robust under those hashes as well.

dict = Dict{CollidingHash, Nothing}()
dict[CollidingHash()] = nothing
dict[CollidingHash()] = nothing
display(dict)

# Dict{CollidingHash, Nothing} with 2 entries:
#  CollidingHash() => nothing
#  CollidingHash() => nothing

Whereas HAMT.

dict = HAMT{CollidingHash, Nothing}()
dict[CollidingHash()] = nothing
dict[CollidingHash()] = nothing
ERROR: Perfect hash collision detected

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages