unordered-containers 0.1.3.0 → 0.1.4.0
raw patch · 5 files changed
+80/−16 lines, 5 files
Files
- Data/HashMap/Common.hs +20/−1
- Data/HashMap/Lazy.hs +28/−14
- Data/HashMap/Strict.hs +4/−0
- Data/HashSet.hs +27/−0
- unordered-containers.cabal +1/−1
Data/HashMap/Common.hs view
@@ -20,6 +20,7 @@ , union -- * Transformations+ , toList , filterMapWithKey , traverseWithKey @@ -39,6 +40,10 @@ import Data.Word (Word) import Prelude hiding (foldr, map) +#if defined(__GLASGOW_HASKELL__)+import GHC.Exts (build)+#endif+ import qualified Data.FullList.Lazy as FL ------------------------------------------------------------------------@@ -53,7 +58,7 @@ | Tip {-# UNPACK #-} !Hash {-# UNPACK #-} !(FL.FullList k v) | Nil- deriving (Show, Typeable)+ deriving (Typeable) type Suffix = Int type Hash = Int@@ -78,6 +83,16 @@ t1 == t2 = equal t1 t2 t1 /= t2 = nequal t1 t2 +-- | /O(n)/ Return a list of this map's elements. The list is+-- produced lazily.+toList :: HashMap k v -> [(k, v)]+#if defined(__GLASGOW_HASKELL__)+toList t = build (\ c z -> foldrWithKey (curry c) z t)+#else+toList = foldrWithKey (\ k v xs -> (k, v) : xs) []+#endif+{-# INLINE toList #-}+ equal :: (Eq k, Eq v) => HashMap k v -> HashMap k v -> Bool equal (Bin sm1 l1 r1) (Bin sm2 l2 r2) = (sm1 == sm2) && (equal l1 l2) && (equal r1 r2)@@ -99,6 +114,10 @@ instance Functor (HashMap k) where fmap = map++instance (Show k, Show v) => Show (HashMap k v) where+ showsPrec d m = showParen (d > 10) $+ showString "fromList " . shows (toList m) -- | /O(n)/ Transform this map by applying a function to every value. map :: (v1 -> v2) -> HashMap k v1 -> HashMap k v2
Data/HashMap/Lazy.hs view
@@ -53,6 +53,10 @@ , map , traverseWithKey + -- * Difference and intersection+ , difference+ , intersection+ -- * Folds , foldl' , foldlWithKey'@@ -78,10 +82,6 @@ import qualified Data.List as List import Prelude hiding (filter, foldr, lookup, map, null, pred) -#if defined(__GLASGOW_HASKELL__)-import GHC.Exts (build)-#endif- import Data.HashMap.Common ------------------------------------------------------------------------@@ -230,6 +230,30 @@ f' k v = (k, f v) {-# INLINE map #-} +-- | /O(n)/ Difference of two maps. Return elements of the first map+-- not existing in the second.+difference :: (Eq k, Hashable k) => HashMap k v -> HashMap k w -> HashMap k v+difference a b = foldlWithKey' go empty a+ where+ go m k v = case lookup k b of+ Nothing -> insert k v m+ _ -> m+#if __GLASGOW_HASKELL__ >= 700+{-# INLINABLE difference #-}+#endif++-- | /O(n)/ Intersection of two maps. Return elements of the first map+-- for keys existing in the second.+intersection :: (Eq k, Hashable k) => HashMap k v -> HashMap k w -> HashMap k v+intersection a b = foldlWithKey' go empty a+ where+ go m k v = case lookup k b of+ Just _ -> insert k v m+ _ -> m+#if __GLASGOW_HASKELL__ >= 700+{-# INLINABLE intersection #-}+#endif+ ------------------------------------------------------------------------ -- * Folds @@ -286,16 +310,6 @@ ------------------------------------------------------------------------ -- Conversions---- | /O(n)/ Return a list of this map's elements. The list is--- produced lazily.-toList :: HashMap k v -> [(k, v)]-#if defined(__GLASGOW_HASKELL__)-toList t = build (\ c z -> foldrWithKey (curry c) z t)-#else-toList = foldrWithKey (\ k v xs -> (k, v) : xs) []-#endif-{-# INLINE toList #-} -- | /O(n*min(W, n))/ Construct a map from a list of elements. fromList :: (Eq k, Hashable k) => [(k, v)] -> HashMap k v
Data/HashMap/Strict.hs view
@@ -54,6 +54,10 @@ , map , traverseWithKey + -- * Difference and intersection+ , difference+ , intersection+ -- * Folds , foldl' , foldlWithKey'
Data/HashSet.hs view
@@ -43,6 +43,10 @@ -- * Transformations , map + -- * Difference and intersection+ , difference+ , intersection+ -- * Folds , foldl' , foldr@@ -93,6 +97,10 @@ mappend = union {-# INLINE mappend #-} +instance (Show a) => Show (HashSet a) where+ showsPrec d m = showParen (d > 10) $+ showString "fromList " . shows (toList m)+ -- | /O(1)/ Construct an empty set. empty :: HashSet a empty = HashSet H.empty@@ -105,6 +113,9 @@ #endif -- | /O(n)/ Construct a set containing all elements from both sets.+--+-- To obtain good performance, the smaller set must be presented as+-- the first argument. union :: (Eq a, Hashable a) => HashSet a -> HashSet a -> HashSet a union s1 s2 = HashSet $ H.union (asMap s1) (asMap s2) {-# INLINE union #-}@@ -144,6 +155,22 @@ map f = fromList . List.map f . toList #if __GLASGOW_HASKELL__ >= 700 {-# INLINABLE map #-}+#endif++-- | /O(n)/ Difference of two sets. Return elements of the first set+-- not existing in the second.+difference :: (Eq a, Hashable a) => HashSet a -> HashSet a -> HashSet a+difference (HashSet a) (HashSet b) = HashSet (H.difference a b)+#if __GLASGOW_HASKELL__ >= 700+{-# INLINABLE difference #-}+#endif++-- | /O(n)/ Intersection of two sets. Return elements present in both+-- the first set and the second.+intersection :: (Eq a, Hashable a) => HashSet a -> HashSet a -> HashSet a+intersection (HashSet a) (HashSet b) = HashSet (H.intersection a b)+#if __GLASGOW_HASKELL__ >= 700+{-# INLINABLE intersection #-} #endif -- | /O(n)/ Reduce this set by applying a binary operator to all
unordered-containers.cabal view
@@ -1,5 +1,5 @@ name: unordered-containers-version: 0.1.3.0+version: 0.1.4.0 synopsis: Efficient hashing-based container types description: Efficient hashing-based container types. The containers have been