-
Notifications
You must be signed in to change notification settings - Fork 103
Open
Labels
Description
unordered-containers/Data/HashMap/Internal.hs
Lines 2197 to 2202 in 352591a
| -- | /O(n*m)/ Check if the first array is a subset of the second array. | |
| subsetArray :: Eq k => (v1 -> v2 -> Bool) -> A.Array (Leaf k v1) -> A.Array (Leaf k v2) -> Bool | |
| subsetArray cmpV ary1 ary2 = A.length ary1 <= A.length ary2 && A.all inAry2 ary1 | |
| where | |
| inAry2 (L k1 v1) = lookupInArrayCont (\_ -> False) (\v2 _ -> cmpV v1 v2) k1 ary2 | |
| {-# INLINE inAry2 #-} |
Once we've identified an element of ary2 to correspond to an element of ary1, it would be nice if we wouldn't check the same element again against the subsequent elements of ary1.
@treeowl had a neat idea for that in #282 (comment):
I wouldn't record indices. But we could
thawone of the arrays and play mutation games. Say we have1 2 3 4and we search for
3. Then we can mutate the array toundefined 2 1 4That is, swap the
3to the front and replace it withundefined. Then start the next scan in the second slot.