packages feed

int-multimap 0.1.1.1 → 0.2

raw patch · 3 files changed

+127/−127 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- IntMultiMap: data IntMultiMap a
- IntMultiMap: delete :: (Hashable a, Eq a) => Int -> a -> IntMultiMap a -> IntMultiMap a
- IntMultiMap: elems :: IntMultiMap a -> [a]
- IntMultiMap: empty :: IntMultiMap a
- IntMultiMap: fromList :: (Eq a, Hashable a) => [(Int, a)] -> IntMultiMap a
- IntMultiMap: insert :: (Hashable a, Ord a) => Int -> a -> IntMultiMap a -> IntMultiMap a
- IntMultiMap: instance (GHC.Classes.Eq a, Data.Hashable.Class.Hashable a) => GHC.Exts.IsList (IntMultiMap.IntMultiMap a)
- IntMultiMap: instance Data.Foldable.Foldable IntMultiMap.IntMultiMap
- IntMultiMap: instance GHC.Classes.Eq a => GHC.Classes.Eq (IntMultiMap.IntMultiMap a)
- IntMultiMap: instance GHC.Generics.Generic (IntMultiMap.IntMultiMap a)
- IntMultiMap: instance GHC.Show.Show a => GHC.Show.Show (IntMultiMap.IntMultiMap a)
- IntMultiMap: keys :: IntMultiMap a -> [Int]
- IntMultiMap: map :: (Eq b, Hashable b) => (a -> b) -> IntMultiMap a -> IntMultiMap b
- IntMultiMap: member :: Int -> IntMultiMap a -> Bool
- IntMultiMap: null :: IntMultiMap a -> Bool
- IntMultiMap: singleton :: (Hashable a) => Int -> a -> IntMultiMap a
- IntMultiMap: size :: IntMultiMap a -> Int
- IntMultiMap: split :: Int -> IntMultiMap a -> (IntMultiMap a, IntMultiMap a)
- IntMultiMap: toList :: IntMultiMap b -> [(Int, b)]
+ IntMultimap: data IntMultiMap a
+ IntMultimap: delete :: (Hashable a, Eq a) => Int -> a -> IntMultiMap a -> IntMultiMap a
+ IntMultimap: elems :: IntMultiMap a -> [a]
+ IntMultimap: empty :: IntMultiMap a
+ IntMultimap: fromList :: (Eq a, Hashable a) => [(Int, a)] -> IntMultiMap a
+ IntMultimap: insert :: (Hashable a, Ord a) => Int -> a -> IntMultiMap a -> IntMultiMap a
+ IntMultimap: instance (GHC.Classes.Eq a, Data.Hashable.Class.Hashable a) => GHC.Exts.IsList (IntMultimap.IntMultiMap a)
+ IntMultimap: instance Data.Foldable.Foldable IntMultimap.IntMultiMap
+ IntMultimap: instance GHC.Classes.Eq a => GHC.Classes.Eq (IntMultimap.IntMultiMap a)
+ IntMultimap: instance GHC.Generics.Generic (IntMultimap.IntMultiMap a)
+ IntMultimap: instance GHC.Show.Show a => GHC.Show.Show (IntMultimap.IntMultiMap a)
+ IntMultimap: keys :: IntMultiMap a -> [Int]
+ IntMultimap: map :: (Eq b, Hashable b) => (a -> b) -> IntMultiMap a -> IntMultiMap b
+ IntMultimap: member :: Int -> IntMultiMap a -> Bool
+ IntMultimap: null :: IntMultiMap a -> Bool
+ IntMultimap: singleton :: (Hashable a) => Int -> a -> IntMultiMap a
+ IntMultimap: size :: IntMultiMap a -> Int
+ IntMultimap: split :: Int -> IntMultiMap a -> (IntMultiMap a, IntMultiMap a)
+ IntMultimap: toList :: IntMultiMap b -> [(Int, b)]

Files

