Hash.Words

lib/Hash/Words.gob

The word operations the hash functions in Hash share. All of them wrap: a hash is supposed to overflow.

fun fold : fun(Int, Int) -> Int

The xor of the two halves of the unsigned 128-bit product x * y: the "folded multiply" that the multiply-based hashes mix with. The high half is what carries the upper input bits down into the low bits a table indexes by.

fun rotl : fun(Int, Int) -> Int

x rotated by n bits, taken modulo 64. Both shift amounts are masked, so that a rotation by a multiple of 64 shifts by 0 both ways and is x.

fun rotr : fun(Int, Int) -> Int
type Words64 = Words64(ByteView)

bytes read as overlapping little-endian words: Words64(bytes)[at] is the 8 bytes from bytes[at] to bytes[at + 7], and Words32(bytes)[at] the 4 from bytes[at], zero-extended. Indexing panics if the word runs past the end of the view, as indexing bytes would. A view lies inside its storage, so a word inside the view is a load inside the storage.

Each read is one load instruction. Assembling the word a byte at a time with Byte.getLE is simpler, but made string keys about twice as slow in a Map under every hasher here, and 80-byte keys five times as slow.

type Words32 = Words32(ByteView)
fun byteAt : fun(ByteView, Int) -> Int
instance Index Words64
instance Index Words32