packages feed

hashmap 1.1.0.1 → 1.2.0.0

raw patch · 5 files changed

+213/−184 lines, 5 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Data.HashMap: data HashMap k v
- Data.HashMap: instance (Data k, Hashable k, Ord k, Data a) => Data (HashMap k a)
- Data.HashMap: instance (Eq k, Eq v) => Eq (HashMap k v)
- Data.HashMap: instance (Ord k, Ord v) => Ord (HashMap k v)
- Data.HashMap: instance (Read k, Hashable k, Ord k, Read a) => Read (HashMap k a)
- Data.HashMap: instance (Show k, Show a) => Show (HashMap k a)
- Data.HashMap: instance Foldable (HashMap k)
- Data.HashMap: instance Functor (HashMap k)
- Data.HashMap: instance Ord k => Monoid (HashMap k a)
- Data.HashMap: instance Traversable (HashMap k)
- Data.HashMap: instance Typeable2 HashMap
- Data.HashSet: data HashSet a
- Data.HashSet: instance (Hashable a, Ord a, Data a) => Data (HashSet a)
- Data.HashSet: instance (Hashable a, Ord a, Read a) => Read (HashSet a)
- Data.HashSet: instance Eq a => Eq (HashSet a)
- Data.HashSet: instance Ord a => Monoid (HashSet a)
- Data.HashSet: instance Ord a => Ord (HashSet a)
- Data.HashSet: instance Show a => Show (HashSet a)
- Data.HashSet: instance Typeable1 HashSet
+ Data.HashMap: data Map k v
+ Data.HashMap: instance (Data k, Hashable k, Ord k, Data a) => Data (Map k a)
+ Data.HashMap: instance (Eq k, Eq v) => Eq (Map k v)
+ Data.HashMap: instance (Ord k, Ord v) => Ord (Map k v)
+ Data.HashMap: instance (Read k, Hashable k, Ord k, Read a) => Read (Map k a)
+ Data.HashMap: instance (Show k, Show a) => Show (Map k a)
+ Data.HashMap: instance Foldable (Map k)
+ Data.HashMap: instance Functor (Map k)
+ Data.HashMap: instance Ord k => Monoid (Map k a)
+ Data.HashMap: instance Traversable (Map k)
+ Data.HashMap: instance Typeable2 Map
+ Data.HashMap: type HashMap k v = Map k v
+ Data.HashSet: data Set a
+ Data.HashSet: instance (Hashable a, Ord a, Data a) => Data (Set a)
+ Data.HashSet: instance (Hashable a, Ord a, Read a) => Read (Set a)
+ Data.HashSet: instance Eq a => Eq (Set a)
+ Data.HashSet: instance Ord a => Monoid (Set a)
+ Data.HashSet: instance Ord a => Ord (Set a)
+ Data.HashSet: instance Show a => Show (Set a)
+ Data.HashSet: instance Typeable1 Set
+ Data.HashSet: type HashSet a = Set a
- Data.HashMap: (!) :: (Hashable k, Ord k) => HashMap k a -> k -> a
+ Data.HashMap: (!) :: (Hashable k, Ord k) => Map k a -> k -> a
- Data.HashMap: (\\) :: Ord k => HashMap k a -> HashMap k b -> HashMap k a
+ Data.HashMap: (\\) :: Ord k => Map k a -> Map k b -> Map k a
- Data.HashMap: adjust :: (Hashable k, Ord k) => (a -> a) -> k -> HashMap k a -> HashMap k a
+ Data.HashMap: adjust :: (Hashable k, Ord k) => (a -> a) -> k -> Map k a -> Map k a
- Data.HashMap: adjustWithKey :: (Hashable k, Ord k) => (k -> a -> a) -> k -> HashMap k a -> HashMap k a
+ Data.HashMap: adjustWithKey :: (Hashable k, Ord k) => (k -> a -> a) -> k -> Map k a -> Map k a
- Data.HashMap: alter :: (Hashable k, Ord k) => (Maybe a -> Maybe a) -> k -> HashMap k a -> HashMap k a
+ Data.HashMap: alter :: (Hashable k, Ord k) => (Maybe a -> Maybe a) -> k -> Map k a -> Map k a
- Data.HashMap: assocs :: HashMap k a -> [(k, a)]
+ Data.HashMap: assocs :: Map k a -> [(k, a)]
- Data.HashMap: delete :: (Hashable k, Ord k) => k -> HashMap k a -> HashMap k a
+ Data.HashMap: delete :: (Hashable k, Ord k) => k -> Map k a -> Map k a
- Data.HashMap: difference :: Ord k => HashMap k a -> HashMap k b -> HashMap k a
+ Data.HashMap: difference :: Ord k => Map k a -> Map k b -> Map k a
- Data.HashMap: differenceWith :: Ord k => (a -> b -> Maybe a) -> HashMap k a -> HashMap k b -> HashMap k a
+ Data.HashMap: differenceWith :: Ord k => (a -> b -> Maybe a) -> Map k a -> Map k b -> Map k a
- Data.HashMap: differenceWithKey :: Ord k => (k -> a -> b -> Maybe a) -> HashMap k a -> HashMap k b -> HashMap k a
+ Data.HashMap: differenceWithKey :: Ord k => (k -> a -> b -> Maybe a) -> Map k a -> Map k b -> Map k a
- Data.HashMap: elems :: HashMap k a -> [a]
+ Data.HashMap: elems :: Map k a -> [a]
- Data.HashMap: empty :: HashMap k a
+ Data.HashMap: empty :: Map k a
- Data.HashMap: filter :: Ord k => (a -> Bool) -> HashMap k a -> HashMap k a
+ Data.HashMap: filter :: Ord k => (a -> Bool) -> Map k a -> Map k a
- Data.HashMap: filterWithKey :: Ord k => (k -> a -> Bool) -> HashMap k a -> HashMap k a
+ Data.HashMap: filterWithKey :: Ord k => (k -> a -> Bool) -> Map k a -> Map k a
- Data.HashMap: findWithDefault :: (Hashable k, Ord k) => a -> k -> HashMap k a -> a
+ Data.HashMap: findWithDefault :: (Hashable k, Ord k) => a -> k -> Map k a -> a
- Data.HashMap: fold :: (a -> b -> b) -> b -> HashMap k a -> b
+ Data.HashMap: fold :: (a -> b -> b) -> b -> Map k a -> b
- Data.HashMap: foldWithKey :: (k -> a -> b -> b) -> b -> HashMap k a -> b
+ Data.HashMap: foldWithKey :: (k -> a -> b -> b) -> b -> Map k a -> b
- Data.HashMap: fromList :: (Hashable k, Ord k) => [(k, a)] -> HashMap k a
+ Data.HashMap: fromList :: (Hashable k, Ord k) => [(k, a)] -> Map k a
- Data.HashMap: fromListWith :: (Hashable k, Ord k) => (a -> a -> a) -> [(k, a)] -> HashMap k a
+ Data.HashMap: fromListWith :: (Hashable k, Ord k) => (a -> a -> a) -> [(k, a)] -> Map k a
- Data.HashMap: fromListWithKey :: (Hashable k, Ord k) => (k -> a -> a -> a) -> [(k, a)] -> HashMap k a
+ Data.HashMap: fromListWithKey :: (Hashable k, Ord k) => (k -> a -> a -> a) -> [(k, a)] -> Map k a
- Data.HashMap: insert :: (Hashable k, Ord k) => k -> a -> HashMap k a -> HashMap k a
+ Data.HashMap: insert :: (Hashable k, Ord k) => k -> a -> Map k a -> Map k a
- Data.HashMap: insertLookupWithKey :: (Hashable k, Ord k) => (k -> a -> a -> a) -> k -> a -> HashMap k a -> (Maybe a, HashMap k a)
+ Data.HashMap: insertLookupWithKey :: (Hashable k, Ord k) => (k -> a -> a -> a) -> k -> a -> Map k a -> (Maybe a, Map k a)
- Data.HashMap: insertWith :: (Hashable k, Ord k) => (a -> a -> a) -> k -> a -> HashMap k a -> HashMap k a
+ Data.HashMap: insertWith :: (Hashable k, Ord k) => (a -> a -> a) -> k -> a -> Map k a -> Map k a
- Data.HashMap: insertWithKey :: (Hashable k, Ord k) => (k -> a -> a -> a) -> k -> a -> HashMap k a -> HashMap k a
+ Data.HashMap: insertWithKey :: (Hashable k, Ord k) => (k -> a -> a -> a) -> k -> a -> Map k a -> Map k a
- Data.HashMap: intersection :: Ord k => HashMap k a -> HashMap k b -> HashMap k a
+ Data.HashMap: intersection :: Ord k => Map k a -> Map k b -> Map k a
- Data.HashMap: intersectionWith :: Ord k => (a -> b -> c) -> HashMap k a -> HashMap k b -> HashMap k c
+ Data.HashMap: intersectionWith :: Ord k => (a -> b -> c) -> Map k a -> Map k b -> Map k c
- Data.HashMap: intersectionWithKey :: Ord k => (k -> a -> b -> c) -> HashMap k a -> HashMap k b -> HashMap k c
+ Data.HashMap: intersectionWithKey :: Ord k => (k -> a -> b -> c) -> Map k a -> Map k b -> Map k c
- Data.HashMap: isProperSubmapOf :: (Ord k, Eq a) => HashMap k a -> HashMap k a -> Bool
+ Data.HashMap: isProperSubmapOf :: (Ord k, Eq a) => Map k a -> Map k a -> Bool
- Data.HashMap: isProperSubmapOfBy :: Ord k => (a -> b -> Bool) -> HashMap k a -> HashMap k b -> Bool
+ Data.HashMap: isProperSubmapOfBy :: Ord k => (a -> b -> Bool) -> Map k a -> Map k b -> Bool
- Data.HashMap: isSubmapOf :: (Ord k, Eq a) => HashMap k a -> HashMap k a -> Bool
+ Data.HashMap: isSubmapOf :: (Ord k, Eq a) => Map k a -> Map k a -> Bool
- Data.HashMap: isSubmapOfBy :: Ord k => (a -> b -> Bool) -> HashMap k a -> HashMap k b -> Bool
+ Data.HashMap: isSubmapOfBy :: Ord k => (a -> b -> Bool) -> Map k a -> Map k b -> Bool
- Data.HashMap: keys :: HashMap k a -> [k]
+ Data.HashMap: keys :: Map k a -> [k]
- Data.HashMap: keysSet :: Ord k => HashMap k a -> Set k
+ Data.HashMap: keysSet :: Ord k => Map k a -> Set k
- Data.HashMap: lookup :: (Hashable k, Ord k) => k -> HashMap k a -> Maybe a
+ Data.HashMap: lookup :: (Hashable k, Ord k) => k -> Map k a -> Maybe a
- Data.HashMap: map :: (a -> b) -> HashMap k a -> HashMap k b
+ Data.HashMap: map :: (a -> b) -> Map k a -> Map k b
- Data.HashMap: mapAccum :: (a -> b -> (a, c)) -> a -> HashMap k b -> (a, HashMap k c)
+ Data.HashMap: mapAccum :: (a -> b -> (a, c)) -> a -> Map k b -> (a, Map k c)
- Data.HashMap: mapAccumWithKey :: (a -> k -> b -> (a, c)) -> a -> HashMap k b -> (a, HashMap k c)
+ Data.HashMap: mapAccumWithKey :: (a -> k -> b -> (a, c)) -> a -> Map k b -> (a, Map k c)
- Data.HashMap: mapEither :: Ord k => (a -> Either b c) -> HashMap k a -> (HashMap k b, HashMap k c)
+ Data.HashMap: mapEither :: Ord k => (a -> Either b c) -> Map k a -> (Map k b, Map k c)
- Data.HashMap: mapEitherWithKey :: Ord k => (k -> a -> Either b c) -> HashMap k a -> (HashMap k b, HashMap k c)
+ Data.HashMap: mapEitherWithKey :: Ord k => (k -> a -> Either b c) -> Map k a -> (Map k b, Map k c)
- Data.HashMap: mapMaybe :: Ord k => (a -> Maybe b) -> HashMap k a -> HashMap k b
+ Data.HashMap: mapMaybe :: Ord k => (a -> Maybe b) -> Map k a -> Map k b
- Data.HashMap: mapMaybeWithKey :: Ord k => (k -> a -> Maybe b) -> HashMap k a -> HashMap k b
+ Data.HashMap: mapMaybeWithKey :: Ord k => (k -> a -> Maybe b) -> Map k a -> Map k b
- Data.HashMap: mapWithKey :: (k -> a -> b) -> HashMap k a -> HashMap k b
+ Data.HashMap: mapWithKey :: (k -> a -> b) -> Map k a -> Map k b
- Data.HashMap: member :: (Hashable k, Ord k) => k -> HashMap k a -> Bool
+ Data.HashMap: member :: (Hashable k, Ord k) => k -> Map k a -> Bool
- Data.HashMap: notMember :: (Hashable k, Ord k) => k -> HashMap k a -> Bool
+ Data.HashMap: notMember :: (Hashable k, Ord k) => k -> Map k a -> Bool
- Data.HashMap: null :: HashMap k a -> Bool
+ Data.HashMap: null :: Map k a -> Bool
- Data.HashMap: partition :: Ord k => (a -> Bool) -> HashMap k a -> (HashMap k a, HashMap k a)
+ Data.HashMap: partition :: Ord k => (a -> Bool) -> Map k a -> (Map k a, Map k a)
- Data.HashMap: partitionWithKey :: Ord k => (k -> a -> Bool) -> HashMap k a -> (HashMap k a, HashMap k a)
+ Data.HashMap: partitionWithKey :: Ord k => (k -> a -> Bool) -> Map k a -> (Map k a, Map k a)
- Data.HashMap: singleton :: Hashable k => k -> a -> HashMap k a
+ Data.HashMap: singleton :: Hashable k => k -> a -> Map k a
- Data.HashMap: size :: HashMap k a -> Int
+ Data.HashMap: size :: Map k a -> Int
- Data.HashMap: toList :: HashMap k a -> [(k, a)]
+ Data.HashMap: toList :: Map k a -> [(k, a)]
- Data.HashMap: union :: Ord k => HashMap k a -> HashMap k a -> HashMap k a
+ Data.HashMap: union :: Ord k => Map k a -> Map k a -> Map k a
- Data.HashMap: unionWith :: Ord k => (a -> a -> a) -> HashMap k a -> HashMap k a -> HashMap k a
+ Data.HashMap: unionWith :: Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k a
- Data.HashMap: unionWithKey :: Ord k => (k -> a -> a -> a) -> HashMap k a -> HashMap k a -> HashMap k a
+ Data.HashMap: unionWithKey :: Ord k => (k -> a -> a -> a) -> Map k a -> Map k a -> Map k a
- Data.HashMap: unions :: Ord k => [HashMap k a] -> HashMap k a
+ Data.HashMap: unions :: Ord k => [Map k a] -> Map k a
- Data.HashMap: unionsWith :: Ord k => (a -> a -> a) -> [HashMap k a] -> HashMap k a
+ Data.HashMap: unionsWith :: Ord k => (a -> a -> a) -> [Map k a] -> Map k a
- Data.HashMap: update :: (Hashable k, Ord k) => (a -> Maybe a) -> k -> HashMap k a -> HashMap k a
+ Data.HashMap: update :: (Hashable k, Ord k) => (a -> Maybe a) -> k -> Map k a -> Map k a
- Data.HashMap: updateLookupWithKey :: (Hashable k, Ord k) => (k -> a -> Maybe a) -> k -> HashMap k a -> (Maybe a, HashMap k a)
+ Data.HashMap: updateLookupWithKey :: (Hashable k, Ord k) => (k -> a -> Maybe a) -> k -> Map k a -> (Maybe a, Map k a)
- Data.HashMap: updateWithKey :: (Hashable k, Ord k) => (k -> a -> Maybe a) -> k -> HashMap k a -> HashMap k a
+ Data.HashMap: updateWithKey :: (Hashable k, Ord k) => (k -> a -> Maybe a) -> k -> Map k a -> Map k a
- Data.HashSet: (\\) :: Ord a => HashSet a -> HashSet a -> HashSet a
+ Data.HashSet: (\\) :: Ord a => Set a -> Set a -> Set a
- Data.HashSet: delete :: (Hashable a, Ord a) => a -> HashSet a -> HashSet a
+ Data.HashSet: delete :: (Hashable a, Ord a) => a -> Set a -> Set a
- Data.HashSet: difference :: Ord a => HashSet a -> HashSet a -> HashSet a
+ Data.HashSet: difference :: Ord a => Set a -> Set a -> Set a
- Data.HashSet: elems :: HashSet a -> [a]
+ Data.HashSet: elems :: Set a -> [a]
- Data.HashSet: empty :: HashSet a
+ Data.HashSet: empty :: Set a
- Data.HashSet: filter :: Ord a => (a -> Bool) -> HashSet a -> HashSet a
+ Data.HashSet: filter :: Ord a => (a -> Bool) -> Set a -> Set a
- Data.HashSet: fold :: (a -> b -> b) -> b -> HashSet a -> b
+ Data.HashSet: fold :: (a -> b -> b) -> b -> Set a -> b
- Data.HashSet: fromList :: (Hashable a, Ord a) => [a] -> HashSet a
+ Data.HashSet: fromList :: (Hashable a, Ord a) => [a] -> Set a
- Data.HashSet: insert :: (Hashable a, Ord a) => a -> HashSet a -> HashSet a
+ Data.HashSet: insert :: (Hashable a, Ord a) => a -> Set a -> Set a
- Data.HashSet: intersection :: Ord a => HashSet a -> HashSet a -> HashSet a
+ Data.HashSet: intersection :: Ord a => Set a -> Set a -> Set a
- Data.HashSet: isProperSubsetOf :: Ord a => HashSet a -> HashSet a -> Bool
+ Data.HashSet: isProperSubsetOf :: Ord a => Set a -> Set a -> Bool
- Data.HashSet: isSubsetOf :: Ord a => HashSet a -> HashSet a -> Bool
+ Data.HashSet: isSubsetOf :: Ord a => Set a -> Set a -> Bool
- Data.HashSet: map :: (Hashable b, Ord b) => (a -> b) -> HashSet a -> HashSet b
+ Data.HashSet: map :: (Hashable b, Ord b) => (a -> b) -> Set a -> Set b
- Data.HashSet: member :: (Hashable a, Ord a) => a -> HashSet a -> Bool
+ Data.HashSet: member :: (Hashable a, Ord a) => a -> Set a -> Bool
- Data.HashSet: notMember :: (Hashable a, Ord a) => a -> HashSet a -> Bool
+ Data.HashSet: notMember :: (Hashable a, Ord a) => a -> Set a -> Bool
- Data.HashSet: null :: HashSet a -> Bool
+ Data.HashSet: null :: Set a -> Bool
- Data.HashSet: partition :: Ord a => (a -> Bool) -> HashSet a -> (HashSet a, HashSet a)
+ Data.HashSet: partition :: Ord a => (a -> Bool) -> Set a -> (Set a, Set a)
- Data.HashSet: singleton :: Hashable a => a -> HashSet a
+ Data.HashSet: singleton :: Hashable a => a -> Set a
- Data.HashSet: size :: HashSet a -> Int
+ Data.HashSet: size :: Set a -> Int
- Data.HashSet: toList :: HashSet a -> [a]
+ Data.HashSet: toList :: Set a -> [a]
- Data.HashSet: union :: Ord a => HashSet a -> HashSet a -> HashSet a
+ Data.HashSet: union :: Ord a => Set a -> Set a -> Set a
- Data.HashSet: unions :: Ord a => [HashSet a] -> HashSet a
+ Data.HashSet: unions :: Ord a => [Set a] -> Set a