int-multimap.cabal view
@@ -1,7 +1,7 @@ name:   int-multimap version:-  0.1.1.1+  0.2 synopsis:   A data structure that associates each Int key with a set of values category:@@ -40,7 +40,7 @@   default-language:     Haskell2010   exposed-modules:-    IntMultiMap+    IntMultimap   other-modules:   build-depends:     base >=4.7 && <5,
− library/IntMultiMap.hs
@@ -1,125 +0,0 @@-module IntMultiMap-(-  IntMultiMap,--  -- * Construction-  empty,-  singleton,--  -- * List-  toList,-  fromList,--  -- * Transformations-  map,--  -- * Basic interface-  null,-  size,-  member,-  delete,-  insert,--  -- * Conversions-  elems,-  keys,--  -- * Filter-  split-)-where--import qualified Data.IntMap.Strict as A-import qualified Data.HashSet as B-import qualified Data.Foldable as C-import qualified GHC.Exts as G-import GHC.Generics-import Prelude hiding (map, null)-import Data.Int-import Data.Hashable-import Data.Functor-import Data.List(length)-import Control.Monad--{-|-A multi map of integers to values a.--}-newtype IntMultiMap a =-  IntMultiMap (A.IntMap (B.HashSet a))-  deriving(Foldable, Eq, Show, Generic)--{---------------------------------------------------------------------  Transformations---------------------------------------------------------------------}-map :: (Eq b, Hashable b) => (a -> b) -> IntMultiMap a -> IntMultiMap b-map f (IntMultiMap intMap) = IntMultiMap $-  fmap (\hashSet -> B.map f hashSet) intMap-{-# INLINE map #-}--{---------------------------------------------------------------------  Lists---------------------------------------------------------------------}-instance (Eq a, Hashable a) => G.IsList (IntMultiMap a) where-  type Item (IntMultiMap a) = (Int, a)-  toList = toList-  fromList = fromList--toList :: IntMultiMap b -> [(Int, b)]-toList (IntMultiMap multiMap) = do-  (key, hashSet) <- A.toList multiMap-  fmap ((,) key) $ B.toList hashSet--fromList :: (Eq a, Hashable a) =>-     [(Int, a)] -> IntMultiMap a-fromList = IntMultiMap . A.fromListWith B.union . fmap (fmap B.singleton)--{---------------------------------------------------------------------  Construction---------------------------------------------------------------------}-empty :: IntMultiMap a-empty = IntMultiMap A.empty--singleton :: (Hashable a) => Int -> a -> IntMultiMap a-singleton k v = IntMultiMap $ A.singleton k $ B.singleton v-{-# INLINABLE singleton #-}--{---------------------------------------------------------------------  Basic interface---------------------------------------------------------------------}-null :: IntMultiMap a -> Bool-null (IntMultiMap intMap) = A.null intMap-{-# INLINE null #-}--size :: IntMultiMap a -> Int-size = length . toList--member :: Int -> IntMultiMap a -> Bool-member key (IntMultiMap intMap) = A.member key intMap--insert :: (Hashable a, Ord a) => Int -> a -> IntMultiMap a -> IntMultiMap a-insert key value (IntMultiMap intMap) =-  IntMultiMap $ A.update (\hash -> Just $ B.insert value hash) key intMap--delete :: (Hashable a, Eq a) => Int {-^ Key -} -> a -> IntMultiMap a -> IntMultiMap a-delete key value (IntMultiMap intMap) =-  IntMultiMap $ A.update f key intMap-  where-    f hashSet =-      mfilter (not . B.null) . Just $ B.delete value hashSet--{---------------------------------------------------------------------  Conversions---------------------------------------------------------------------}-elems :: IntMultiMap a -> [a]-elems = foldr (:) []--keys  :: IntMultiMap a -> [Int]-keys (IntMultiMap intMap) = A.keys intMap--{---------------------------------------------------------------------  Filter---------------------------------------------------------------------}-split :: Int -> IntMultiMap a -> (IntMultiMap a, IntMultiMap a)-split key (IntMultiMap intMap) = (IntMultiMap oldMap, IntMultiMap newMap)-  where-    (oldMap, newMap) = A.split key intMap
+ library/IntMultimap.hs view
@@ -0,0 +1,125 @@+module IntMultimap+(+  IntMultiMap,++  -- * Construction+  empty,+  singleton,++  -- * List+  toList,+  fromList,++  -- * Transformations+  map,++  -- * Basic interface+  null,+  size,+  member,+  delete,+  insert,++  -- * Conversions+  elems,+  keys,++  -- * Filter+  split+)+where++import qualified Data.IntMap.Strict as A+import qualified Data.HashSet as B+import qualified Data.Foldable as C+import qualified GHC.Exts as G+import GHC.Generics+import Prelude hiding (map, null)+import Data.Int+import Data.Hashable+import Data.Functor+import Data.List(length)+import Control.Monad++{-|+A multi map of integers to values a.+-}+newtype IntMultiMap a =+  IntMultiMap (A.IntMap (B.HashSet a))+  deriving(Foldable, Eq, Show, Generic)++{--------------------------------------------------------------------+  Transformations+--------------------------------------------------------------------}+map :: (Eq b, Hashable b) => (a -> b) -> IntMultiMap a -> IntMultiMap b+map f (IntMultiMap intMap) = IntMultiMap $+  fmap (\hashSet -> B.map f hashSet) intMap+{-# INLINE map #-}++{--------------------------------------------------------------------+  Lists+--------------------------------------------------------------------}+instance (Eq a, Hashable a) => G.IsList (IntMultiMap a) where+  type Item (IntMultiMap a) = (Int, a)+  toList = toList+  fromList = fromList++toList :: IntMultiMap b -> [(Int, b)]+toList (IntMultiMap multiMap) = do+  (key, hashSet) <- A.toList multiMap+  fmap ((,) key) $ B.toList hashSet++fromList :: (Eq a, Hashable a) =>+     [(Int, a)] -> IntMultiMap a+fromList = IntMultiMap . A.fromListWith B.union . fmap (fmap B.singleton)++{--------------------------------------------------------------------+  Construction+--------------------------------------------------------------------}+empty :: IntMultiMap a+empty = IntMultiMap A.empty++singleton :: (Hashable a) => Int -> a -> IntMultiMap a+singleton k v = IntMultiMap $ A.singleton k $ B.singleton v+{-# INLINABLE singleton #-}++{--------------------------------------------------------------------+  Basic interface+--------------------------------------------------------------------}+null :: IntMultiMap a -> Bool+null (IntMultiMap intMap) = A.null intMap+{-# INLINE null #-}++size :: IntMultiMap a -> Int+size = length . toList++member :: Int -> IntMultiMap a -> Bool+member key (IntMultiMap intMap) = A.member key intMap++insert :: (Hashable a, Ord a) => Int -> a -> IntMultiMap a -> IntMultiMap a+insert key value (IntMultiMap intMap) =+  IntMultiMap $ A.update (\hash -> Just $ B.insert value hash) key intMap++delete :: (Hashable a, Eq a) => Int {-^ Key -} -> a -> IntMultiMap a -> IntMultiMap a+delete key value (IntMultiMap intMap) =+  IntMultiMap $ A.update f key intMap+  where+    f hashSet =+      mfilter (not . B.null) . Just $ B.delete value hashSet++{--------------------------------------------------------------------+  Conversions+--------------------------------------------------------------------}+elems :: IntMultiMap a -> [a]+elems = foldr (:) []++keys  :: IntMultiMap a -> [Int]+keys (IntMultiMap intMap) = A.keys intMap++{--------------------------------------------------------------------+  Filter+--------------------------------------------------------------------}+split :: Int -> IntMultiMap a -> (IntMultiMap a, IntMultiMap a)+split key (IntMultiMap intMap) = (IntMultiMap oldMap, IntMultiMap newMap)+  where+    (oldMap, newMap) = A.split key intMap