@@ -1939,7 +1939,26 @@ differenceWithKey f = go_differenceWithKey 0
19391939 go_differenceWithKey _s a@ (Collision hA aryA) (Leaf hB (L kB vB))
19401940 | hA == hB = updateCollision (\ vA -> f kB vA vB) hA kB aryA a
19411941 | otherwise = a
1942- go_differenceWithKey s a@ (BitmapIndexed bA aryA) b@ (Leaf hB _)
1942+ go_differenceWithKey s a@ (Collision hA _) (BitmapIndexed bB aryB)
1943+ | bB .&. m == 0 = a
1944+ | otherwise =
1945+ case A. index# aryB (sparseIndex bB m) of
1946+ (# stB # ) -> go_differenceWithKey (nextShift s) a stB
1947+ where m = mask hA s
1948+ go_differenceWithKey s a@ (Collision hA _) (Full aryB)
1949+ = case A. index# aryB (index hA s) of
1950+ (# stB # ) -> go_differenceWithKey (nextShift s) a stB
1951+ go_differenceWithKey s a@ (BitmapIndexed bA aryA) (BitmapIndexed bB aryB)
1952+ = differenceWithKey_Arrays s bA aryA a bB aryB
1953+ go_differenceWithKey s a@ (Full aryA) (BitmapIndexed bB aryB)
1954+ = differenceWithKey_Arrays s fullBitmap aryA a bB aryB
1955+ go_differenceWithKey s a@ (BitmapIndexed bA aryA) (Full aryB)
1956+ = differenceWithKey_Arrays s bA aryA a fullBitmap aryB
1957+ go_differenceWithKey s a@ (Full aryA) (Full aryB)
1958+ = differenceWithKey_Arrays s fullBitmap aryA a fullBitmap aryB
1959+ go_differenceWithKey _s a@ (Collision hA aryA) (Collision hB aryB)
1960+ = differenceWithKey_Collisions f hA aryA a hB aryB
1961+ go_differenceWithKey s a@ (BitmapIndexed bA aryA) b
19431962 | bA .&. m == 0 = a
19441963 | otherwise = case A. index# aryA i of
19451964 (# ! stA # ) -> case go_differenceWithKey (nextShift s) stA b of
@@ -1953,36 +1972,10 @@ differenceWithKey f = go_differenceWithKey 0
19531972 | stA `ptrEq` stA' -> a
19541973 | otherwise -> BitmapIndexed bA (A. update aryA i stA')
19551974 where
1975+ hB = hashOfLeafOrCollision b
19561976 m = mask hB s
19571977 i = sparseIndex bA m
1958- go_differenceWithKey s a@ (BitmapIndexed bA aryA) b@ (Collision hB _)
1959- | bA .&. m == 0 = a
1960- | otherwise =
1961- case A. index# aryA i of
1962- (# ! st # ) -> case go_differenceWithKey (nextShift s) st b of
1963- Empty | A. length aryA == 2
1964- , (# l # ) <- A. index# aryA (otherOfOneOrZero i)
1965- , isLeafOrCollision l
1966- -> l
1967- | otherwise
1968- -> BitmapIndexed (bA .&. complement m) (A. delete aryA i)
1969- st' | isLeafOrCollision st' && A. length aryA == 1 -> st'
1970- | st `ptrEq` st' -> a
1971- | otherwise -> BitmapIndexed bA (A. update aryA i st')
1972- where
1973- m = mask hB s
1974- i = sparseIndex bA m
1975- go_differenceWithKey s a@ (Full aryA) b@ (Leaf hB _)
1976- = case A. index# aryA i of
1977- (# ! stA # ) -> case go_differenceWithKey (nextShift s) stA b of
1978- Empty ->
1979- let aryA' = A. delete aryA i
1980- bm = fullBitmap .&. complement (1 `unsafeShiftL` i)
1981- in BitmapIndexed bm aryA'
1982- stA' | stA `ptrEq` stA' -> a
1983- | otherwise -> Full (updateFullArray aryA i stA')
1984- where i = index hB s
1985- go_differenceWithKey s a@ (Full aryA) b@ (Collision hB _)
1978+ go_differenceWithKey s a@ (Full aryA) b
19861979 = case A. index# aryA i of
19871980 (# ! stA # ) -> case go_differenceWithKey (nextShift s) stA b of
19881981 Empty ->
@@ -1991,26 +1984,9 @@ differenceWithKey f = go_differenceWithKey 0
19911984 in BitmapIndexed bm aryA'
19921985 stA' | stA `ptrEq` stA' -> a
19931986 | otherwise -> Full (updateFullArray aryA i stA')
1994- where i = index hB s
1995- go_differenceWithKey s a@ (Collision hA _) (BitmapIndexed bB aryB)
1996- | bB .&. m == 0 = a
1997- | otherwise =
1998- case A. index# aryB (sparseIndex bB m) of
1999- (# stB # ) -> go_differenceWithKey (nextShift s) a stB
2000- where m = mask hA s
2001- go_differenceWithKey s a@ (Collision hA _) (Full aryB)
2002- = case A. index# aryB (index hA s) of
2003- (# stB # ) -> go_differenceWithKey (nextShift s) a stB
2004- go_differenceWithKey s a@ (BitmapIndexed bA aryA) (BitmapIndexed bB aryB)
2005- = differenceWithKey_Arrays s bA aryA a bB aryB
2006- go_differenceWithKey s a@ (Full aryA) (BitmapIndexed bB aryB)
2007- = differenceWithKey_Arrays s fullBitmap aryA a bB aryB
2008- go_differenceWithKey s a@ (BitmapIndexed bA aryA) (Full aryB)
2009- = differenceWithKey_Arrays s bA aryA a fullBitmap aryB
2010- go_differenceWithKey s a@ (Full aryA) (Full aryB)
2011- = differenceWithKey_Arrays s fullBitmap aryA a fullBitmap aryB
2012- go_differenceWithKey _s a@ (Collision hA aryA) (Collision hB aryB)
2013- = differenceWithKey_Collisions f hA aryA a hB aryB
1987+ where
1988+ hB = hashOfLeafOrCollision b
1989+ i = index hB s
20141990
20151991 differenceWithKey_Arrays ! s ! bA ! aryA tA ! bB ! aryB
20161992 | bA .&. bB == 0 = tA
0 commit comments