Files

CHANGES view
@@ -1,3 +1,12 @@+= Version 1.2.0.0, 2011-05-08 =+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^+* Rename HashMap and HashSet to Map and Set.+That allows to use this package as a drop-in+replacement for Data.Map and Data.Set packages.+HashMap and HashSet types are kept as deprecated+type synonyms.++ = Version 1.1.0.1, 2011-04-19 = ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ * Convert the repository to Git.
Data/HashMap.hs view
@@ -3,29 +3,32 @@ ----------------------------------------------------------------------------- -- | -- Module      :  Data.HashMap--- Copyright   :  (c) Milan Straka 2010+-- Copyright   :  (c) Milan Straka 2011 -- License     :  BSD-style -- Maintainer  :  fox@ucw.cz -- Stability   :  provisional -- Portability :  portable ----- Persistent 'HashMap', which is defined as+-- Persistent 'Map' based on hashing, which is defined as -- -- @---   data 'HashMap' k v = 'Data.IntMap.IntMap' ('Data.Map.Map' k v)+--   data 'Map' k v = 'Data.IntMap.IntMap' (Some k v) -- @ -- -- is an 'Data.IntMap.IntMap' indexed by hash values of keys,--- containing a map @'Data.Map.Map' k v@ with keys of the same hash values.+-- containing a value of @Some e@. That contains either one+-- @('k', 'v')@ pair or a @'Data.Map.Map' k v@ with keys of the same hash values. ----- The interface of a 'HashMap' is a suitable subset of 'Data.IntMap.IntMap'.+-- The interface of a 'Map' is a suitable subset of 'Data.IntMap.IntMap'+-- and can be used as a drop-in replacement of 'Data.Map.Map'. -- -- The complexity of operations is determined by the complexities of -- 'Data.IntMap.IntMap' and 'Data.Map.Map' operations. See the sources of--- 'HashMap' to see which operations from @containers@ package are used.+-- 'Map' to see which operations from @containers@ package are used. ----------------------------------------------------------------------------- -module Data.HashMap ( HashMap+module Data.HashMap ( Map+                    , HashMap                      -- * Operators                     , (!), (\\)@@ -139,13 +142,13 @@  -- | Find the value at a key. -- Calls 'error' when the element can not be found.-(!) :: (Hashable k, Ord k) => HashMap k a -> k -> a+(!) :: (Hashable k, Ord k) => Map k a -> k -> a m ! k = case lookup k m of           Nothing -> error "HashMap.(!): key not an element of the map"           Just v -> v  -- | Same as 'difference'.-(\\) :: Ord k => HashMap k a -> HashMap k b -> HashMap k a+(\\) :: Ord k => Map k a -> Map k b -> Map k a m1 \\ m2 = difference m1 m2  @@ -155,33 +158,38 @@  data Some k v = Only !k v | More !(M.Map k v) deriving (Eq, Ord) --- | The abstract type of a @HashMap@. Its interface is a suitable+-- | The abstract type of a @Map@. Its interface is a suitable -- subset of 'Data.IntMap.IntMap'.-newtype HashMap k v = HashMap (I.IntMap (Some k v)) deriving (Eq, Ord)+newtype Map k v = Map (I.IntMap (Some k v)) deriving (Eq, Ord) -instance Functor (HashMap k) where+-- | The @HashMap@ is a type synonym for @Map@ for backward compatibility.+-- It is deprecated and will be removed in furture releases.+{-# DEPRECATED HashMap "HashMap is deprecated. Please use Map instead." #-}+type HashMap k v = Map k v++instance Functor (Map k) where   fmap = map -instance Ord k => Monoid (HashMap k a) where+instance Ord k => Monoid (Map k a) where   mempty  = empty   mappend = union   mconcat = unions -instance Foldable (HashMap k) where-  foldMap f (HashMap m) = foldMap some_fold m+instance Foldable (Map k) where+  foldMap f (Map m) = foldMap some_fold m     where some_fold (Only _ x) = f x           some_fold (More s)   = foldMap f s -instance Traversable (HashMap k) where-  traverse f (HashMap m) = pure HashMap <*> traverse some_traverse m+instance Traversable (Map k) where+  traverse f (Map m) = pure Map <*> traverse some_traverse m     where some_traverse (Only k x) = pure (Only k) <*> f x           some_traverse (More s) = pure More <*> traverse f s -instance (Show k, Show a) => Show (HashMap k a) where+instance (Show k, Show a) => Show (Map k a) where   showsPrec d m   = showParen (d > 10) $     showString "fromList " . shows (toList m) -instance (Read k, Hashable k, Ord k, Read a) => Read (HashMap k a) where+instance (Read k, Hashable k, Ord k, Read a) => Read (Map k a) where #ifdef __GLASGOW_HASKELL__   readPrec = parens $ prec 10 $ do     Ident "fromList" <- lexP@@ -197,7 +205,7 @@ #endif  #include "Typeable.h"-INSTANCE_TYPEABLE2(HashMap,hashMapTc,"HashMap")+INSTANCE_TYPEABLE2(Map,mapTc,"Map")   @@ -209,11 +217,11 @@ -- This instance preserves data abstraction at the cost of inefficiency. -- We omit reflection services for the sake of data abstraction. -instance (Data k, Hashable k, Ord k, Data a) => Data (HashMap k a) where+instance (Data k, Hashable k, Ord k, Data a) => Data (Map k a) where   gfoldl f z m = z fromList `f` (toList m)   toConstr _   = error "toConstr"   gunfold _ _  = error "gunfold"-  dataTypeOf _ = mkNoRepType "Data.HashMap.HashMap"+  dataTypeOf _ = mkNoRepType "Data.HashMap.Map"   dataCast1 f  = gcast1 f #endif @@ -234,23 +242,23 @@   Query --------------------------------------------------------------------} -- | Is the map empty?-null :: HashMap k a -> Bool-null (HashMap m) = I.null m+null :: Map k a -> Bool+null (Map m) = I.null m  -- | Number of elements in the map.-size :: HashMap k a -> Int-size (HashMap m) = I.fold ((+) . some_size) 0 m+size :: Map k a -> Int+size (Map m) = I.fold ((+) . some_size) 0 m   where some_size (Only _ _) = 1         some_size (More s) = M.size s  -- | Is the key a member of the map?-member :: (Hashable k, Ord k) => k -> HashMap k a -> Bool+member :: (Hashable k, Ord k) => k -> Map k a -> Bool member k m = case lookup k m of                Nothing -> False                Just _  -> True  -- | Is the key not a member of the map?-notMember :: (Hashable k, Ord k) => k -> HashMap k a -> Bool+notMember :: (Hashable k, Ord k) => k -> Map k a -> Bool notMember k m = not $ member k m  some_lookup :: Ord k => k -> Some k a -> Maybe a@@ -259,12 +267,12 @@ some_lookup k (More s) = M.lookup k s  -- | Lookup the value at a key in the map.-lookup :: (Hashable k, Ord k) => k -> HashMap k a -> Maybe a-lookup k (HashMap m) = I.lookup (hash k) m >>= some_lookup k+lookup :: (Hashable k, Ord k) => k -> Map k a -> Maybe a+lookup k (Map m) = I.lookup (hash k) m >>= some_lookup k  -- | The expression @('findWithDefault' def k map)@ returns the value at key -- @k@ or returns @def@ when the key is not an element of the map.-findWithDefault :: (Hashable k, Ord k) => a -> k -> HashMap k a -> a+findWithDefault :: (Hashable k, Ord k) => a -> k -> Map k a -> a findWithDefault def k m = case lookup k m of                             Nothing -> def                             Just x  -> x@@ -274,12 +282,12 @@   Construction --------------------------------------------------------------------} -- | The empty map.-empty :: HashMap k a-empty = HashMap I.empty+empty :: Map k a+empty = Map I.empty  -- | A map of one element.-singleton :: Hashable k => k -> a -> HashMap k a-singleton k x = HashMap $+singleton :: Hashable k => k -> a -> Map k a+singleton k x = Map $   I.singleton (hash k) $ (Only k x)  @@ -290,8 +298,8 @@ -- the map, the associated value is replaced with the supplied value, i.e. -- 'insert' is equivalent to @'insertWith' 'const'@. insert :: (Hashable k, Ord k)-       => k -> a -> HashMap k a -> HashMap k a-insert k x (HashMap m) = HashMap $+       => k -> a -> Map k a -> Map k a+insert k x (Map m) = Map $   I.insertWith some_insert (hash k) (Only k x) m   where some_insert _ (Only k' x') | k `eq` k' = Only k x                                    | otherwise = More $ M.insert k x (M.singleton k' x')@@ -301,8 +309,8 @@ -- insert the pair (key, value) into @mp@ if key does not exist in the map. If -- the key does exist, the function will insert @f new_value old_value@. insertWith :: (Hashable k, Ord k)-           => (a -> a -> a) -> k -> a -> HashMap k a -> HashMap k a-insertWith f k x (HashMap m) = HashMap $+           => (a -> a -> a) -> k -> a -> Map k a -> Map k a+insertWith f k x (Map m) = Map $   I.insertWith some_insert_with (hash k) (Only k x) m   where some_insert_with _ (Only k' x') | k `eq` k' = Only k (f x x')                                         | otherwise = More $ M.insert k x (M.singleton k' x')@@ -312,8 +320,8 @@ -- insert the pair (key, value) into @mp@ if key does not exist in the map. If -- the key does exist, the function will insert @f key new_value old_value@. insertWithKey :: (Hashable k, Ord k)-              => (k -> a -> a -> a) -> k -> a -> HashMap k a -> HashMap k a-insertWithKey f k x (HashMap m) = HashMap $+              => (k -> a -> a -> a) -> k -> a -> Map k a -> Map k a+insertWithKey f k x (Map m) = Map $   I.insertWith some_insert_with_key (hash k) (Only k x) m   where some_insert_with_key _ (Only k' x') | k `eq` k' = Only k (f k x x')                                             | otherwise = More $ M.insert k x (M.singleton k' x')@@ -323,10 +331,10 @@ -- first element is equal to (@'lookup' k map@) and the second element equal to -- (@'insertWithKey' f k x map@). insertLookupWithKey :: (Hashable k, Ord k)-                    => (k -> a -> a -> a) -> k -> a -> HashMap k a -> (Maybe a, HashMap k a)-insertLookupWithKey f k x (HashMap m) =+                    => (k -> a -> a -> a) -> k -> a -> Map k a -> (Maybe a, Map k a)+insertLookupWithKey f k x (Map m) =   case I.insertLookupWithKey some_insert_with_key (hash k) (Only k x) m of-    (found, m') -> (found >>= some_lookup k, HashMap m')+    (found, m') -> (found >>= some_lookup k, Map m')   where some_insert_with_key _ _ (Only k' x') | k `eq` k' = Only k (f k x x')                                               | otherwise = More $ M.insert k x (M.singleton k' x')         some_insert_with_key _ _ (More s) = More $ M.insertWithKey f k x s@@ -348,8 +356,8 @@ -- | Delete a key and its value from the map. When the key is not -- a member of the map, the original map is returned. delete :: (Hashable k, Ord k)-       => k -> HashMap k a -> HashMap k a-delete k (HashMap m) = HashMap $+       => k -> Map k a -> Map k a+delete k (Map m) = Map $   I.update some_delete (hash k) m   where some_delete v@(Only k' _) | k `eq` k'  = Nothing                                   | otherwise  = Just v@@ -358,8 +366,8 @@ -- | Adjust a value at a specific key. When the key is not a member of the map, -- the original map is returned. adjust :: (Hashable k, Ord k)-       => (a -> a) -> k -> HashMap k a -> HashMap k a-adjust f k (HashMap m) = HashMap $+       => (a -> a) -> k -> Map k a -> Map k a+adjust f k (Map m) = Map $   I.adjust some_adjust (hash k) m   where some_adjust v@(Only k' x) | k `eq` k'  = Only k (f x)                                   | otherwise  = v@@ -368,8 +376,8 @@ -- | Adjust a value at a specific key. When the key is not a member of the map, -- the original map is returned. adjustWithKey :: (Hashable k, Ord k)-              => (k -> a -> a) -> k -> HashMap k a -> HashMap k a-adjustWithKey f k (HashMap m) = HashMap $+              => (k -> a -> a) -> k -> Map k a -> Map k a+adjustWithKey f k (Map m) = Map $   I.adjust some_adjust_with_key (hash k) m   where some_adjust_with_key v@(Only k' x) | k `eq` k'  = Only k (f k x)                                            | otherwise  = v@@ -379,8 +387,8 @@ -- in the map). If (@f x@) is 'Nothing', the element is deleted. If it is -- (@'Just' y@), the key @k@ is bound to the new value @y@. update :: (Hashable k, Ord k)-       => (a -> Maybe a) -> k -> HashMap k a -> HashMap k a-update f k (HashMap m) = HashMap $+       => (a -> Maybe a) -> k -> Map k a -> Map k a+update f k (Map m) = Map $   I.update some_update (hash k) m   where some_update v@(Only k' x) | k `eq` k' = f x >>= return . Only k'                                   | otherwise = Just v@@ -390,8 +398,8 @@ -- in the map). If (@f k x@) is 'Nothing', the element is deleted. If it is -- (@'Just' y@), the key @k@ is bound to the new value @y@. updateWithKey :: (Hashable k, Ord k)-              => (k -> a -> Maybe a) -> k -> HashMap k a -> HashMap k a-updateWithKey f k (HashMap m) = HashMap $+              => (k -> a -> Maybe a) -> k -> Map k a -> Map k a+updateWithKey f k (Map m) = Map $   I.update some_update_with_key (hash k) m   where some_update_with_key v@(Only k' x) | k `eq` k' = f k x >>= return . Only k'                                            | otherwise = Just v@@ -401,20 +409,20 @@ -- This is different behavior than 'Data.Map.updateLookupWithKey'.  Returns the -- original key value if the map entry is deleted. updateLookupWithKey :: (Hashable k, Ord k)-                    => (k -> a -> Maybe a) -> k -> HashMap k a -> (Maybe a, HashMap k a)-updateLookupWithKey f k (HashMap m) =+                    => (k -> a -> Maybe a) -> k -> Map k a -> (Maybe a, Map k a)+updateLookupWithKey f k (Map m) =   case I.updateLookupWithKey some_update_with_key (hash k) m of-    (found, m') -> (found >>= some_lookup k, HashMap m')+    (found, m') -> (found >>= some_lookup k, Map m')   where some_update_with_key _ v@(Only k' x) | k `eq` k' = f k x >>= return . Only k'                                              | otherwise = Just v         some_update_with_key _ (More t) = some_norm $ M.updateWithKey f k t  -- | The expression (@'alter' f k map@) alters the value @x@ at @k@, or absence -- thereof.  'alter' can be used to insert, delete, or update a value in an--- 'HashMap'.+-- 'Map'. alter :: (Hashable k, Ord k)-      => (Maybe a -> Maybe a) -> k -> HashMap k a -> HashMap k a-alter f k (HashMap m) = HashMap $+      => (Maybe a -> Maybe a) -> k -> Map k a -> Map k a+alter f k (Map m) = Map $   I.alter some_alter (hash k) m   where some_alter Nothing = f Nothing >>= return . Only k         some_alter (Just v@(Only k' x)) | k `eq` k' = f (Just x) >>= return . Only k'@@ -426,18 +434,18 @@   Union --------------------------------------------------------------------} -- | The union of a list of maps.-unions :: Ord k => [HashMap k a] -> HashMap k a+unions :: Ord k => [Map k a] -> Map k a unions xs = foldl' union empty xs  -- | The union of a list of maps, with a combining operation.-unionsWith :: Ord k => (a->a->a) -> [HashMap k a] -> HashMap k a+unionsWith :: Ord k => (a->a->a) -> [Map k a] -> Map k a unionsWith f xs = foldl' (unionWith f) empty xs  -- | The (left-biased) union of two maps. -- It prefers the first map when duplicate keys are encountered, -- i.e. (@'union' == 'unionWith' 'const'@).-union :: Ord k => HashMap k a -> HashMap k a -> HashMap k a-union (HashMap m1) (HashMap m2) = HashMap $+union :: Ord k => Map k a -> Map k a -> Map k a+union (Map m1) (Map m2) = Map $   I.unionWith some_union m1 m2   where some_union v@(Only k x) (Only l y) | k `eq` l  = v                                            | otherwise = More (M.singleton k x `M.union` M.singleton l y)@@ -453,21 +461,21 @@ some_union_with_key f (More t) (More u) = More $ M.unionWithKey f t u  -- | The union with a combining function.-unionWith :: Ord k => (a -> a -> a) -> HashMap k a -> HashMap k a -> HashMap k a-unionWith f (HashMap m1) (HashMap m2) = HashMap $+unionWith :: Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k a+unionWith f (Map m1) (Map m2) = Map $   I.unionWith (some_union_with_key $ const f) m1 m2  -- | The union with a combining function.-unionWithKey :: Ord k => (k -> a -> a -> a) -> HashMap k a -> HashMap k a -> HashMap k a-unionWithKey f (HashMap m1) (HashMap m2) = HashMap $+unionWithKey :: Ord k => (k -> a -> a -> a) -> Map k a -> Map k a -> Map k a+unionWithKey f (Map m1) (Map m2) = Map $   I.unionWith (some_union_with_key f) m1 m2  {--------------------------------------------------------------------   Difference --------------------------------------------------------------------} -- | Difference between two maps (based on keys).-difference :: Ord k => HashMap k a -> HashMap k b -> HashMap k a-difference (HashMap m1) (HashMap m2) = HashMap $+difference :: Ord k => Map k a -> Map k b -> Map k a+difference (Map m1) (Map m2) = Map $   I.differenceWith some_diff m1 m2   where some_diff v@(Only k _) (Only l _) | k `eq` l  = Nothing                                           | otherwise = Just v@@ -484,16 +492,16 @@ some_diff_with_key f (More t) (More u) = some_norm $ M.differenceWithKey f t u  -- | Difference with a combining function.-differenceWith :: Ord k => (a -> b -> Maybe a) -> HashMap k a -> HashMap k b -> HashMap k a-differenceWith f (HashMap m1) (HashMap m2) = HashMap $+differenceWith :: Ord k => (a -> b -> Maybe a) -> Map k a -> Map k b -> Map k a+differenceWith f (Map m1) (Map m2) = Map $   I.differenceWith (some_diff_with_key $ const f) m1 m2  -- | Difference with a combining function. When two equal keys are -- encountered, the combining function is applied to the key and both values. -- If it returns 'Nothing', the element is discarded (proper set difference). -- If it returns (@'Just' y@), the element is updated with a new value @y@.-differenceWithKey :: Ord k => (k -> a -> b -> Maybe a) -> HashMap k a -> HashMap k b -> HashMap k a-differenceWithKey f (HashMap m1) (HashMap m2) = HashMap $+differenceWithKey :: Ord k => (k -> a -> b -> Maybe a) -> Map k a -> Map k b -> Map k a+differenceWithKey f (Map m1) (Map m2) = Map $   I.differenceWith (some_diff_with_key f) m1 m2  @@ -506,8 +514,8 @@         some_empty (More t) = not $ M.null t  -- | The (left-biased) intersection of two maps (based on keys).-intersection :: Ord k => HashMap k a -> HashMap k b -> HashMap k a-intersection (HashMap m1) (HashMap m2) = HashMap $ delete_empty $+intersection :: Ord k => Map k a -> Map k b -> Map k a+intersection (Map m1) (Map m2) = Map $ delete_empty $   I.intersectionWith some_intersection m1 m2   where some_intersection v@(Only k _) (Only l _) | k `eq` l  = v                                                   | otherwise = More (M.empty)@@ -524,13 +532,13 @@ some_intersection_with_key f (More t) (More u) = some_norm' $ M.intersectionWithKey f t u  -- | The intersection with a combining function.-intersectionWith :: Ord k => (a -> b -> c) -> HashMap k a -> HashMap k b -> HashMap k c-intersectionWith f (HashMap m1) (HashMap m2) = HashMap $ delete_empty $+intersectionWith :: Ord k => (a -> b -> c) -> Map k a -> Map k b -> Map k c+intersectionWith f (Map m1) (Map m2) = Map $ delete_empty $   I.intersectionWith (some_intersection_with_key $ const f) m1 m2  -- | The intersection with a combining function.-intersectionWithKey :: Ord k => (k -> a -> b -> c) -> HashMap k a -> HashMap k b -> HashMap k c-intersectionWithKey f (HashMap m1) (HashMap m2) = HashMap $ delete_empty $+intersectionWithKey :: Ord k => (k -> a -> b -> c) -> Map k a -> Map k b -> Map k c+intersectionWithKey f (Map m1) (Map m2) = Map $ delete_empty $   I.intersectionWith (some_intersection_with_key f) m1 m2  @@ -538,19 +546,19 @@   Submap --------------------------------------------------------------------} -- | Is this a proper submap? (ie. a submap but not equal).-isProperSubmapOf :: (Ord k, Eq a) => HashMap k a -> HashMap k a -> Bool+isProperSubmapOf :: (Ord k, Eq a) => Map k a -> Map k a -> Bool isProperSubmapOf m1 m2 = isSubmapOf m1 m2 && size m1 < size m2  -- | Is this a proper submap? (ie. a submap but not equal).  The expression -- (@'isProperSubmapOfBy' f m1 m2@) returns 'True' when @m1@ and @m2@ are not -- equal, all keys in @m1@ are in @m2@, and when @f@ returns 'True' when -- applied to their respective values.-isProperSubmapOfBy :: Ord k => (a -> b -> Bool) -> HashMap k a -> HashMap k b -> Bool+isProperSubmapOfBy :: Ord k => (a -> b -> Bool) -> Map k a -> Map k b -> Bool isProperSubmapOfBy f m1 m2 = isSubmapOfBy f m1 m2 && size m1 < size m2  -- | Is this a submap?-isSubmapOf :: (Ord k, Eq a) => HashMap k a -> HashMap k a -> Bool-isSubmapOf (HashMap m1) (HashMap m2) =+isSubmapOf :: (Ord k, Eq a) => Map k a -> Map k a -> Bool+isSubmapOf (Map m1) (Map m2) =   I.isSubmapOfBy some_isSubmapOf m1 m2   where some_isSubmapOf (Only k _) (Only l _) = k `eq` l         some_isSubmapOf (Only k _) (More t)   = k `M.member` t@@ -560,8 +568,8 @@ -- | The expression (@'isSubmapOfBy' f m1 m2@) returns 'True' if all keys in -- @m1@ are in @m2@, and when @f@ returns 'True' when applied to their -- respective values.-isSubmapOfBy :: Ord k => (a -> b -> Bool) -> HashMap k a -> HashMap k b -> Bool-isSubmapOfBy f (HashMap m1) (HashMap m2) =+isSubmapOfBy :: Ord k => (a -> b -> Bool) -> Map k a -> Map k b -> Bool+isSubmapOfBy f (Map m1) (Map m2) =   I.isSubmapOfBy some_isSubmapOfBy m1 m2   where some_isSubmapOfBy (Only k x) (Only l y) = k `eq` l && x `f` y         some_isSubmapOfBy (Only k x) (More t) | Just y <- M.lookup k t = f x y@@ -574,34 +582,34 @@   Mapping --------------------------------------------------------------------} -- | Map a function over all values in the map.-map :: (a -> b) -> HashMap k a -> HashMap k b-map f (HashMap m) = HashMap $+map :: (a -> b) -> Map k a -> Map k b+map f (Map m) = Map $   I.map some_map m   where some_map (Only k x) = Only k $ f x         some_map (More t)   = More $ M.map f t  -- | Map a function over all values in the map.-mapWithKey :: (k -> a -> b) -> HashMap k a -> HashMap k b-mapWithKey f (HashMap m) = HashMap $+mapWithKey :: (k -> a -> b) -> Map k a -> Map k b+mapWithKey f (Map m) = Map $   I.map some_map_with_key m   where some_map_with_key (Only k x) = Only k $ f k x         some_map_with_key (More t)   = More $ M.mapWithKey f t  -- | The function @'mapAccum'@ threads an accumulating argument through the map -- in unspecified order of keys.-mapAccum :: (a -> b -> (a,c)) -> a -> HashMap k b -> (a,HashMap k c)-mapAccum f a (HashMap m) =+mapAccum :: (a -> b -> (a,c)) -> a -> Map k b -> (a,Map k c)+mapAccum f a (Map m) =   case I.mapAccum some_map_accum a m of-    (acc, m') -> (acc, HashMap m')+    (acc, m') -> (acc, Map m')   where some_map_accum acc (Only k x) = case f acc x of (acc', x') -> (acc', Only k x')         some_map_accum acc (More t)   = case M.mapAccum f acc t of (acc', t') -> (acc', More t')  -- | The function @'mapAccumWithKey'@ threads an accumulating argument through -- the map in unspecified order of keys.-mapAccumWithKey :: (a -> k -> b -> (a,c)) -> a -> HashMap k b -> (a,HashMap k c)-mapAccumWithKey f a (HashMap m) =+mapAccumWithKey :: (a -> k -> b -> (a,c)) -> a -> Map k b -> (a,Map k c)+mapAccumWithKey f a (Map m) =   case I.mapAccum some_map_accum_with_key a m of-    (acc, m') -> (acc, HashMap m')+    (acc, m') -> (acc, Map m')   where some_map_accum_with_key acc (Only k x) = case f acc k x of (acc', x') -> (acc', Only k x')         some_map_accum_with_key acc (More t)   = case M.mapAccumWithKey f acc t of (acc', t') -> (acc', More t') @@ -610,16 +618,16 @@   Filter --------------------------------------------------------------------} -- | Filter all values that satisfy some predicate.-filter :: Ord k => (a -> Bool) -> HashMap k a -> HashMap k a-filter p (HashMap m) = HashMap $+filter :: Ord k => (a -> Bool) -> Map k a -> Map k a+filter p (Map m) = Map $   I.mapMaybe some_filter m   where some_filter v@(Only _ x) | p x       = Just v                                  | otherwise = Nothing         some_filter (More t) = some_norm $ M.filter p t  -- | Filter all keys\/values that satisfy some predicate.-filterWithKey :: Ord k => (k -> a -> Bool) -> HashMap k a -> HashMap k a-filterWithKey p (HashMap m) = HashMap $+filterWithKey :: Ord k => (k -> a -> Bool) -> Map k a -> Map k a+filterWithKey p (Map m) = Map $   I.mapMaybe some_filter_with_key m   where some_filter_with_key v@(Only k x) | p k x     = Just v                                           | otherwise = Nothing@@ -628,35 +636,35 @@ -- | Partition the map according to some predicate. The first map contains all -- elements that satisfy the predicate, the second all elements that fail the -- predicate.-partition :: Ord k => (a -> Bool) -> HashMap k a -> (HashMap k a, HashMap k a)+partition :: Ord k => (a -> Bool) -> Map k a -> (Map k a, Map k a) partition p m = (filter p m, filter (not . p) m)  -- | Partition the map according to some predicate. The first map contains all -- elements that satisfy the predicate, the second all elements that fail the -- predicate.-partitionWithKey :: Ord k => (k -> a -> Bool) -> HashMap k a -> (HashMap k a, HashMap k a)+partitionWithKey :: Ord k => (k -> a -> Bool) -> Map k a -> (Map k a, Map k a) partitionWithKey p m = (filterWithKey p m, filterWithKey (\k -> not . p k) m)  -- | Map values and collect the 'Just' results.-mapMaybe :: Ord k => (a -> Maybe b) -> HashMap k a -> HashMap k b-mapMaybe f (HashMap m) = HashMap $+mapMaybe :: Ord k => (a -> Maybe b) -> Map k a -> Map k b+mapMaybe f (Map m) = Map $   I.mapMaybe some_map_maybe m   where some_map_maybe (Only k x) = f x >>= return . Only k         some_map_maybe (More t) = some_norm $ M.mapMaybe f t  -- | Map keys\/values and collect the 'Just' results.-mapMaybeWithKey :: Ord k => (k -> a -> Maybe b) -> HashMap k a -> HashMap k b-mapMaybeWithKey f (HashMap m) = HashMap $+mapMaybeWithKey :: Ord k => (k -> a -> Maybe b) -> Map k a -> Map k b+mapMaybeWithKey f (Map m) = Map $   I.mapMaybe some_map_maybe_with_key m   where some_map_maybe_with_key (Only k x) = f k x >>= return . Only k         some_map_maybe_with_key (More t) = some_norm $ M.mapMaybeWithKey f t  -- | Map values and separate the 'Left' and 'Right' results.-mapEither :: Ord k => (a -> Either b c) -> HashMap k a -> (HashMap k b, HashMap k c)+mapEither :: Ord k => (a -> Either b c) -> Map k a -> (Map k b, Map k c) mapEither f m = (mapMaybe (maybe_left . f) m, mapMaybe (maybe_right . f) m)  -- | Map keys\/values and separate the 'Left' and 'Right' results.-mapEitherWithKey :: Ord k => (k -> a -> Either b c) -> HashMap k a -> (HashMap k b, HashMap k c)+mapEitherWithKey :: Ord k => (k -> a -> Either b c) -> Map k a -> (Map k b, Map k c) mapEitherWithKey f m = (mapMaybeWithKey (\k a -> maybe_left  (f k a)) m                        ,mapMaybeWithKey (\k a -> maybe_right (f k a)) m) @@ -675,15 +683,15 @@ --------------------------------------------------------------------} -- | Fold the values in the map, such that @'fold' f z == 'Prelude.foldr' -- f z . 'elems'@.-fold :: (a -> b -> b) -> b -> HashMap k a -> b-fold f z (HashMap m) = I.fold some_fold z m+fold :: (a -> b -> b) -> b -> Map k a -> b+fold f z (Map m) = I.fold some_fold z m   where some_fold (Only _ x) y = f x y         some_fold (More t) y   = M.fold f y t  -- | Fold the keys and values in the map, such that @'foldWithKey' f z == -- 'Prelude.foldr' ('uncurry' f) z . 'toAscList'@.-foldWithKey :: (k -> a -> b -> b) -> b -> HashMap k a -> b-foldWithKey f z (HashMap m) = I.fold some_fold_with_key z m+foldWithKey :: (k -> a -> b -> b) -> b -> Map k a -> b+foldWithKey f z (Map m) = I.fold some_fold_with_key z m   where some_fold_with_key (Only k x) y = f k x y         some_fold_with_key (More t) y   = M.foldWithKey f y t @@ -692,25 +700,25 @@   List variations --------------------------------------------------------------------} -- | Return all elements of the map in arbitrary order of their keys.-elems :: HashMap k a -> [a]-elems (HashMap m) = I.fold some_append_elems [] m+elems :: Map k a -> [a]+elems (Map m) = I.fold some_append_elems [] m   where some_append_elems (Only _ x) acc = x : acc         some_append_elems (More t) acc   = M.elems t ++ acc  -- | Return all keys of the map in arbitrary order.-keys  :: HashMap k a -> [k]-keys (HashMap m) = I.fold some_append_keys [] m+keys  :: Map k a -> [k]+keys (Map m) = I.fold some_append_keys [] m   where some_append_keys (Only k _) acc = k : acc         some_append_keys (More t) acc   = M.keys t ++ acc  -- | The set of all keys of the map.-keysSet :: Ord k => HashMap k a -> S.Set k-keysSet (HashMap m) = I.fold (S.union . some_keys_set) S.empty m+keysSet :: Ord k => Map k a -> S.Set k+keysSet (Map m) = I.fold (S.union . some_keys_set) S.empty m   where some_keys_set (Only k _) = S.singleton k         some_keys_set (More t)   = M.keysSet t  -- | Return all key\/value pairs in the map in arbitrary key order.-assocs :: HashMap k a -> [(k,a)]+assocs :: Map k a -> [(k,a)] assocs = toList  @@ -718,21 +726,21 @@   Lists --------------------------------------------------------------------} -- | Convert the map to a list of key\/value pairs.-toList :: HashMap k a -> [(k,a)]-toList (HashMap m) =+toList :: Map k a -> [(k,a)]+toList (Map m) =   I.fold some_append [] m   where some_append (Only k x) acc = (k, x) : acc         some_append (More t) acc   = M.toList t ++ acc  -- | Create a map from a list of key\/value pairs. fromList :: (Hashable k, Ord k)-         => [(k,a)] -> HashMap k a+         => [(k,a)] -> Map k a fromList xs = foldl' (\m (k, x) -> insert k x m) empty xs  -- | Create a map from a list of key\/value pairs with a combining function.-fromListWith :: (Hashable k, Ord k) => (a -> a -> a) -> [(k,a)] -> HashMap k a+fromListWith :: (Hashable k, Ord k) => (a -> a -> a) -> [(k,a)] -> Map k a fromListWith f xs = foldl' (\m (k, x) -> insertWith f k x m) empty xs  -- | Build a map from a list of key\/value pairs with a combining function.-fromListWithKey :: (Hashable k, Ord k) => (k -> a -> a -> a) -> [(k,a)] -> HashMap k a+fromListWithKey :: (Hashable k, Ord k) => (k -> a -> a -> a) -> [(k,a)] -> Map k a fromListWithKey f xs = foldl' (\m (k, x) -> insertWithKey f k x m) empty xs
Data/HashSet.hs view
@@ -4,29 +4,32 @@ ----------------------------------------------------------------------------- -- | -- Module      :  Data.HashSet--- Copyright   :  (c) Milan Straka 2010+-- Copyright   :  (c) Milan Straka 2011 -- License     :  BSD-style -- Maintainer  :  fox@ucw.cz -- Stability   :  provisional -- Portability :  portable ----- Persistent 'HashSet', which is defined as+-- Persistent 'Set' based on hashing, which is defined as -- -- @---   data 'HashSet' e = 'Data.IntMap.IntMap' ('Data.Set.Set' e)+--   data 'Set' e = 'Data.IntMap.IntMap' (Some e) -- @ -- -- is an 'Data.IntMap.IntMap' indexed by hash values of elements,--- containing a set @'Data.Set.Set' e@ with elements of the same hash values.+-- containing a value of @Some e@. That contains either one 'e'+-- or a @'Data.Set.Set' e@ with elements of the same hash values. ----- The interface of a 'HashSet' is a suitable subset of 'Data.IntSet.IntSet'.+-- The interface of a 'Set' is a suitable subset of 'Data.IntSet.IntSet'+-- and can be used as a drop-in replacement of 'Data.Set.Set'. -- -- The complexity of operations is determined by the complexities of -- 'Data.IntMap.IntMap' and 'Data.Set.Set' operations. See the sources of--- 'HashSet' to see which operations from @containers@ package are used.+-- 'Set' to see which operations from @containers@ package are used. ----------------------------------------------------------------------------- -module Data.HashSet ( HashSet+module Data.HashSet ( Set+                    , HashSet                      -- * Operators                     , (\\)@@ -88,7 +91,7 @@ --------------------------------------------------------------------}  -- | Same as 'difference'.-(\\) :: Ord a => HashSet a -> HashSet a -> HashSet a+(\\) :: Ord a => Set a -> Set a -> Set a s1 \\ s2 = difference s1 s2  @@ -98,20 +101,25 @@  data Some a = Only !a | More !(S.Set a) deriving (Eq, Ord) --- | The abstract type of a @HashSet@. Its interface is a suitable+-- | The abstract type of a @Set@. Its interface is a suitable -- subset of 'Data.IntSet.IntSet'.-newtype HashSet a = HashSet (I.IntMap (Some a)) deriving (Eq, Ord)+newtype Set a = Set (I.IntMap (Some a)) deriving (Eq, Ord) -instance Ord a => Monoid (HashSet a) where+-- | The @HashSet@ is a type synonym for @Set@ for backward compatibility.+-- It is deprecated and will be removed in furture releases.+{-# DEPRECATED HashSet "HashSet is deprecated. Please use Set instead." #-}+type HashSet a = Set a++instance Ord a => Monoid (Set a) where   mempty  = empty   mappend = union   mconcat = unions -instance Show a => Show (HashSet a) where+instance Show a => Show (Set a) where   showsPrec d m   = showParen (d > 10) $     showString "fromList " . shows (toList m) -instance (Hashable a, Ord a, Read a) => Read (HashSet a) where+instance (Hashable a, Ord a, Read a) => Read (Set a) where #ifdef __GLASGOW_HASKELL__   readPrec = parens $ prec 10 $ do     Ident "fromList" <- lexP@@ -127,7 +135,7 @@ #endif  #include "Typeable.h"-INSTANCE_TYPEABLE1(HashSet,hashSetTc,"HashSet")+INSTANCE_TYPEABLE1(Set,setTc,"Set")   #if __GLASGOW_HASKELL__@@ -138,11 +146,11 @@ -- This instance preserves data abstraction at the cost of inefficiency. -- We omit reflection services for the sake of data abstraction. -instance (Hashable a, Ord a, Data a) => Data (HashSet a) where+instance (Hashable a, Ord a, Data a) => Data (Set a) where   gfoldl f z m = z fromList `f` (toList m)   toConstr _   = error "toConstr"   gunfold _ _  = error "gunfold"-  dataTypeOf _ = mkNoRepType "Data.HashSet.HashSet"+  dataTypeOf _ = mkNoRepType "Data.HashSet.Set"   dataCast1 f  = gcast1 f #endif @@ -162,30 +170,30 @@   Query --------------------------------------------------------------------} -- | Is the set empty?-null :: HashSet a -> Bool-null (HashSet s) = I.null s+null :: Set a -> Bool+null (Set s) = I.null s  -- | Number of elements in the set.-size :: HashSet a -> Int-size (HashSet s) = I.fold ((+) . some_size) 0 s+size :: Set a -> Int+size (Set s) = I.fold ((+) . some_size) 0 s   where some_size (Only _) = 1         some_size (More t) = S.size t  -- | Is the element a member of the set?-member :: (Hashable a, Ord a) => a -> HashSet a -> Bool-member a (HashSet s) =+member :: (Hashable a, Ord a) => a -> Set a -> Bool+member a (Set s) =   case I.lookup (hash a) s of     Nothing -> False     Just (Only a') -> a `eq` a'     Just (More s') -> S.member a s'  -- | Is the element not a member of the set?-notMember :: (Hashable a, Ord a) => a -> HashSet a -> Bool+notMember :: (Hashable a, Ord a) => a -> Set a -> Bool notMember k s = not $ member k s  -- | Is this a subset?-isSubsetOf :: Ord a => HashSet a -> HashSet a -> Bool-isSubsetOf (HashSet s1) (HashSet s2) =+isSubsetOf :: Ord a => Set a -> Set a -> Bool+isSubsetOf (Set s1) (Set s2) =   I.isSubmapOfBy (some_isSubsetOf) s1 s2   where some_isSubsetOf (Only a) (Only b) = a `eq` b         some_isSubsetOf (Only a) (More s) = a `S.member` s@@ -193,7 +201,7 @@         some_isSubsetOf (More s) (More t) = s `S.isSubsetOf` t  -- | Is this a proper subset? (ie. a subset but not equal).-isProperSubsetOf :: Ord a => HashSet a -> HashSet a -> Bool+isProperSubsetOf :: Ord a => Set a -> Set a -> Bool isProperSubsetOf s1 s2 = isSubsetOf s1 s2 && size s1 < size s2  @@ -201,18 +209,18 @@   Construction --------------------------------------------------------------------} -- | The empty set.-empty :: HashSet a-empty = HashSet I.empty+empty :: Set a+empty = Set I.empty  -- | A set of one element.-singleton :: Hashable a => a -> HashSet a-singleton a = HashSet $+singleton :: Hashable a => a -> Set a+singleton a = Set $   I.singleton (hash a) $ Only a  -- | Add a value to the set. When the value is already an element of the set, -- it is replaced by the new one, ie. 'insert' is left-biased.-insert :: (Hashable a, Ord a) => a -> HashSet a -> HashSet a-insert a (HashSet s) = HashSet $+insert :: (Hashable a, Ord a) => a -> Set a -> Set a+insert a (Set s) = Set $   I.insertWith some_insert (hash a) (Only a) s   where some_insert _ v@(Only b) | a `eq` b    = v                                  | otherwise = More $ S.insert a (S.singleton b)@@ -230,8 +238,8 @@  -- | Delete a value in the set. Returns the original set when the value was not -- present.-delete :: (Hashable a, Ord a) => a -> HashSet a -> HashSet a-delete a (HashSet s) = HashSet $+delete :: (Hashable a, Ord a) => a -> Set a -> Set a+delete a (Set s) = Set $   I.update some_delete (hash a) s   where some_delete v@(Only b) | a `eq` b  = Nothing                                | otherwise = Just v@@ -243,8 +251,8 @@ --------------------------------------------------------------------}  -- | The union of two sets.-union :: Ord a => HashSet a -> HashSet a -> HashSet a-union (HashSet s1) (HashSet s2) = HashSet $ I.unionWith some_union s1 s2+union :: Ord a => Set a -> Set a -> Set a+union (Set s1) (Set s2) = Set $ I.unionWith some_union s1 s2   where some_union v@(Only a) (Only b) | a `eq` b  = v                                        | otherwise = More (S.singleton a `S.union` S.singleton b)         some_union (Only a) (More s) = More $ S.singleton a `S.union` s@@ -252,12 +260,12 @@         some_union (More s) (More t) = More $ s `S.union` t  -- | The union of a list of sets.-unions :: Ord a => [HashSet a] -> HashSet a+unions :: Ord a => [Set a] -> Set a unions xs = foldl' union empty xs  -- | Difference between two sets.-difference :: Ord a => HashSet a -> HashSet a -> HashSet a-difference (HashSet s1) (HashSet s2) = HashSet $+difference :: Ord a => Set a -> Set a -> Set a+difference (Set s1) (Set s2) = Set $   I.differenceWith some_diff s1 s2   where some_diff v@(Only a) (Only b) | a `eq` b  = Nothing                                       | otherwise = Just v@@ -277,8 +285,8 @@         some_empty (More s) = not $ S.null s  -- | The intersection of two sets.-intersection :: Ord a => HashSet a -> HashSet a -> HashSet a-intersection (HashSet s1) (HashSet s2) = HashSet $ delete_empty $+intersection :: Ord a => Set a -> Set a -> Set a+intersection (Set s1) (Set s2) = Set $ delete_empty $   I.intersectionWith some_intersection s1 s2   where some_intersection v@(Only a) (Only b) | a `eq` b  = v                                               | otherwise = More (S.empty)@@ -293,8 +301,8 @@   Filter --------------------------------------------------------------------} -- | Filter all elements that satisfy some predicate.-filter :: Ord a => (a -> Bool) -> HashSet a -> HashSet a-filter p (HashSet s) = HashSet $+filter :: Ord a => (a -> Bool) -> Set a -> Set a+filter p (Set s) = Set $   I.mapMaybe some_filter s   where some_filter v@(Only a) | p a       = Just v                                | otherwise = Nothing@@ -303,7 +311,7 @@ -- | Partition the set according to some predicate. The first set contains all -- elements that satisfy the predicate, the second all elements that fail the -- predicate.-partition :: Ord a => (a -> Bool) -> HashSet a -> (HashSet a, HashSet a)+partition :: Ord a => (a -> Bool) -> Set a -> (Set a, Set a) partition p s = (filter p s, filter (not . p) s)  @@ -314,7 +322,7 @@ -- -- It's worth noting that the size of the result may be smaller if, for some -- @(x,y)@, @x /= y && f x == f y@-map :: (Hashable b, Ord b) => (a -> b) -> HashSet a -> HashSet b+map :: (Hashable b, Ord b) => (a -> b) -> Set a -> Set b map f = fromList . fold ((:) . f) []  @@ -322,8 +330,8 @@   Fold --------------------------------------------------------------------} -- | Fold over the elements of a set in an unspecified order.-fold :: (a -> b -> b) -> b -> HashSet a -> b-fold f z (HashSet s) = I.fold some_fold z s+fold :: (a -> b -> b) -> b -> Set a -> b+fold f z (Set s) = I.fold some_fold z s   where some_fold (Only a) x = f a x         some_fold (More t) x = S.fold f x t @@ -332,15 +340,15 @@   Conversions --------------------------------------------------------------------} -- | The elements of a set. (For sets, this is equivalent to toList).-elems :: HashSet a -> [a]+elems :: Set a -> [a] elems = toList  -- | Convert the set to a list of elements.-toList :: HashSet a -> [a]-toList (HashSet s) = I.fold some_append [] s+toList :: Set a -> [a]+toList (Set s) = I.fold some_append [] s   where some_append (Only a) acc = a : acc         some_append (More t) acc = S.toList t ++ acc  -- | Create a set from a list of elements.-fromList :: (Hashable a, Ord a) => [a] -> HashSet a+fromList :: (Hashable a, Ord a) => [a] -> Set a fromList xs = foldl' (flip insert) empty xs
LICENSE view
@@ -1,4 +1,4 @@-Copyright Milan Straka 2010+Copyright Milan Straka 2011  All rights reserved. 
hashmap.cabal view
@@ -1,17 +1,21 @@ Name:                hashmap-Version:             1.1.0.1-Synopsis:            Persistent containers HashMap and HashSet.-Description:         An implementation of persistent 'HashMap' and 'HashSet' on+Version:             1.2.0.0+Synopsis:            Persistent containers Map and Set based on hashing.+Description:         An implementation of persistent 'Map' and 'Set' containers+                     based on hashing. The implementation is build on                      top of 'Data.IntMap.IntMap' and 'Data.IntSet.IntSet',                      with very similar API. It uses 'Hashable' class from the                      @hashable@ package for hashing.                      .-                     The @'HashMap' key value@ is an 'Data.IntMap.IntMap'-                     indexed by the hash value, containing @'Data.Map.Map' key value@-                     for all keys with the same hash value.+                     This package can be used as a drop-in replacement for+                     'Data.Map' and 'Data.Set' modules.                      .-                     The @'HashSet' elem@ is an 'Data.IntMap.IntMap' indexed by-                     the hash value, containing @'Data.Set.Set' elem@ for+                     The @'Map' key value@ is an 'Data.IntMap.IntMap'+                     indexed by the hash value, containing either one ('key', 'value')+                     or a @'Data.Map.Map' key value@ for all keys with the same hash value.+                     .+                     The @'Set' elem@ is an 'Data.IntMap.IntMap' indexed by+                     the hash value, containing either one 'elem' or @'Data.Set.Set' elem@ for                      all elements with the same hash value. Homepage:            http://git.auryn.cz/haskell/hashmap/ License:             BSD3