module What4.Utils.IncrHash
( IncrHash
, mkIncrHash
, toIncrHash
, toIncrHashWithSalt
) where
import Data.Bits
import Data.Hashable
newtype IncrHash = IncrHash Int
deriving (Eq,Ord)
instance Semigroup IncrHash where
IncrHash x <> IncrHash y = IncrHash (x `xor` y)
instance Monoid IncrHash where
mempty = IncrHash 0
mappend = (<>)
mkIncrHash :: Int -> IncrHash
mkIncrHash = IncrHash
toIncrHash :: Hashable a => a -> IncrHash
toIncrHash = IncrHash . hash
toIncrHashWithSalt :: Hashable a => Int -> a -> IncrHash
toIncrHashWithSalt s a = IncrHash (hashWithSalt s a)
instance Hashable IncrHash where
hashWithSalt s (IncrHash h) = hashWithSalt s h