-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Combinators for building fast hashing functions.
--   
--   Combinators for building fast hashing functions. Includes hashing
--   functions for all basic Haskell98 types.
@package data-hash
@version 0.2.0.1


-- | Efficient implementation of a rolling hash, i.e., the computation of a
--   hash through a moving window of a fixed size <tt>n</tt> 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:
--   
--   <ul>
--   <li><pre>currentHash rh == foldl1 combine (lastHashes rh)</pre></li>
--   <li><pre>length (lastHashes rh) &lt;= windowSize rh</pre></li>
--   <li><pre>length (lastHashes $ addAndRoll rh a) == windowSize rh --
--   whenever length (lastHashes rh) == windowSize rh</pre></li>
--   <li><pre>last (lastHashes $ addAndRoll rh x) == hash a</pre></li>
--   <li><pre>init (lastHashes $ addAndRoll rh a) <tt>isSuffixOf</tt>
--   (lastHashes rh)</pre></li>
--   </ul>
module Data.Hash.Rolling
data RollingHash a

-- | <tt>rollingHash n</tt> creates a <tt>RollingHash</tt> of window size
--   <tt>n</tt> (for <tt>n &gt; 0</tt>)
rollingHash :: Int -> RollingHash a

-- | <tt>addAndRoll x rh</tt> adds a new input element and rolls the window
--   one place through the input (if at least <tt>n</tt> elements were
--   already consumed).
addAndRoll :: Hashable a => RollingHash a -> a -> RollingHash a
currentHash :: RollingHash a -> Hash

-- | <tt>lastHashes rh</tt> returns the last <tt>n</tt> hashes.
lastHashes :: RollingHash a -> [Hash]
windowSize :: RollingHash a -> Int
instance GHC.Show.Show (Data.Hash.Rolling.RollingHash a)


-- | Combinators for building fast hashing functions.
--   
--   Based on the BuzHash algorithm by Robert Uzgalis (see, e.g. "Hashing
--   concepts and the Java programming language" at
--   <a>http://www.serve.net/buz/hash.adt/java.000.html</a>)
module Data.Hash

-- | A 64-bit hash
data Hash
asWord64 :: Hash -> Word64
hashWord8 :: Word8 -> Hash

-- | <tt>h1 `combine` h2</tt> combines hashes <tt>h1</tt> and <tt>h2</tt>
--   into a new hash.
--   
--   It is used to generate hash functions for complex types. For example:
--   
--   <pre>
--   hashPair :: (Hashable a, Hashable b) =&gt; (a,b) -&gt; Hash
--   hashPair (a,b) = hash a `combine` hash b
--   </pre>
combine :: Hash -> Hash -> Hash
hashWord16 :: Word16 -> Hash
hashWord32 :: Word32 -> Hash
hashWord64 :: Word64 -> Hash
hashInt :: Int -> Hash

-- | Observe that, unlike the other functions in this module,
--   <tt>hashStorable</tt> is machine-dependent (the computed hash depends
--   on endianness, etc.).
hashStorable :: Storable a => a -> Hash
hashFoldable :: (Foldable t, Hashable a) => t a -> Hash
class Hashable a
hash :: Hashable a => a -> Hash
