HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduledata-hash-0.2.0.1Haskell98

Data.Hash.Rolling

Efficient implementation of a rolling hash, i.e., the computation of a hash through a moving window of a fixed size n over some stream. All operations are O(1) (in particular, they do not depend on the size of the window).

Some laws that this type satisfies:

  • currentHash rh == foldl1 combine (lastHashes rh)
  • length (lastHashes rh) <= windowSize rh
  • length (lastHashes $ addAndRoll rh a) == windowSize rh -- whenever length (lastHashes rh) == windowSize rh
  • last (lastHashes $ addAndRoll rh x) == hash a
  • init (lastHashes $ addAndRoll rh a) isSuffixOf (lastHashes rh)
  • 1 type
  • 5 values

The RollingHash type

1 declaration

Construction and manipulation

valueaddAndRoll :: Hashable a => RollingHash a -> a -> RollingHash a
#

addAndRoll x rh adds a new input element and rolls the window one place through the input (if at least n elements were already consumed).

Querying