packages feed

smallarray 0.1.0 → 0.2.0

raw patch · 3 files changed

+24/−4 lines, 3 filesdep +hashable

Dependencies added: hashable

Files

Data/ByteArray.hs view
@@ -35,6 +35,7 @@     , Elt(..)     , unsafeFreeze     , asPtr+    , hashByteArray     ) where  @@ -61,9 +62,11 @@ import Control.Monad.ST import Control.DeepSeq +import qualified Data.Hashable as H+ #if defined(USING_GHC) -- in GHC prior to 7, the built-in length primitive on ByteArrays would--- round up to the nearest 4-byte word. After it returns the amount request+-- round up to the nearest 4-byte word. After v7 it returns the amount requested -- during allocation, which is what we want. -- Prior to GHC 7 we carry around a length. #if __GLASGOW_HASKELL__ > 612@@ -127,6 +130,12 @@ -- | Only for use with pinned arrays. asPtr :: ByteArray -> (Ptr a -> IO b) -> IO b +-- | Hash the contents of the ByteArray+hashByteArray :: ByteArray -> Int++-- other hashing functions can be easily provided, say+-- hashing a part of the array or incremental hashing+ #if defined(USING_GHC)  #ifdef HAS_LENGTH@@ -167,6 +176,8 @@ touch :: a -> IO () touch x = IO $ \s-> case touch# x s of s' -> (# s', () #) +hashByteArray arr = H.hashByteArray (unArray arr) 0 (length arr)+ #define deriveElt(Typ, Ct, rd, wrt, ix, sz) \ instance Elt Typ where { \     read ary (I# n) = ST (\s -> case rd (unMArray ary) n s of \@@ -213,6 +224,11 @@  length (ByteArray _ n) = n lengthM (MutableByteArray _ n) = n++hashByteArray arr =+    unsafePerformIO $+    withArrayPtr arr $ \ptr ->+    H.hashPtr ptr 0 (length arr)  #define deriveElt(Typ) \ instance Elt Typ where { \
Data/SmallArray/Internal.hs view
@@ -25,7 +25,7 @@ -- naming. module Data.SmallArray.Internal where -import Prelude hiding (length)+import Prelude hiding (length, elem) import qualified Prelude  import Control.Exception (assert)@@ -38,6 +38,7 @@ import Data.Word  import Control.DeepSeq+import qualified Data.Hashable as H  -- | A simple array. Indexing starts from zero. newtype Array a@@ -59,6 +60,9 @@ instance (Eq a, Elt a) => Eq (Array a) where     {-# SPECIALIZE instance Eq (Array Word8) #-}     (==) = eqArray++instance H.Hashable (Array a) where+    hash (A bArr) = B.hashByteArray bArr  eqArray :: (Eq a, Elt a) => Array a -> Array a -> Bool eqArray a b
smallarray.cabal view
@@ -3,7 +3,7 @@ -- See the Haskell package versioning policy -- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for -- standards guiding when and how versions should be incremented.-Version:             0.1.0+Version:             0.2.0  Synopsis:            low-level unboxed arrays, with minimal features. @@ -43,5 +43,5 @@   Other-modules:       Data.ByteArray                        Data.SmallArray.Internal   -  Build-depends:       base < 4.4, deepseq >= 1.1 && < 1.2+  Build-depends:       base < 4.4, deepseq >= 1.1 && < 1.2, hashable < 1.1 && >= 1.0.1   ghc-options: -Wall -funbox-strict-fields -O2