@@ -94,8 +94,6 @@ import qualified Data.Sequence as Seq
94
94
import qualified Data.Set as Set
95
95
import qualified Data.Tree as Tree
96
96
97
- import qualified Data.Text.Internal.Lazy as TL
98
-
99
97
#if __GLASGOW_HASKELL__ >= 703
100
98
import Foreign.C (CSize (.. ))
101
99
#else
@@ -670,13 +668,7 @@ instance Hashable B.ByteString where
670
668
hashPtrWithSalt p (fromIntegral len) (hashWithSalt salt len)
671
669
672
670
instance Hashable BL. ByteString where
673
- hashWithSalt salt = finalise . BL. foldlChunks step (SP salt 0 )
674
- where
675
- finalise (SP s l) = hashWithSalt s l
676
- step (SP s l) bs = unsafeDupablePerformIO $
677
- B. unsafeUseAsCStringLen bs $ \ (p, len) -> do
678
- s' <- hashPtrWithSalt p (fromIntegral len) s
679
- return (SP s' (l + len))
671
+ hashWithSalt = hashLazyByteStringWithSalt
680
672
681
673
#if MIN_VERSION_bytestring(0,10,4)
682
674
instance Hashable BSI. ShortByteString where
@@ -690,12 +682,7 @@ instance Hashable T.Text where
690
682
(hashWithSalt salt len)
691
683
692
684
instance Hashable TL. Text where
693
- hashWithSalt salt = finalise . TL. foldlChunks step (SP salt 0 )
694
- where
695
- finalise (SP s l) = hashWithSalt s l
696
- step (SP s l) (T. Text arr off len) = SP
697
- (hashByteArrayWithSalt (TA. aBA arr) (off `shiftL` 1 ) (len `shiftL` 1 ) s)
698
- (l + len)
685
+ hashWithSalt = hashLazyTextWithSalt
699
686
700
687
-- | Compute the hash of a ThreadId.
701
688
hashThreadId :: ThreadId -> Int
@@ -781,20 +768,6 @@ hashPtr :: Ptr a -- ^ pointer to the data to hash
781
768
-> IO Int -- ^ hash value
782
769
hashPtr p len = hashPtrWithSalt p len defaultSalt
783
770
784
- -- | Compute a hash value for the content of this pointer, using an
785
- -- initial salt.
786
- --
787
- -- This function can for example be used to hash non-contiguous
788
- -- segments of memory as if they were one contiguous segment, by using
789
- -- the output of one hash as the salt for the next.
790
- hashPtrWithSalt :: Ptr a -- ^ pointer to the data to hash
791
- -> Int -- ^ length, in bytes
792
- -> Int -- ^ salt
793
- -> IO Int -- ^ hash value
794
- hashPtrWithSalt p len salt =
795
- fromIntegral `fmap` c_siphash24 k0 (fromSalt salt) (castPtr p)
796
- (fromIntegral len)
797
-
798
771
-- | Compute a hash value for the content of this 'ByteArray#',
799
772
-- beginning at the specified offset, using specified number of bytes.
800
773
hashByteArray :: ByteArray # -- ^ data to hash
@@ -804,37 +777,6 @@ hashByteArray :: ByteArray# -- ^ data to hash
804
777
hashByteArray ba0 off len = hashByteArrayWithSalt ba0 off len defaultSalt
805
778
{-# INLINE hashByteArray #-}
806
779
807
- -- | Compute a hash value for the content of this 'ByteArray#', using
808
- -- an initial salt.
809
- --
810
- -- This function can for example be used to hash non-contiguous
811
- -- segments of memory as if they were one contiguous segment, by using
812
- -- the output of one hash as the salt for the next.
813
- hashByteArrayWithSalt
814
- :: ByteArray # -- ^ data to hash
815
- -> Int -- ^ offset, in bytes
816
- -> Int -- ^ length, in bytes
817
- -> Int -- ^ salt
818
- -> Int -- ^ hash value
819
- hashByteArrayWithSalt ba ! off ! len ! h =
820
- fromIntegral $
821
- c_siphash24_offset k0 (fromSalt h) ba (fromIntegral off) (fromIntegral len)
822
-
823
- k0 :: Word64
824
- k0 = 0x56e2b8a0aee1721a
825
- {-# INLINE k0 #-}
826
-
827
- fromSalt :: Int -> Word64
828
- #if WORD_SIZE_IN_BITS == 64
829
- fromSalt = fromIntegral
830
- #else
831
- fromSalt v = fromIntegral v `xor` k1
832
-
833
- k1 :: Word64
834
- k1 = 0x7654954208bdfef9
835
- {-# INLINE k1 #-}
836
- #endif
837
-
838
780
-- | Combine two given hash values. 'combine' has zero as a left
839
781
-- identity.
840
782
combine :: Int -> Int -> Int
@@ -1078,8 +1020,6 @@ instance Hashable IntSet.IntSet where
1078
1020
instance Hashable1 Seq. Seq where
1079
1021
liftHashWithSalt h s x = F. foldl' h (hashWithSalt s (Seq. length x)) x
1080
1022
1081
- foreign import ccall unsafe " hashable_siphash24_offset" c_siphash24_offset
1082
- :: Word64 -> Word64 -> ByteArray # -> CSize -> CSize -> Word64
1083
1023
1084
1024
-- | @since 1.3.4.0
1085
1025
instance Hashable v => Hashable (Seq. Seq v ) where
@@ -1092,44 +1032,3 @@ instance Hashable1 Tree.Tree where
1092
1032
-- | @since 1.3.4.0
1093
1033
instance Hashable v => Hashable (Tree. Tree v ) where
1094
1034
hashWithSalt = hashWithSalt1
1095
- foreign import ccall unsafe " hashable_siphash24" c_siphash24
1096
- :: Word64 -> Word64 -> Ptr Word8 -> CSize -> IO Word64
1097
- <<<<<<< variant A
1098
- >>>>>>> variant B
1099
-
1100
- hashLazyByteStringWithSalt :: Int -> BL. ByteString -> Int
1101
- hashLazyByteStringWithSalt salt cs0 = unsafePerformIO . allocaArray 5 $ \ v -> do
1102
- c_siphash_init k0 (fromSalt salt) v
1103
- let go ! buffered ! totallen (BL. Chunk c cs) =
1104
- B. unsafeUseAsCStringLen c $ \ (ptr, len) -> do
1105
- let len' = fromIntegral len
1106
- buffered' <- c_siphash24_chunk buffered v (castPtr ptr) len' (- 1 )
1107
- go buffered' (totallen + len') cs
1108
- go buffered totallen _ = do
1109
- _ <- c_siphash24_chunk buffered v nullPtr 0 totallen
1110
- fromIntegral `fmap` peek (v `advancePtr` 4 )
1111
- go 0 0 cs0
1112
-
1113
- foreign import ccall unsafe " hashable_siphash24_chunk" c_siphash24_chunk
1114
- :: CInt -> Ptr Word64 -> Ptr Word8 -> CSize -> CSize -> IO CInt
1115
-
1116
- foreign import ccall unsafe " hashable_siphash_init" c_siphash_init
1117
- :: Word64 -> Word64 -> Ptr Word64 -> IO ()
1118
-
1119
- hashLazyTextWithSalt :: Int -> TL. Text -> Int
1120
- hashLazyTextWithSalt salt cs0 = unsafePerformIO . allocaArray 5 $ \ v -> do
1121
- c_siphash_init k0 (fromSalt salt) v
1122
- let go ! buffered ! totallen (TL. Chunk (T. Text arr off len) cs) = do
1123
- let len' = fromIntegral (len `shiftL` 1 )
1124
- buffered' <- c_siphash24_chunk_offset buffered v (TA. aBA arr)
1125
- (fromIntegral (off `shiftL` 1 )) len' (- 1 )
1126
- go buffered' (totallen + len') cs
1127
- go buffered totallen _ = do
1128
- _ <- c_siphash24_chunk buffered v nullPtr 0 totallen
1129
- fromIntegral `fmap` peek (v `advancePtr` 4 )
1130
- go 0 0 cs0
1131
-
1132
- foreign import ccall unsafe " hashable_siphash24_chunk_offset"
1133
- c_siphash24_chunk_offset
1134
- :: CInt -> Ptr Word64 -> ByteArray # -> CSize -> CSize -> CSize -> IO CInt
1135
- ======= end
0 commit comments