Skip to content

Commit 7e8fc9e

Browse files
committed
fix error in isSubmapOf based on wrong assumption
1 parent 1b3ed0e commit 7e8fc9e

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

Data/HashMap/Base.hs

+7-8
Original file line numberDiff line numberDiff line change
@@ -1477,6 +1477,8 @@ isSubmapOfBy comp = go 0
14771477
-- Insert the collision into a bitmap indexed node and recurse.
14781478
go s t1@(BitmapIndexed {}) t2@(Collision h2 _) =
14791479
go s t1 (BitmapIndexed (mask h2 s) (A.singleton t2))
1480+
go s t1@(BitmapIndexed {}) t2@(Leaf h2 _) =
1481+
go s t1 (BitmapIndexed (mask h2 s) (A.singleton t2))
14801482
go s t1@(Full {}) t2@(Collision h2 _) =
14811483
go s t1 (BitmapIndexed (mask h2 s) (A.singleton t2))
14821484

@@ -1491,10 +1493,9 @@ isSubmapOfBy comp = go 0
14911493
go s (Full ls1) (BitmapIndexed b2 ls2) =
14921494
submapBitmapIndexed (go (s+bitsPerSubkey)) fullNodeMask ls1 b2 ls2
14931495

1494-
-- A collision, bitmap indexed an full node always contain at least two
1495-
-- entries. Hence it cannot be a map of a leaf.
1496+
-- Collision and Full nodes always contain at least two entries. Hence it
1497+
-- cannot be a map of a leaf.
14961498
go _ (Collision {}) (Leaf {}) = False
1497-
go _ (BitmapIndexed {}) (Leaf {}) = False
14981499
go _ (Full {}) (Leaf {}) = False
14991500

15001501

@@ -2189,12 +2190,10 @@ updateOrConcatWithKey f ary1 ary2 = A.run $ do
21892190

21902191
-- | /O(n*m)/ Check if the first array is a subset of the second array.
21912192
subsetArray :: Eq k => (v1 -> v2 -> Bool) -> A.Array (Leaf k v1) -> A.Array (Leaf k v2) -> Bool
2192-
subsetArray cmpV ary1 ary2 = A.length ary1 <= A.length ary2 && go 0 (A.length ary1)
2193+
subsetArray cmpV ary1 ary2 = A.length ary1 <= A.length ary2 && A.all inAry2 ary1
21932194
where
2194-
go !i n
2195-
| i >= n = True
2196-
| otherwise = let (L k1 v1) = A.index ary1 i
2197-
in lookupInArrayCont (\_ -> False) (\v2 _ -> cmpV v1 v2 && go (i+1) n) k1 ary2
2195+
inAry2 (L k1 v1) = lookupInArrayCont (\_ -> False) (\v2 _ -> cmpV v1 v2) k1 ary2
2196+
{-# INLINE inAry2 #-}
21982197

21992198
------------------------------------------------------------------------
22002199
-- Manually unrolled loops

0 commit comments

Comments
 (0)