Skip to content

Commit d4bda2e

Browse files
fix intersection
1 parent 4da2c20 commit d4bda2e

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

Data/HashMap/Internal.hs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1859,9 +1859,10 @@ intersectionArrayBy f !b1 !b2 !ary1 !ary2
18591859
testBit x = x .&. m /= 0
18601860
b' = b .&. complement m
18611861
(len, bFinal) <- go 0 0 0 bCombined bIntersect
1862+
l <- A.read mary 0
18621863
case len of
18631864
0 -> pure Empty
1864-
1 -> A.read mary 0
1865+
1 | isLeafOrCollision l -> pure l
18651866
_ -> bitmapIndexedOrFull bFinal <$> (A.unsafeFreeze =<< A.shrink mary len)
18661867
where
18671868
bCombined = b1 .|. b2
@@ -1915,6 +1916,49 @@ searchSwap toFind start = go start toFind start
19151916
else go i0 k (i + 1) mary
19161917
{-# INLINE searchSwap #-}
19171918

1919+
type WhenMissingKey k x y = k -> x -> Maybe y
1920+
1921+
type WhenMissingTree k x y = HashMap k x -> HashMap k y
1922+
1923+
type WhenMatched k x y z = k -> x -> y -> Maybe z
1924+
1925+
type MergeLeaf k x y z = Hash -> Hash -> Leaf k x -> Leaf k y -> HashMap k z
1926+
1927+
type MergeCollision k x y z = Hash -> Hash -> A.Array (Leaf k x) -> A.Array (Leaf k y) -> HashMap k z
1928+
1929+
type MergeBitmap k x y z = Bitmap -> Bitmap -> A.Array (HashMap k x) -> A.Array (HashMap k y) -> HashMap k z
1930+
1931+
-- what a monstrosity
1932+
mergeMonstrosity ::
1933+
MergeLeaf k x y z ->
1934+
MergeCollision k x y z ->
1935+
WhenMissingKey k x z ->
1936+
WhenMissingTree k x z ->
1937+
WhenMissingKey k y z ->
1938+
WhenMissingTree k y z ->
1939+
WhenMatched k x y z ->
1940+
HashMap k x ->
1941+
HashMap k y ->
1942+
HashMap k z
1943+
mergeMonstrosity
1944+
mergeLeaf
1945+
mergeCollision
1946+
missK1
1947+
missT1
1948+
missK2
1949+
missT2
1950+
match = go 0
1951+
where
1952+
go !_ t1 Empty = missT1 t1
1953+
go _ Empty t2 = missT2 t2
1954+
go _ (Leaf h1 l1) (Leaf h2 l2) = mergeLeaf h1 h2 l1 l2
1955+
go _ (Collision h1 ls1) (Collision h2 ls2) = mergeCollision h1 h2 ls1 ls2
1956+
go _ (BitmapIndexed b1 ary1) (BitmapIndexed b2 ary2) = mergeBitmap b1 b2 ary1 ary2
1957+
{-# INLINE mergeMonstrosity #-}
1958+
1959+
mergeBitmap :: Bitmap -> Bitmap -> A.Array (HashMap k x) -> A.Array (HashMap k y) -> HashMap k z
1960+
mergeBitmap b1 b2 ary1 ary2 = undefined
1961+
{-# INLINE mergeBitmap #-}
19181962

19191963
------------------------------------------------------------------------
19201964
-- * Folds

0 commit comments

Comments
 (0)