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 #-}
1010{-# 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 #-}
1515{-# OPTIONS_GHC -fno-full-laziness -funbox-strict-fields #-}
1616{-# OPTIONS_HADDOCK not-home #-}
1717
@@ -140,39 +140,36 @@ module Data.HashMap.Internal
140140 , adjust #
141141 ) where
142142
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 (.. ))
158154import 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
176173
177174-- | A set of values. A set cannot contain duplicate values.
178175------------------------------------------------------------------------
@@ -196,11 +193,11 @@ instance (TH.Lift k, TH.Lift v) => TH.Lift (Leaf k v) where
196193#endif
197194
198195-- | @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
201198
202199-- | @since 0.2.14.0
203- instance NF. NFData2 Leaf where
200+ instance NFData2 Leaf where
204201 liftRnf2 rnf1 rnf2 (L k v) = rnf1 k `seq` rnf2 v
205202
206203-- Invariant: The length of the 1st argument to 'Full' is
@@ -228,16 +225,16 @@ instance (NFData k, NFData v) => NFData (HashMap k v) where
228225 rnf (Collision _ ary) = rnf ary
229226
230227-- | @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
233230
234231-- | @since 0.2.14.0
235- instance NF. NFData2 HashMap where
232+ instance NFData2 HashMap where
236233 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
241238
242239instance Functor (HashMap k ) where
243240 fmap = map
@@ -300,26 +297,26 @@ instance (Eq k, Hashable k) => Monoid (HashMap k v) where
300297instance (Data k , Data v , Eq k , Hashable k ) => Data (HashMap k v ) where
301298 gfoldl f z m = z fromList `f` toList m
302299 toConstr _ = fromListConstr
303- gunfold k z c = case constrIndex c of
300+ gunfold k z c = case Data. constrIndex c of
304301 1 -> k (z fromList)
305302 _ -> error " gunfold"
306303 dataTypeOf _ = hashMapDataType
307- dataCast1 f = gcast1 f
308- dataCast2 f = gcast2 f
304+ dataCast1 f = Data. gcast1 f
305+ dataCast2 f = Data. gcast2 f
309306
310307fromListConstr :: Constr
311- fromListConstr = mkConstr hashMapDataType " fromList" [] Prefix
308+ fromListConstr = Data. mkConstr hashMapDataType " fromList" [] Data. Prefix
312309
313310hashMapDataType :: DataType
314- hashMapDataType = mkDataType " Data.HashMap.Internal.HashMap" [fromListConstr]
311+ hashMapDataType = Data. mkDataType " Data.HashMap.Internal.HashMap" [fromListConstr]
315312
316313type Hash = Word
317314type Bitmap = Word
318315type Shift = Int
319316
320317instance Show2 HashMap where
321318 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)
323320 where
324321 sp = liftShowsPrec2 spk slk spv slv
325322 sl = liftShowList2 spk slk spv slv
@@ -328,8 +325,8 @@ instance Show k => Show1 (HashMap k) where
328325 liftShowsPrec = liftShowsPrec2 showsPrec showList
329326
330327instance (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
333330 where
334331 rp' = liftReadsPrec rp rl
335332 rl' = liftReadList rp rl
@@ -484,7 +481,7 @@ equalKeys = go
484481
485482 leafEq (L k1 _) (L k2 _) = k1 == k2
486483
487- instance H. Hashable2 HashMap where
484+ instance Hashable2 HashMap where
488485 liftHashWithSalt2 hk hv salt hm = go salt (toList' hm [] )
489486 where
490487 -- go :: Int -> [HashMap k v] -> Int
@@ -502,12 +499,12 @@ instance H.Hashable2 HashMap where
502499
503500 -- hashCollisionWithSalt :: Int -> A.Array (Leaf k v) -> Int
504501 hashCollisionWithSalt s
505- = L . foldl' H. hashWithSalt s . arrayHashesSorted s
502+ = List . foldl' H. hashWithSalt s . arrayHashesSorted s
506503
507504 -- 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
509506
510- instance (Hashable k ) => H. Hashable1 (HashMap k ) where
507+ instance (Hashable k ) => Hashable1 (HashMap k ) where
511508 liftHashWithSalt = H. liftHashWithSalt2 H. hashWithSalt
512509
513510instance (Hashable k , Hashable v ) => Hashable (HashMap k v ) where
@@ -529,10 +526,10 @@ instance (Hashable k, Hashable v) => Hashable (HashMap k v) where
529526
530527 hashCollisionWithSalt :: Int -> A. Array (Leaf k v ) -> Int
531528 hashCollisionWithSalt s
532- = L . foldl' H. hashWithSalt s . arrayHashesSorted s
529+ = List . foldl' H. hashWithSalt s . arrayHashesSorted s
533530
534531 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
536533
537534 -- Helper to get 'Leaf's and 'Collision's as a list.
538535toList' :: HashMap k v -> [HashMap k v ] -> [HashMap k v ]
@@ -1410,7 +1407,7 @@ alterFEager f !k m = (<$> f mv) $ \fres ->
14101407--
14111408-- @since 0.2.12
14121409isSubmapOf :: (Eq k , Hashable k , Eq v ) => HashMap k v -> HashMap k v -> Bool
1413- isSubmapOf = (inline isSubmapOfBy) (==)
1410+ isSubmapOf = (Exts. inline isSubmapOfBy) (==)
14141411{-# INLINABLE isSubmapOf #-}
14151412
14161413-- | /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
16521649
16531650-- | Construct a set containing all elements from a list of sets.
16541651unions :: (Eq k , Hashable k ) => [HashMap k v ] -> HashMap k v
1655- unions = L . foldl' union empty
1652+ unions = List . foldl' union empty
16561653{-# INLINE unions #-}
16571654
16581655
@@ -2020,13 +2017,13 @@ filter p = filterWithKey (\_ v -> p v)
20202017-- | /O(n)/ Return a list of this map's keys. The list is produced
20212018-- lazily.
20222019keys :: HashMap k v -> [k ]
2023- keys = L .map fst . toList
2020+ keys = List .map fst . toList
20242021{-# INLINE keys #-}
20252022
20262023-- | /O(n)/ Return a list of this map's values. The list is produced
20272024-- lazily.
20282025elems :: HashMap k v -> [v ]
2029- elems = L .map snd . toList
2026+ elems = List .map snd . toList
20302027{-# INLINE elems #-}
20312028
20322029------------------------------------------------------------------------
@@ -2035,13 +2032,13 @@ elems = L.map snd . toList
20352032-- | /O(n)/ Return a list of this map's elements. The list is
20362033-- produced lazily. The order of its elements is unspecified.
20372034toList :: 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)
20392036{-# INLINE toList #-}
20402037
20412038-- | /O(n)/ Construct a map with the supplied mappings. If the list
20422039-- contains duplicate mappings, the later mappings take precedence.
20432040fromList :: (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
20452042{-# INLINABLE fromList #-}
20462043
20472044-- | /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
20752072-- > fromListWith f [(k, a), (k, b), (k, c), (k, d)]
20762073-- > = fromList [(k, f d (f c (f b a)))]
20772074fromListWith :: (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
20792076{-# INLINE fromListWith #-}
20802077
20812078-- | /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
21052102--
21062103-- @since 0.2.11
21072104fromListWithKey :: (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
21092106{-# INLINE fromListWithKey #-}
21102107
21112108------------------------------------------------------------------------
@@ -2282,7 +2279,7 @@ fullNodeMask = complement (complement 0 `unsafeShiftL` maxChildren)
22822279-- | Check if two the two arguments are the same value. N.B. This
22832280-- function might give false negatives (due to GC moving objects.)
22842281ptrEq :: a -> a -> Bool
2285- ptrEq x y = isTrue# (reallyUnsafePtrEquality# x y ==# 1 # )
2282+ ptrEq x y = Exts. isTrue# (Exts. reallyUnsafePtrEquality# x y ==# 1 # )
22862283{-# INLINE ptrEq #-}
22872284
22882285------------------------------------------------------------------------
0 commit comments