packages feed

hashable 1.2.3.3 → 1.2.4.0

raw patch · 6 files changed

+105/−19 lines, 6 filesdep ~basedep ~criteriondep ~textPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: base, criterion, text

API changes (from Hackage documentation)

- Data.Hashable: class Hashable a where hash = hashWithSalt defaultSalt hashWithSalt salt = ghashWithSalt salt . from
+ Data.Hashable: class Hashable a
- Data.Hashable: hashUsing :: Hashable b => (a -> b) -> Int -> a -> Int
+ Data.Hashable: hashUsing :: (Hashable b) => (a -> b) -> Int -> a -> Int

Files

CHANGES.md view
@@ -1,3 +1,10 @@+## Version 1.2.4.0++ * Add instances for: Unique, Version, Fixed, NonEmpty, Min, Max, Arg,+   First, Last, WrappedMonoid, Option++ * Support GHC 8.0+ ## Version 1.2.3.3   * Support integer-simple.
Data/Hashable/Class.hs view
@@ -38,7 +38,7 @@     ) where  import Control.Exception (assert)-import Data.Bits (bitSize, shiftL, shiftR, xor)+import Data.Bits (shiftL, shiftR, xor) import qualified Data.ByteString as B import qualified Data.ByteString.Internal as B import qualified Data.ByteString.Lazy as BL@@ -51,7 +51,8 @@ import qualified Data.Text.Internal as T import qualified Data.Text.Lazy as TL import Data.Typeable-import Data.Word (Word, Word8, Word16, Word32, Word64)+import Data.Version (Version(..))+import Data.Word (Word8, Word16, Word32, Word64) import Foreign.C (CString) import Foreign.Marshal.Utils (with) import Foreign.Ptr (Ptr, castPtr)@@ -61,7 +62,12 @@ import GHC.Prim (ThreadId#) import System.IO.Unsafe (unsafePerformIO) import System.Mem.StableName+import Data.Unique (Unique, hashUnique) +#if MIN_VERSION_base(4,7,0)+import Data.Fixed (Fixed(..))+#endif+ #ifdef GENERICS import GHC.Generics #endif@@ -81,7 +87,17 @@ import Foreign.C.Types (CInt) #endif -#if !MIN_VERSION_bytestring(0,10,0)+#if !(MIN_VERSION_base(4,8,0))+import Data.Word (Word)+#endif++#if MIN_VERSION_base(4,7,0)+import Data.Bits (finiteBitSize)+#else+import Data.Bits (bitSize)+#endif++#if !(MIN_VERSION_bytestring(0,10,0)) import qualified Data.ByteString.Lazy.Internal as BL  -- foldlChunks #endif @@ -109,6 +125,11 @@ import GHC.Exts (Word(..)) #endif +#if MIN_VERSION_base(4,9,0)+import qualified Data.List.NonEmpty as NE+import Data.Semigroup+#endif+ #include "MachDeps.h"  infixl 0 `hashWithSalt`@@ -215,7 +236,11 @@  instance Hashable Int64 where     hash n+#if MIN_VERSION_base(4,7,0)+        | finiteBitSize (undefined :: Int) == 64 = fromIntegral n+#else         | bitSize (undefined :: Int) == 64 = fromIntegral n+#endif         | otherwise = fromIntegral (fromIntegral n `xor`                                    (fromIntegral n `shiftR` 32 :: Word64))     hashWithSalt = defaultHashWithSalt@@ -238,7 +263,11 @@  instance Hashable Word64 where     hash n+#if MIN_VERSION_base(4,7,0)+        | finiteBitSize (undefined :: Int) == 64 = fromIntegral n+#else         | bitSize (undefined :: Int) == 64 = fromIntegral n+#endif         | otherwise = fromIntegral (n `xor` (n `shiftR` 32))     hashWithSalt = defaultHashWithSalt @@ -322,7 +351,12 @@         inBounds x = x >= fromIntegral (minBound :: Int) && x <= maxInt #endif +#if MIN_VERSION_base(4,9,0)+-- Starting with base-4.9, numerator/denominator don't need 'Integral' anymore+instance Hashable a => Hashable (Ratio a) where+#else instance (Integral a, Hashable a) => Hashable (Ratio a) where+#endif     {-# SPECIALIZE instance Hashable (Ratio Integer) #-}     hash a = hash (numerator a) `hashWithSalt` denominator a     hashWithSalt s a = s `hashWithSalt` numerator a `hashWithSalt` denominator a@@ -412,9 +446,15 @@     hash = hashStableName     hashWithSalt = defaultHashWithSalt +-- Auxillary type for Hashable [a] definition+data SPInt = SP !Int !Int+ instance Hashable a => Hashable [a] where     {-# SPECIALIZE instance Hashable [Char] #-}-    hashWithSalt = foldl' hashWithSalt+    hashWithSalt salt arr = finalise (foldl' step (SP salt 0) arr)+      where+        finalise (SP s l) = hashWithSalt s l+        step (SP s l) x   = SP (hashWithSalt s x) (l + 1)  instance Hashable B.ByteString where     hashWithSalt salt bs = B.inlinePerformIO $@@ -533,3 +573,43 @@ -- identity. combine :: Int -> Int -> Int combine h1 h2 = (h1 * 16777619) `xor` h2++instance Hashable Unique where+    hash = hashUnique+    hashWithSalt = defaultHashWithSalt++instance Hashable Version where+    hashWithSalt salt (Version branch tags) =+        salt `hashWithSalt` branch `hashWithSalt` tags++#if MIN_VERSION_base(4,7,0)+instance Hashable (Fixed a) where+    hashWithSalt salt (MkFixed i) = hashWithSalt salt i+#endif++-- instances formerly provided by 'semigroups' package+#if MIN_VERSION_base(4,9,0)+instance Hashable a => Hashable (NE.NonEmpty a) where+    hashWithSalt p (a NE.:| as) = p `hashWithSalt` a `hashWithSalt` as++instance Hashable a => Hashable (Min a) where+    hashWithSalt p (Min a) = hashWithSalt p a++instance Hashable a => Hashable (Max a) where+    hashWithSalt p (Max a) = hashWithSalt p a++instance (Hashable a, Hashable b) => Hashable (Arg a b) where+    hashWithSalt p (Arg a b) = hashWithSalt p a `hashWithSalt` b++instance Hashable a => Hashable (First a) where+    hashWithSalt p (First a) = hashWithSalt p a++instance Hashable a => Hashable (Last a) where+    hashWithSalt p (Last a) = hashWithSalt p a++instance Hashable a => Hashable (WrappedMonoid a) where+    hashWithSalt p (WrapMonoid a) = hashWithSalt p a++instance Hashable a => Hashable (Option a) where+    hashWithSalt p (Option a) = hashWithSalt p a+#endif
Data/Hashable/Generic.hs view
@@ -17,7 +17,7 @@     (     ) where -import Data.Bits (Bits, shiftR)+import Data.Bits (shiftR) import Data.Hashable.Class import GHC.Generics @@ -43,12 +43,11 @@ class GSum f where     hashSum :: Int -> Int -> Int -> f a -> Int -instance (GSum a, GSum b, GHashable a, GHashable b,-          SumSize a, SumSize b) => GHashable (a :+: b) where+instance (GSum a, GSum b, SumSize a, SumSize b) => GHashable (a :+: b) where     ghashWithSalt salt = hashSum salt 0 size         where size = unTagged (sumSize :: Tagged (a :+: b)) -instance (GSum a, GSum b, GHashable a, GHashable b) => GSum (a :+: b) where+instance (GSum a, GSum b) => GSum (a :+: b) where     hashSum !salt !code !size s = case s of                                     L1 x -> hashSum salt code           sizeL x                                     R1 x -> hashSum salt (code + sizeL) sizeR x
Data/Hashable/SipHash.hs view
@@ -153,7 +153,7 @@   return (fromWord64 w) #endif -#if !MIN_VERSION_base(4,5,0)+#if !(MIN_VERSION_base(4,5,0)) unsafeShiftL :: Word64 -> Int -> Word64 unsafeShiftL = shiftL #endif
benchmarks/Benchmarks.hs view
@@ -98,13 +98,13 @@         withForeignPtr fp1Mb $ \ p1Mb ->         defaultMain         [ bgroup "hashPtr"-          [ bench "5" $ hashPtr p5 5-          , bench "8" $ hashPtr p8 8-          , bench "11" $ hashPtr p11 11-          , bench "40" $ hashPtr p40 40-          , bench "128" $ hashPtr p128 128-          , bench "512" $ hashPtr p512 512-          , bench "2^20" $ hashPtr p1Mb mb+          [ bench "5" $ whnfIO $ hashPtr p5 5+          , bench "8" $ whnfIO $ hashPtr p8 8+          , bench "11" $ whnfIO $ hashPtr p11 11+          , bench "40" $ whnfIO $ hashPtr p40 40+          , bench "128" $ whnfIO $ hashPtr p128 128+          , bench "512" $ whnfIO $ hashPtr p512 512+          , bench "2^20" $ whnfIO $ hashPtr p1Mb mb           ]         , bgroup "hashByteArray"           [ bench "5" $ whnf (hashByteArray ba5 0) 5
hashable.cabal view
@@ -1,5 +1,5 @@ Name:                hashable-Version:             1.2.3.3+Version:             1.2.4.0 Synopsis:            A class for types that can be converted to a hash value Description:         This package defines a class, 'Hashable', for types that                      can be converted to a hash value.  This class@@ -39,7 +39,7 @@ Library   Exposed-modules:   Data.Hashable   Other-modules:     Data.Hashable.Class-  Build-depends:     base >= 4.0 && < 4.9,+  Build-depends:     base >= 4.0 && < 4.10,                      bytestring >= 0.9 && < 0.11   if impl(ghc)     Build-depends:   ghc-prim,@@ -104,7 +104,7 @@   build-depends:     base,     bytestring,-    criterion,+    criterion >= 1.0,     ghc-prim,     siphash,     text