|
-- | /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 thaw one of the arrays and play mutation games. Say we have
and we search for 3. Then we can mutate the array to
That is, swap the 3 to the front and replace it with undefined. Then start the next scan in the second slot.
unordered-containers/Data/HashMap/Internal.hs
Lines 2197 to 2202 in 352591a
Once we've identified an element of
ary2to correspond to an element ofary1, it would be nice if we wouldn't check the same element again against the subsequent elements ofary1.@treeowl had a neat idea for that in #282 (comment):