x-lang

← Index

x/type/hash

FNV-1a string hashing, homed on the Hash class.

Class Hash

(Hash fnv-1a s)

Hash a string to a word using the FNV-1a algorithm: FNV-1a 64 on an 8-byte word, FNV-1a 32 on a 4-byte word.

Parameters:

Returns: INTEGER — The FNV-1a hash, the word’s width

Examples:

(= (Hash fnv-1a "a") (Hash fnv-1a "a")) => #t
(str=? (Hash ->hex (Hash fnv-1a "")) (if (< %word-size 8) "811c9dc5" "cbf29ce484222325")) => #t

(Hash ->hex n)

Convert a word to its unsigned hex string, two digits a byte: 16 on an 8-byte word, 8 on a 4-byte word.

Parameters:

Returns: STRING — The word’s bits in hexadecimal

Examples:

(str=? (Hash ->hex 255) (if (< %word-size 8) "000000ff" "00000000000000ff")) => #t
(= (Str8 length (Hash ->hex -1)) (* 2 %word-size)) => #t