Skip to content

ancapdev/FNVHash.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FNVHash

Build Status

Implementations of the Fowler–Noll–Vo hash functions. See Wikipedia for details.

Usage

Two variants are implemented, fnv1() and fnv1a(), the latter is preferred for slightly better avalance characteristics

Hashing strings

s = "string to hash"
fnv1a(UInt32, s)  # 0xf474bad3
fnv1a(UInt64, s)  # 0xff0f01f28783a2d3
fnv1a(UInt128, s) # 0xe676f50e87fe52607a2c13a4c192bca3

Hashing byte vectors

data = [0x0, 0x1, 0x2, 0x3]
fnv1a(UInt32, data)  # 0xc3aa51b1
fnv1a(UInt64, data)  # 0x4475327f98e05411
fnv1a(UInt128, data) # 0x66ad33ec62757277b806e89d2ca0ff79

Hashing raw data

data = [0x0, 0x1, 0x2, 0x3]
GC.@preserve data begin
    raw = pointer(data)
    raw_len = sizeof(data)
    fnv1a(UInt32, raw, raw_len)  # 0xc3aa51b1
    fnv1a(UInt64, raw, raw_len)  # 0x4475327f98e05411
    fnv1a(UInt128, raw, raw_len) # 0x66ad33ec62757277b806e89d2ca0ff79
end

About

Fowler–Noll–Vo hash functions Julia package

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages