Data.Hashable

lib/Data/Hashable.gob

No module comment.

class Hasher h

A hash function's state, fed a key's parts in order. Every method returns the next state, and a caller uses each state once: after passing a state to hashInt, hashBytes or finishHash, it uses only the state returned. Hashing the same parts from the same seed then gives the same hash, for an implementation of either kind:

  • one that returns a new value, which the optimizer can keep in registers, so that a key hashed in one inlined call stores nothing to memory;
  • one that changes the state in place and returns it, which costs a store per field but no allocation when a step is too large to inline.

A hasher takes a whole word or a whole run of bytes per call, never a byte at a time: every hash worth having mixes 64 bits per step, and one call per byte costs a call per byte whatever the function is.

A hasher is fed a key's parts, not a stream. Each run of bytes is one part, and the hasher marks where it ends, so a Hash instance hands over a string or a byte array as one run and adds nothing to delimit it. Marking the end costs Hash.FxHash and Hash.FoldHash nothing: their byte functions read a run from both ends and fold in its length, which is also why a run cannot be fed to them in pieces.

fun startHash : [Hasher h] fun(Int) -> h

Returns a fresh state for a table whose seed is seed. Two states made from one seed hash equal inputs to equal values.

fun hashInt : [Hasher h] fun(h, Int) -> h

Absorbs one word. Every scalar a key holds -- an Int, a Char, a Byte, a constructor's tag, a length -- goes in through here.

fun hashBytes : [Hasher h] fun(h, ByteView) -> h

Absorbs the bytes of a view as one run, and where the run ends. Two keys that split the same bytes into runs differently are different inputs, and a run fed in pieces need not hash as the whole run does.

fun finishHash : [Hasher h] fun(h) -> Int

Returns the hash of everything absorbed.

class Hash a : Eq a
fun hashInto : [Hash a, Hasher h] fun(a, h) -> h
instance Hash Unit