@@ -675,7 +675,7 @@ insert' h0 k0 v0 m0 = go h0 k0 v0 0 m0
675
675
then t
676
676
else Leaf h (L k x)
677
677
else collision h l (L k x)
678
- | otherwise = runST (two s h k x hy ky y )
678
+ | otherwise = runST (two s h k x hy t )
679
679
go h k x s t@ (BitmapIndexed b ary)
680
680
| b .&. m == 0 =
681
681
let ! ary' = A. insert ary i $! Leaf h (L k x)
@@ -711,9 +711,9 @@ insertNewKey :: Hash -> k -> v -> HashMap k v -> HashMap k v
711
711
insertNewKey ! h0 ! k0 x0 ! m0 = go h0 k0 x0 0 m0
712
712
where
713
713
go ! h ! k x ! _ Empty = Leaf h (L k x)
714
- go h k x s (Leaf hy l@ ( L ky y) )
714
+ go h k x s t @ (Leaf hy l)
715
715
| hy == h = collision h l (L k x)
716
- | otherwise = runST (two s h k x hy ky y )
716
+ | otherwise = runST (two s h k x hy t )
717
717
go h k x s (BitmapIndexed b ary)
718
718
| b .&. m == 0 =
719
719
let ! ary' = A. insert ary i $! Leaf h (L k x)
@@ -800,7 +800,7 @@ unsafeInsert k0 v0 m0 = runST (go h0 k0 v0 0 m0)
800
800
then return t
801
801
else return $! Leaf h (L k x)
802
802
else return $! collision h l (L k x)
803
- | otherwise = two s h k x hy ky y
803
+ | otherwise = two s h k x hy t
804
804
go h k x s t@ (BitmapIndexed b ary)
805
805
| b .&. m == 0 = do
806
806
ary' <- A. insertM ary i $! Leaf h (L k x)
@@ -823,18 +823,20 @@ unsafeInsert k0 v0 m0 = runST (go h0 k0 v0 0 m0)
823
823
| otherwise = go h k x s $ BitmapIndexed (mask hy s) (A. singleton t)
824
824
{-# INLINABLE unsafeInsert #-}
825
825
826
- -- | Create a map from two key-value pairs which hashes don't collide.
827
- two :: Shift -> Hash -> k -> v -> Hash -> k -> v -> ST s (HashMap k v )
826
+ -- | Create a map from two key-value pairs which hashes don't collide. To
827
+ -- enhance sharing, the second key-value pair is represented by the hash of its
828
+ -- key and a singleton HashMap pairing its key with its value.
829
+ two :: Shift -> Hash -> k -> v -> Hash -> HashMap k v -> ST s (HashMap k v )
828
830
two = go
829
831
where
830
- go s h1 k1 v1 h2 k2 v2
832
+ go s h1 k1 v1 h2 t2
831
833
| bp1 == bp2 = do
832
- st <- go (s+ bitsPerSubkey) h1 k1 v1 h2 k2 v2
834
+ st <- go (s+ bitsPerSubkey) h1 k1 v1 h2 t2
833
835
ary <- A. singletonM st
834
836
return $ BitmapIndexed bp1 ary
835
837
| otherwise = do
836
838
mary <- A. new 2 $! Leaf h1 (L k1 v1)
837
- A. write mary idx2 $! Leaf h2 ( L k2 v2)
839
+ A. write mary idx2 $! t2
838
840
ary <- A. unsafeFreeze mary
839
841
return $! BitmapIndexed (bp1 .|. bp2) ary
840
842
where
@@ -875,7 +877,7 @@ insertModifying x f k0 m0 = go h0 k0 0 m0
875
877
(# v' # ) | ptrEq y v' -> t
876
878
| otherwise -> Leaf h (L k (v'))
877
879
else collision h l (L k x)
878
- | otherwise = runST (two s h k x hy ky y )
880
+ | otherwise = runST (two s h k x hy t )
879
881
go h k s t@ (BitmapIndexed b ary)
880
882
| b .&. m == 0 =
881
883
let ary' = A. insert ary i $! Leaf h (L k x)
@@ -935,11 +937,11 @@ unsafeInsertWith f k0 v0 m0 = runST (go h0 k0 v0 0 m0)
935
937
h0 = hash k0
936
938
go :: Hash -> k -> v -> Shift -> HashMap k v -> ST s (HashMap k v )
937
939
go ! h ! k x ! _ Empty = return $! Leaf h (L k x)
938
- go h k x s (Leaf hy l@ (L ky y))
940
+ go h k x s t @ (Leaf hy l@ (L ky y))
939
941
| hy == h = if ky == k
940
942
then return $! Leaf h (L k (f x y))
941
943
else return $! collision h l (L k x)
942
- | otherwise = two s h k x hy ky y
944
+ | otherwise = two s h k x hy t
943
945
go h k x s t@ (BitmapIndexed b ary)
944
946
| b .&. m == 0 = do
945
947
ary' <- A. insertM ary i $! Leaf h (L k x)
0 commit comments