@@ -113,7 +113,7 @@ module Data.HashMap.Internal
113113 , Validity (.. )
114114 , Error (.. )
115115 , SubHash
116- , SubHashPath ( .. )
116+ , SubHashPath
117117
118118 -- ** Internals used by the strict version
119119 , Hash
@@ -2495,24 +2495,23 @@ data Error k
24952495-- | A part of a 'Hash' with 'bitsPerSubkey' bits.
24962496type SubHash = Word
24972497
2498- data SubHashPath = Root | Cons ! SubHash ! SubHashPath
2499- deriving (Eq , Show )
2498+ type SubHashPath = [SubHash ]
25002499
25012500valid :: Hashable k => HashMap k v -> Validity k
25022501valid Empty = Valid
2503- valid t = validInternal Root t
2502+ valid t = validInternal [] t
25042503 where
25052504 validInternal p Empty = Invalid INV1_internal_Empty p
25062505 validInternal p (Leaf h l) = validHash p h <> validLeaf p h l
25072506 validInternal p (Collision h ary) = validHash p h <> validCollision p h ary
25082507 validInternal p (BitmapIndexed b ary) = validBitmapIndexed p b ary
25092508 validInternal p (Full ary) = validFull p ary
25102509
2511- validHash p0 h0 = go p0 h0
2510+ validHash p0 h0 = go ( reverse p0) h0
25122511 where
2513- go Root ! _ = Valid
2514- go (Cons sh p) h | h .&. subkeyMask == sh = go p (h `unsafeShiftR` bitsPerSubkey)
2515- | otherwise = Invalid (INV2_misplaced_hash h0) p0
2512+ go [] ! _ = Valid
2513+ go (sh : p) h | h .&. subkeyMask == sh = go p (h `unsafeShiftR` bitsPerSubkey)
2514+ | otherwise = Invalid (INV2_misplaced_hash h0) p0
25162515
25172516 validLeaf p h (L k _) | hash k == h = Valid
25182517 | otherwise = Invalid (INV3_key_hash_mismatch k h) p
@@ -2540,7 +2539,7 @@ valid t = validInternal Root t
25402539 | otherwise = go b
25412540 where
25422541 go 0 = Valid
2543- go b' = validInternal (Cons ( fromIntegral c) p) (A. index ary i) <> go b''
2542+ go b' = validInternal (fromIntegral c : p) (A. index ary i) <> go b''
25442543 where
25452544 c = countTrailingZeros b'
25462545 m = 1 `unsafeShiftL` c
0 commit comments