@@ -32,7 +32,9 @@ module Data.HashMap.Internal
32
32
33
33
-- * Construction
34
34
, empty
35
+ , empty'
35
36
, singleton
37
+ , singleton'
36
38
37
39
-- * Basic interface
38
40
, null
@@ -325,7 +327,7 @@ instance (Eq k, Hashable k, KnownNat salt) => Semigroup (HashMapT salt k v) wher
325
327
-- >>> mappend (fromList [(1,'a'),(2,'b')]) (fromList [(2,'c'),(3,'d')])
326
328
-- fromList [(1,'a'),(2,'b'),(3,'d')]
327
329
instance (Eq k , Hashable k , KnownNat salt ) => Monoid (HashMapT salt k v ) where
328
- mempty = empty
330
+ mempty = empty'
329
331
{-# INLINE mempty #-}
330
332
#if __GLASGOW_HASKELL__ >= 711
331
333
mappend = (<>)
@@ -597,12 +599,20 @@ isLeafOrCollision _ = False
597
599
-- * Construction
598
600
599
601
-- | /O(1)/ Construct an empty map.
600
- empty :: forall k v salt . HashMapT salt k v
601
- empty = Empty
602
+ empty :: forall k v salt . HashMap k v
603
+ empty = empty'
604
+
605
+ -- | like 'empty' but allows a custom salt to be set
606
+ empty' :: forall k v salt . HashMapT salt k v
607
+ empty' = Empty
602
608
603
609
-- | /O(1)/ Construct a map with a single element.
604
- singleton :: forall k v salt . (Hashable k , KnownNat salt ) => k -> v -> HashMapT salt k v
605
- singleton k v = Leaf (hash (Proxy :: Proxy salt ) k) (L k v)
610
+ singleton :: forall k v salt . (Hashable k ) => k -> v -> HashMap k v
611
+ singleton = singleton'
612
+
613
+ -- | like 'singleton' but allows a custom salt to be set
614
+ singleton' :: forall k v salt . (Hashable k , KnownNat salt ) => k -> v -> HashMapT salt k v
615
+ singleton' k v = Leaf (hash (Proxy :: Proxy salt ) k) (L k v)
606
616
607
617
------------------------------------------------------------------------
608
618
-- * Basic interface
@@ -1728,7 +1738,7 @@ unionArrayBy f b1 b2 ary1 ary2 = A.run $ do
1728
1738
1729
1739
-- | Construct a set containing all elements from a list of sets.
1730
1740
unions :: (Eq k , Hashable k , KnownNat salt ) => [HashMapT salt k v ] -> HashMapT salt k v
1731
- unions = L. foldl' union empty
1741
+ unions = L. foldl' union empty'
1732
1742
{-# INLINE unions #-}
1733
1743
1734
1744
@@ -1824,7 +1834,7 @@ mapKeys f = fromList . foldrWithKey (\k x xs -> (f k, x) : xs) []
1824
1834
-- | /O(n*log m)/ Difference of two maps. Return elements of the first map
1825
1835
-- not existing in the second.
1826
1836
difference :: (Eq k , Hashable k , KnownNat salt ) => HashMapT salt k v -> HashMapT salt k w -> HashMapT salt k v
1827
- difference a b = foldlWithKey' go empty a
1837
+ difference a b = foldlWithKey' go empty' a
1828
1838
where
1829
1839
go m k v = case lookup k b of
1830
1840
Nothing -> insert k v m
@@ -1836,7 +1846,7 @@ difference a b = foldlWithKey' go empty a
1836
1846
-- If it returns 'Nothing', the element is discarded (proper set difference). If
1837
1847
-- it returns (@'Just' y@), the element is updated with a new value @y@.
1838
1848
differenceWith :: (Eq k , Hashable k , KnownNat salt ) => (v -> w -> Maybe v ) -> HashMapT salt k v -> HashMapT salt k w -> HashMapT salt k v
1839
- differenceWith f a b = foldlWithKey' go empty a
1849
+ differenceWith f a b = foldlWithKey' go empty' a
1840
1850
where
1841
1851
go m k v = case lookup k b of
1842
1852
Nothing -> insert k v m
@@ -1846,7 +1856,7 @@ differenceWith f a b = foldlWithKey' go empty a
1846
1856
-- | /O(n*log m)/ Intersection of two maps. Return elements of the first
1847
1857
-- map for keys existing in the second.
1848
1858
intersection :: (Eq k , Hashable k , KnownNat salt ) => HashMapT salt k v -> HashMapT salt k w -> HashMapT salt k v
1849
- intersection a b = foldlWithKey' go empty a
1859
+ intersection a b = foldlWithKey' go empty' a
1850
1860
where
1851
1861
go m k v = case lookup k b of
1852
1862
Just _ -> insert k v m
@@ -1858,7 +1868,7 @@ intersection a b = foldlWithKey' go empty a
1858
1868
-- maps.
1859
1869
intersectionWith :: (Eq k , Hashable k , KnownNat salt ) => (v1 -> v2 -> v3 ) -> HashMapT salt k v1
1860
1870
-> HashMapT salt k v2 -> HashMapT salt k v3
1861
- intersectionWith f a b = foldlWithKey' go empty a
1871
+ intersectionWith f a b = foldlWithKey' go empty' a
1862
1872
where
1863
1873
go m k v = case lookup k b of
1864
1874
Just w -> insert k (f v w) m
@@ -1870,7 +1880,7 @@ intersectionWith f a b = foldlWithKey' go empty a
1870
1880
-- maps.
1871
1881
intersectionWithKey :: (Eq k , Hashable k , KnownNat salt ) => (k -> v1 -> v2 -> v3 )
1872
1882
-> HashMapT salt k v1 -> HashMapT salt k v2 -> HashMapT salt k v3
1873
- intersectionWithKey f a b = foldlWithKey' go empty a
1883
+ intersectionWithKey f a b = foldlWithKey' go empty' a
1874
1884
where
1875
1885
go m k v = case lookup k b of
1876
1886
Just w -> insert k (f k v w) m
@@ -2117,7 +2127,7 @@ toList t = build (\ c z -> foldrWithKey (curry c) z t)
2117
2127
-- | /O(n)/ Construct a map with the supplied mappings. If the list
2118
2128
-- contains duplicate mappings, the later mappings take precedence.
2119
2129
fromList :: (Eq k , Hashable k , KnownNat salt ) => [(k , v )] -> HashMapT salt k v
2120
- fromList = L. foldl' (\ m (k, v) -> unsafeInsert k v m) empty
2130
+ fromList = L. foldl' (\ m (k, v) -> unsafeInsert k v m) empty'
2121
2131
{-# INLINABLE fromList #-}
2122
2132
2123
2133
-- | /O(n*log n)/ Construct a map from a list of elements. Uses
@@ -2151,7 +2161,7 @@ fromList = L.foldl' (\ m (k, v) -> unsafeInsert k v m) empty
2151
2161
-- > fromListWith f [(k, a), (k, b), (k, c), (k, d)]
2152
2162
-- > = fromList [(k, f d (f c (f b a)))]
2153
2163
fromListWith :: (Eq k , Hashable k , KnownNat salt ) => (v -> v -> v ) -> [(k , v )] -> HashMapT salt k v
2154
- fromListWith f = L. foldl' (\ m (k, v) -> unsafeInsertWith f k v m) empty
2164
+ fromListWith f = L. foldl' (\ m (k, v) -> unsafeInsertWith f k v m) empty'
2155
2165
{-# INLINE fromListWith #-}
2156
2166
2157
2167
-- | /O(n*log n)/ Construct a map from a list of elements. Uses
@@ -2181,7 +2191,7 @@ fromListWith f = L.foldl' (\ m (k, v) -> unsafeInsertWith f k v m) empty
2181
2191
--
2182
2192
-- @since 0.2.11
2183
2193
fromListWithKey :: (Eq k , Hashable k , KnownNat salt ) => (k -> v -> v -> v ) -> [(k , v )] -> HashMapT salt k v
2184
- fromListWithKey f = L. foldl' (\ m (k, v) -> unsafeInsertWithKey f k v m) empty
2194
+ fromListWithKey f = L. foldl' (\ m (k, v) -> unsafeInsertWithKey f k v m) empty'
2185
2195
{-# INLINE fromListWithKey #-}
2186
2196
2187
2197
------------------------------------------------------------------------
0 commit comments