1
- {-# LANGUAGE CPP #-}
2
- {-# LANGUAGE BangPatterns #-}
3
- {-# LANGUAGE DeriveLift #-}
4
- {-# LANGUAGE LambdaCase #-}
5
- {-# LANGUAGE MagicHash #-}
6
- {-# LANGUAGE PatternGuards #-}
7
- {-# LANGUAGE RoleAnnotations #-}
8
- {-# LANGUAGE ScopedTypeVariables #-}
9
- {-# LANGUAGE StandaloneDeriving #-}
1
+ {-# LANGUAGE BangPatterns #-}
2
+ {-# LANGUAGE CPP #-}
3
+ {-# LANGUAGE DeriveLift #-}
4
+ {-# LANGUAGE LambdaCase #-}
5
+ {-# LANGUAGE MagicHash #-}
6
+ {-# LANGUAGE PatternGuards #-}
7
+ {-# LANGUAGE RoleAnnotations #-}
8
+ {-# LANGUAGE ScopedTypeVariables #-}
9
+ {-# LANGUAGE StandaloneDeriving #-}
10
10
{-# LANGUAGE TemplateHaskellQuotes #-}
11
- {-# LANGUAGE TypeFamilies #-}
12
- {-# LANGUAGE UnboxedTuples #-}
13
- {-# LANGUAGE TypeInType #-}
14
- {-# LANGUAGE UnboxedSums #-}
11
+ {-# LANGUAGE TypeFamilies #-}
12
+ {-# LANGUAGE TypeInType #-}
13
+ {-# LANGUAGE UnboxedSums #-}
14
+ {-# LANGUAGE UnboxedTuples #-}
15
15
{-# OPTIONS_GHC -fno-full-laziness -funbox-strict-fields #-}
16
16
{-# OPTIONS_HADDOCK not-home #-}
17
17
@@ -140,39 +140,36 @@ module Data.HashMap.Internal
140
140
, adjust #
141
141
) where
142
142
143
- import Data.Semigroup (Semigroup (.. ), stimesIdempotentMonoid )
144
- import Control.DeepSeq (NFData (rnf ))
145
- import Control.Monad.ST (ST , runST )
146
- import Data.Bits ((.&.) , (.|.) , complement , popCount , unsafeShiftL , unsafeShiftR )
147
- import Data.Data
148
- import qualified Data.Foldable as Foldable
149
- import Data.Bifoldable
150
- import qualified Data.List as L
151
- import GHC.Exts ((==#) , build , reallyUnsafePtrEquality #, inline )
152
- import Prelude hiding (filter , foldl , foldr , lookup , map , null , pred )
153
- import Text.Read hiding (step )
154
-
155
- import qualified Data.HashMap.Internal.Array as A
156
- import qualified Data.Hashable as H
157
- import Data.Hashable (Hashable )
143
+ import Control.Applicative (Const (.. ))
144
+ import Control.DeepSeq (NFData (.. ), NFData1 (.. ), NFData2 (.. ))
145
+ import Control.Monad.ST (ST , runST )
146
+ import Data.Bifoldable (Bifoldable (.. ))
147
+ import Data.Bits (complement , popCount , unsafeShiftL ,
148
+ unsafeShiftR , (.&.) , (.|.) )
149
+ import Data.Coerce (coerce )
150
+ import Data.Data (Constr , Data (.. ), DataType )
151
+ import Data.Functor.Classes (Eq1 (.. ), Eq2 (.. ), Ord1 (.. ), Ord2 (.. ),
152
+ Read1 (.. ), Show1 (.. ), Show2 (.. ))
153
+ import Data.Functor.Identity (Identity (.. ))
158
154
import Data.HashMap.Internal.List (isPermutationBy , unorderedCompare )
159
-
160
- import GHC.Exts (isTrue #)
161
- import qualified GHC.Exts as Exts
162
-
163
- import Data.Functor.Classes
164
- import GHC.Stack
165
-
166
- import qualified Data.Hashable.Lifted as H
167
-
168
- import qualified Control.DeepSeq as NF
169
-
170
- import GHC.Exts (TYPE , Int (.. ), Int #)
171
-
172
- import Data.Functor.Identity (Identity (.. ))
173
- import Control.Applicative (Const (.. ))
174
- import Data.Coerce (coerce )
175
- import qualified Language.Haskell.TH.Syntax as TH
155
+ import Data.Hashable (Hashable )
156
+ import Data.Hashable.Lifted (Hashable1 , Hashable2 )
157
+ import Data.Semigroup (Semigroup (.. ), stimesIdempotentMonoid )
158
+ import GHC.Exts (Int (.. ), Int #, TYPE , (==#) )
159
+ import GHC.Stack (HasCallStack )
160
+ import Prelude hiding (filter , foldl , foldr , lookup , map ,
161
+ null , pred )
162
+ import Text.Read hiding (step )
163
+
164
+ import qualified Data.Data as Data
165
+ import qualified Data.Foldable as Foldable
166
+ import qualified Data.Functor.Classes as FC
167
+ import qualified Data.HashMap.Internal.Array as A
168
+ import qualified Data.Hashable as H
169
+ import qualified Data.Hashable.Lifted as H
170
+ import qualified Data.List as List
171
+ import qualified GHC.Exts as Exts
172
+ import qualified Language.Haskell.TH.Syntax as TH
176
173
177
174
-- | A set of values. A set cannot contain duplicate values.
178
175
------------------------------------------------------------------------
@@ -196,11 +193,11 @@ instance (TH.Lift k, TH.Lift v) => TH.Lift (Leaf k v) where
196
193
#endif
197
194
198
195
-- | @since 0.2.14.0
199
- instance NFData k => NF. NFData1 (Leaf k ) where
200
- liftRnf rnf2 = NF. liftRnf2 rnf rnf2
196
+ instance NFData k => NFData1 (Leaf k ) where
197
+ liftRnf rnf2 = liftRnf2 rnf rnf2
201
198
202
199
-- | @since 0.2.14.0
203
- instance NF. NFData2 Leaf where
200
+ instance NFData2 Leaf where
204
201
liftRnf2 rnf1 rnf2 (L k v) = rnf1 k `seq` rnf2 v
205
202
206
203
-- Invariant: The length of the 1st argument to 'Full' is
@@ -228,16 +225,16 @@ instance (NFData k, NFData v) => NFData (HashMap k v) where
228
225
rnf (Collision _ ary) = rnf ary
229
226
230
227
-- | @since 0.2.14.0
231
- instance NFData k => NF. NFData1 (HashMap k ) where
232
- liftRnf rnf2 = NF. liftRnf2 rnf rnf2
228
+ instance NFData k => NFData1 (HashMap k ) where
229
+ liftRnf rnf2 = liftRnf2 rnf rnf2
233
230
234
231
-- | @since 0.2.14.0
235
- instance NF. NFData2 HashMap where
232
+ instance NFData2 HashMap where
236
233
liftRnf2 _ _ Empty = ()
237
- liftRnf2 rnf1 rnf2 (BitmapIndexed _ ary) = NF. liftRnf (NF. liftRnf2 rnf1 rnf2) ary
238
- liftRnf2 rnf1 rnf2 (Leaf _ l) = NF. liftRnf2 rnf1 rnf2 l
239
- liftRnf2 rnf1 rnf2 (Full ary) = NF. liftRnf (NF. liftRnf2 rnf1 rnf2) ary
240
- liftRnf2 rnf1 rnf2 (Collision _ ary) = NF. liftRnf (NF. liftRnf2 rnf1 rnf2) ary
234
+ liftRnf2 rnf1 rnf2 (BitmapIndexed _ ary) = liftRnf (liftRnf2 rnf1 rnf2) ary
235
+ liftRnf2 rnf1 rnf2 (Leaf _ l) = liftRnf2 rnf1 rnf2 l
236
+ liftRnf2 rnf1 rnf2 (Full ary) = liftRnf (liftRnf2 rnf1 rnf2) ary
237
+ liftRnf2 rnf1 rnf2 (Collision _ ary) = liftRnf (liftRnf2 rnf1 rnf2) ary
241
238
242
239
instance Functor (HashMap k ) where
243
240
fmap = map
@@ -300,26 +297,26 @@ instance (Eq k, Hashable k) => Monoid (HashMap k v) where
300
297
instance (Data k , Data v , Eq k , Hashable k ) => Data (HashMap k v ) where
301
298
gfoldl f z m = z fromList `f` toList m
302
299
toConstr _ = fromListConstr
303
- gunfold k z c = case constrIndex c of
300
+ gunfold k z c = case Data. constrIndex c of
304
301
1 -> k (z fromList)
305
302
_ -> error " gunfold"
306
303
dataTypeOf _ = hashMapDataType
307
- dataCast1 f = gcast1 f
308
- dataCast2 f = gcast2 f
304
+ dataCast1 f = Data. gcast1 f
305
+ dataCast2 f = Data. gcast2 f
309
306
310
307
fromListConstr :: Constr
311
- fromListConstr = mkConstr hashMapDataType " fromList" [] Prefix
308
+ fromListConstr = Data. mkConstr hashMapDataType " fromList" [] Data. Prefix
312
309
313
310
hashMapDataType :: DataType
314
- hashMapDataType = mkDataType " Data.HashMap.Internal.HashMap" [fromListConstr]
311
+ hashMapDataType = Data. mkDataType " Data.HashMap.Internal.HashMap" [fromListConstr]
315
312
316
313
type Hash = Word
317
314
type Bitmap = Word
318
315
type Shift = Int
319
316
320
317
instance Show2 HashMap where
321
318
liftShowsPrec2 spk slk spv slv d m =
322
- showsUnaryWith (liftShowsPrec sp sl) " fromList" d (toList m)
319
+ FC. showsUnaryWith (liftShowsPrec sp sl) " fromList" d (toList m)
323
320
where
324
321
sp = liftShowsPrec2 spk slk spv slv
325
322
sl = liftShowList2 spk slk spv slv
@@ -328,8 +325,8 @@ instance Show k => Show1 (HashMap k) where
328
325
liftShowsPrec = liftShowsPrec2 showsPrec showList
329
326
330
327
instance (Eq k , Hashable k , Read k ) => Read1 (HashMap k ) where
331
- liftReadsPrec rp rl = readsData $
332
- readsUnaryWith (liftReadsPrec rp' rl') " fromList" fromList
328
+ liftReadsPrec rp rl = FC. readsData $
329
+ FC. readsUnaryWith (liftReadsPrec rp' rl') " fromList" fromList
333
330
where
334
331
rp' = liftReadsPrec rp rl
335
332
rl' = liftReadList rp rl
@@ -484,7 +481,7 @@ equalKeys = go
484
481
485
482
leafEq (L k1 _) (L k2 _) = k1 == k2
486
483
487
- instance H. Hashable2 HashMap where
484
+ instance Hashable2 HashMap where
488
485
liftHashWithSalt2 hk hv salt hm = go salt (toList' hm [] )
489
486
where
490
487
-- go :: Int -> [HashMap k v] -> Int
@@ -502,12 +499,12 @@ instance H.Hashable2 HashMap where
502
499
503
500
-- hashCollisionWithSalt :: Int -> A.Array (Leaf k v) -> Int
504
501
hashCollisionWithSalt s
505
- = L . foldl' H. hashWithSalt s . arrayHashesSorted s
502
+ = List . foldl' H. hashWithSalt s . arrayHashesSorted s
506
503
507
504
-- arrayHashesSorted :: Int -> A.Array (Leaf k v) -> [Int]
508
- arrayHashesSorted s = L . sort . L .map (hashLeafWithSalt s) . A. toList
505
+ arrayHashesSorted s = List . sort . List .map (hashLeafWithSalt s) . A. toList
509
506
510
- instance (Hashable k ) => H. Hashable1 (HashMap k ) where
507
+ instance (Hashable k ) => Hashable1 (HashMap k ) where
511
508
liftHashWithSalt = H. liftHashWithSalt2 H. hashWithSalt
512
509
513
510
instance (Hashable k , Hashable v ) => Hashable (HashMap k v ) where
@@ -529,10 +526,10 @@ instance (Hashable k, Hashable v) => Hashable (HashMap k v) where
529
526
530
527
hashCollisionWithSalt :: Int -> A. Array (Leaf k v ) -> Int
531
528
hashCollisionWithSalt s
532
- = L . foldl' H. hashWithSalt s . arrayHashesSorted s
529
+ = List . foldl' H. hashWithSalt s . arrayHashesSorted s
533
530
534
531
arrayHashesSorted :: Int -> A. Array (Leaf k v ) -> [Int ]
535
- arrayHashesSorted s = L . sort . L .map (hashLeafWithSalt s) . A. toList
532
+ arrayHashesSorted s = List . sort . List .map (hashLeafWithSalt s) . A. toList
536
533
537
534
-- Helper to get 'Leaf's and 'Collision's as a list.
538
535
toList' :: HashMap k v -> [HashMap k v ] -> [HashMap k v ]
@@ -1410,7 +1407,7 @@ alterFEager f !k m = (<$> f mv) $ \fres ->
1410
1407
--
1411
1408
-- @since 0.2.12
1412
1409
isSubmapOf :: (Eq k , Hashable k , Eq v ) => HashMap k v -> HashMap k v -> Bool
1413
- isSubmapOf = (inline isSubmapOfBy) (==)
1410
+ isSubmapOf = (Exts. inline isSubmapOfBy) (==)
1414
1411
{-# INLINABLE isSubmapOf #-}
1415
1412
1416
1413
-- | /O(n*log m)/ Inclusion of maps with value comparison. A map is included in
@@ -1652,7 +1649,7 @@ unionArrayBy f b1 b2 ary1 ary2 = A.run $ do
1652
1649
1653
1650
-- | Construct a set containing all elements from a list of sets.
1654
1651
unions :: (Eq k , Hashable k ) => [HashMap k v ] -> HashMap k v
1655
- unions = L . foldl' union empty
1652
+ unions = List . foldl' union empty
1656
1653
{-# INLINE unions #-}
1657
1654
1658
1655
@@ -2020,13 +2017,13 @@ filter p = filterWithKey (\_ v -> p v)
2020
2017
-- | /O(n)/ Return a list of this map's keys. The list is produced
2021
2018
-- lazily.
2022
2019
keys :: HashMap k v -> [k ]
2023
- keys = L .map fst . toList
2020
+ keys = List .map fst . toList
2024
2021
{-# INLINE keys #-}
2025
2022
2026
2023
-- | /O(n)/ Return a list of this map's values. The list is produced
2027
2024
-- lazily.
2028
2025
elems :: HashMap k v -> [v ]
2029
- elems = L .map snd . toList
2026
+ elems = List .map snd . toList
2030
2027
{-# INLINE elems #-}
2031
2028
2032
2029
------------------------------------------------------------------------
@@ -2035,13 +2032,13 @@ elems = L.map snd . toList
2035
2032
-- | /O(n)/ Return a list of this map's elements. The list is
2036
2033
-- produced lazily. The order of its elements is unspecified.
2037
2034
toList :: HashMap k v -> [(k , v )]
2038
- toList t = build (\ c z -> foldrWithKey (curry c) z t)
2035
+ toList t = Exts. build (\ c z -> foldrWithKey (curry c) z t)
2039
2036
{-# INLINE toList #-}
2040
2037
2041
2038
-- | /O(n)/ Construct a map with the supplied mappings. If the list
2042
2039
-- contains duplicate mappings, the later mappings take precedence.
2043
2040
fromList :: (Eq k , Hashable k ) => [(k , v )] -> HashMap k v
2044
- fromList = L . foldl' (\ m (k, v) -> unsafeInsert k v m) empty
2041
+ fromList = List . foldl' (\ m (k, v) -> unsafeInsert k v m) empty
2045
2042
{-# INLINABLE fromList #-}
2046
2043
2047
2044
-- | /O(n*log n)/ Construct a map from a list of elements. Uses
@@ -2075,7 +2072,7 @@ fromList = L.foldl' (\ m (k, v) -> unsafeInsert k v m) empty
2075
2072
-- > fromListWith f [(k, a), (k, b), (k, c), (k, d)]
2076
2073
-- > = fromList [(k, f d (f c (f b a)))]
2077
2074
fromListWith :: (Eq k , Hashable k ) => (v -> v -> v ) -> [(k , v )] -> HashMap k v
2078
- fromListWith f = L . foldl' (\ m (k, v) -> unsafeInsertWith f k v m) empty
2075
+ fromListWith f = List . foldl' (\ m (k, v) -> unsafeInsertWith f k v m) empty
2079
2076
{-# INLINE fromListWith #-}
2080
2077
2081
2078
-- | /O(n*log n)/ Construct a map from a list of elements. Uses
@@ -2105,7 +2102,7 @@ fromListWith f = L.foldl' (\ m (k, v) -> unsafeInsertWith f k v m) empty
2105
2102
--
2106
2103
-- @since 0.2.11
2107
2104
fromListWithKey :: (Eq k , Hashable k ) => (k -> v -> v -> v ) -> [(k , v )] -> HashMap k v
2108
- fromListWithKey f = L . foldl' (\ m (k, v) -> unsafeInsertWithKey f k v m) empty
2105
+ fromListWithKey f = List . foldl' (\ m (k, v) -> unsafeInsertWithKey f k v m) empty
2109
2106
{-# INLINE fromListWithKey #-}
2110
2107
2111
2108
------------------------------------------------------------------------
@@ -2282,7 +2279,7 @@ fullNodeMask = complement (complement 0 `unsafeShiftL` maxChildren)
2282
2279
-- | Check if two the two arguments are the same value. N.B. This
2283
2280
-- function might give false negatives (due to GC moving objects.)
2284
2281
ptrEq :: a -> a -> Bool
2285
- ptrEq x y = isTrue# (reallyUnsafePtrEquality# x y ==# 1 # )
2282
+ ptrEq x y = Exts. isTrue# (Exts. reallyUnsafePtrEquality# x y ==# 1 # )
2286
2283
{-# INLINE ptrEq #-}
2287
2284
2288
2285
------------------------------------------------------------------------
0 commit comments