packages feed

bytehash 0.1.1.0 → 0.1.1.1

raw patch · 3 files changed

+21/−12 lines, 3 filesdep +containersdep ~primitive

Dependencies added: containers

Dependency ranges changed: primitive

Files

bytehash.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.2 name: bytehash-version: 0.1.1.0+version: 0.1.1.1 synopsis: Universal hashing of bytes description:   Taken together, universal hash functions and a good source of entropy@@ -36,6 +36,7 @@     , entropy >=0.4.1.5 && <0.5     , bytestring >=0.10.8 && <0.12     , transformers >=0.5.6 && <0.7+    , containers >=0.6   hs-source-dirs: src   ghc-options: -O2 -Wall   default-language: Haskell2010
src/Data/Bytes/Hash.hs view
@@ -68,13 +68,6 @@   -> Word32 byteArray !addr !b = bytes addr (Bytes.fromByteArray b) -wordSize :: Int-wordSize = sizeOf (undefined :: Word)--byteSwap :: Word -> Word-{-# inline byteSwap #-}-byteSwap (W# w) = W# (Exts.byteSwap# w)- -- | Statically defined source of entropy. Exactly 16384 bytes. entropy :: Ptr Word8 entropy = Ptr "\
src/Data/Bytes/HashMap.hs view
@@ -22,6 +22,7 @@   , fromList   , fromTrustedList   , fromListWith+  , elements     -- * Used for testing   , HashMapException(..)   , distribution@@ -79,11 +80,26 @@ import qualified Data.Bytes as Bytes import qualified Data.Bytes.Hash as Hash import qualified Data.List as List+import qualified Data.Map.Strict as Map import qualified Data.Primitive as PM import qualified Data.Primitive.Ptr as PM import qualified Data.Primitive.Unlifted.Array as PM import qualified GHC.Exts as Exts +-- | Recover the elements of the hashmap. These are ordered+-- lexicographically by their corresponding keys. That is, this+-- function returns the same output regardless of the entropy used+-- to build the hashmap.+elements :: Map v -> [v]+elements (Map _ _ _ keys vals) = Map.elems (go Map.empty (PM.sizeofSmallArray vals - 1))+  where+  go !acc !ix = case ix of+    (-1) -> acc+    _ ->+      let !k = PM.indexUnliftedArray keys ix+          !v = PM.indexSmallArray vals ix+       in go (Map.insert k v acc) (ix - 1)+ -- | Build a static hash map. This may be used on input that comes -- from an adversarial user. It always produces a perfect hash map. fromList :: CryptHandle -> [(Bytes,v)] -> IO (Map v)@@ -285,13 +301,12 @@   count = List.length @[] xs' :: Int  findUnused :: PM.SmallMutableArray s Bool -> ST s Int-findUnused xs = go 0+findUnused xs = PM.getSizeofSmallMutableArray xs >>= go 0   where-  len = PM.sizeofSmallMutableArray xs-  go !ix = if ix < len+  go !ix !len = if ix < len     then do       PM.readSmallArray xs ix >>= \case-        True -> go (ix + 1)+        True -> go (ix + 1) len         False -> pure ix     else error "findUnused: could not find unused slot"