@@ -938,39 +938,9 @@ insertModifyingArr x f k0 ary0 = go k0 ary0 0 (A.length ary0)
938
938
unsafeInsertWith :: forall k v . (Eq k , Hashable k )
939
939
=> (v -> v -> v ) -> k -> v -> HashMap k v
940
940
-> HashMap k v
941
- unsafeInsertWith f k0 v0 m0 = runST (go h0 k0 v0 0 m0)
942
- where
943
- h0 = hash k0
944
- go :: Hash -> k -> v -> Shift -> HashMap k v -> ST s (HashMap k v )
945
- go ! h ! k x ! _ Empty = return $! Leaf h (L k x)
946
- go h k x s t@ (Leaf hy l@ (L ky y))
947
- | hy == h = if ky == k
948
- then return $! Leaf h (L k (f x y))
949
- else return $! collision h l (L k x)
950
- | otherwise = two s h k x hy t
951
- go h k x s t@ (BitmapIndexed b ary)
952
- | b .&. m == 0 = do
953
- ary' <- A. insertM ary i $! Leaf h (L k x)
954
- return $! bitmapIndexedOrFull (b .|. m) ary'
955
- | otherwise = do
956
- st <- A. indexM ary i
957
- st' <- go h k x (s+ bitsPerSubkey) st
958
- A. unsafeUpdateM ary i st'
959
- return t
960
- where m = mask h s
961
- i = sparseIndex b m
962
- go h k x s t@ (Full ary) = do
963
- st <- A. indexM ary i
964
- st' <- go h k x (s+ bitsPerSubkey) st
965
- A. unsafeUpdateM ary i st'
966
- return t
967
- where i = index h s
968
- go h k x s t@ (Collision hy v)
969
- | h == hy = return $! Collision h (updateOrSnocWith f k x v)
970
- | otherwise = go h k x s $ BitmapIndexed (mask hy s) (A. singleton t)
941
+ unsafeInsertWith f k0 v0 m0 = unsafeInsertWithKey (const f) k0 v0 m0
971
942
{-# INLINABLE unsafeInsertWith #-}
972
943
973
- -- | In-place update version of insertWith
974
944
unsafeInsertWithKey :: forall k v . (Eq k , Hashable k )
975
945
=> (k -> v -> v -> v ) -> k -> v -> HashMap k v
976
946
-> HashMap k v
0 commit comments