@@ -22,7 +22,6 @@ import Data.Bits (shiftR)
22
22
import Data.Hashable.Class
23
23
import GHC.Generics
24
24
25
-
26
25
-- Type without constructors
27
26
instance GHashable arity V1 where
28
27
ghashWithSalt _ salt _ = hashWithSalt salt ()
@@ -52,25 +51,23 @@ instance Hashable1 f => GHashable One (Rec1 f) where
52
51
instance (Hashable1 f , GHashable One g ) => GHashable One (f :.: g ) where
53
52
ghashWithSalt targs salt = liftHashWithSalt (ghashWithSalt targs) salt . unComp1
54
53
55
- class GSum arity f where
56
- hashSum :: HashArgs arity a -> Int -> Int -> Int -> f a -> Int
54
+ class SumSize f => GSum arity f where
55
+ hashSum :: HashArgs arity a -> Int -> Int -> f a -> Int
56
+ -- hashSum args salt offset value = ...
57
57
58
- instance (GSum arity a , GSum arity b , SumSize a , SumSize b ) => GHashable arity (a :+: b ) where
59
- ghashWithSalt toHash salt = hashSum toHash salt 0 size
60
- where size = unTagged (sumSize :: Tagged (a :+: b ))
58
+ instance (GSum arity a , GSum arity b ) => GHashable arity (a :+: b ) where
59
+ ghashWithSalt toHash salt = hashSum toHash salt 0
61
60
62
61
instance (GSum arity a , GSum arity b ) => GSum arity (a :+: b ) where
63
- hashSum toHash ! salt ! code ! size s = case s of
64
- L1 x -> hashSum toHash salt code sizeL x
65
- R1 x -> hashSum toHash salt (code + sizeL) sizeR x
62
+ hashSum toHash ! salt ! offset s = case s of
63
+ L1 x -> hashSum toHash salt offset x
64
+ R1 x -> hashSum toHash salt (offset + sizeL) x
66
65
where
67
- sizeL = size `shiftR` 1
68
- sizeR = size - sizeL
66
+ sizeL = unTagged (sumSize :: Tagged a )
69
67
{-# INLINE hashSum #-}
70
68
71
69
instance GHashable arity a => GSum arity (C1 c a ) where
72
- -- hashSum toHash !salt !code _ (M1 x) = ghashWithSalt toHash (hashWithSalt salt code) x
73
- hashSum toHash ! salt ! code _ (M1 x) = hashWithSalt salt (ghashWithSalt toHash code x)
70
+ hashSum toHash ! salt ! offset (M1 x) = ghashWithSalt toHash (hashWithSalt salt offset) x
74
71
{-# INLINE hashSum #-}
75
72
76
73
class SumSize f where
0 commit comments