dataframe-core-2.4.0.0: Core data structures for the dataframe library.
Safe HaskellNone
LanguageHaskell2010

DataFrame.Internal.Hash

Description

A poor-man's hash used by Grouping to bucket rows without depending on hashable. Each value is folded into an Int with an FxHash-style step (rotate, xor, multiply); small and not cryptographic.

Synopsis

Documentation

fnvOffset :: Int Source #

FNV-1a 64-bit offset basis (used as the initial accumulator). The literal is unsigned and exceeds Int range, so we round-trip through Word64 to get the well-defined two's-complement bit pattern.

nullSalt :: Int Source #

Sentinel mixed in for a null slot, so Nothing does not hash the same as a present value with equal bits (e.g. Just 0). A fixed distinctive constant keeps null hashing deterministic; a real value equal to it collides only rarely.

mixInt :: Int -> Int -> Int Source #

Mix an Int into the accumulator with an FxHash-style step. The rotate diffuses each value's bits before the next is folded in, avoiding the structured collisions a plain xor-then-multiply produces on small/adjacent group keys.

mixDouble :: Int -> Double -> Int Source #

Mix a Double into the accumulator. Loses sub-millisecond precision but matches the bucketing the old hashable-based code used.

mixText :: Int -> Text -> Int Source #

Mix a Text value into the accumulator over its raw UTF-8 bytes, eight at a time. Reading a whole Word64 per step cuts the multiply count ~8x on long keys while staying collision-equivalent (UTF-8 is injective).

mixBytes :: Int -> Array -> Int -> Int -> Int Source #

Mix a raw UTF-8 byte slice [off, off+len) of a Array into the accumulator, eight bytes at a time. The shared kernel behind mixText and the packed-text hash path, so the two never drift.

mixShow :: Show a => Int -> a -> Int Source #

Fallback for arbitrary Show-able values. Slower but covers types without a dedicated combinator (e.g. Day, UTCTime).