on master help sign in
Factor out Hashable instance for Value
commitf8612d0d4faba8f36e4a8d1872ee61ca860b1d00 authorBryan O'Sullivan <bos@serpentine.com> dateWed 4 Dec 2013, 09:15 (13 years ago) parent1a2a0db
1 file changed+11−8
Data/Aeson/Types/Internal.hs+11−8
Data/Aeson/Types/Internal.hs+11−8
@@ -199,15 +199,18 @@ instance IsString Value where
199199 fromString = String . pack
200200 {-# INLINE fromString #-}
201201
202+hashValue :: Int -> Value -> Int
203+hashValue s (Object o) = H.foldl' hashWithSalt
204+ (s `hashWithSalt` (0::Int)) o
205+hashValue s (Array a) = V.foldl' hashWithSalt
206+ (s `hashWithSalt` (1::Int)) a
207+hashValue s (String str) = s `hashWithSalt` (2::Int) `hashWithSalt` str
208+hashValue s (Number n) = s `hashWithSalt` (3::Int) `hashWithSalt` n
209+hashValue s (Bool b) = s `hashWithSalt` (4::Int) `hashWithSalt` b
210+hashValue s Null = s `hashWithSalt` (5::Int)
211+
202212instance Hashable Value where
203− hashWithSalt s (Object o) = H.foldl' hashWithSalt
204− (s `hashWithSalt` (0::Int)) o
205− hashWithSalt s (Array a) = V.foldl' hashWithSalt
206− (s `hashWithSalt` (1::Int)) a
207− hashWithSalt s (String str) = s `hashWithSalt` (2::Int) `hashWithSalt` str
208− hashWithSalt s (Number n) = s `hashWithSalt` (3::Int) `hashWithSalt` n
209− hashWithSalt s (Bool b) = s `hashWithSalt` (4::Int) `hashWithSalt` b
210− hashWithSalt s Null = s `hashWithSalt` (5::Int)
213+ hashWithSalt = hashValue
211214
212215-- | The empty array.
213216emptyArray :: Value