int-multimap 0.2.1 → 0.3
raw patch · 2 files changed
+35/−35 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- IntMultimap: data 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: data 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: delete :: (Hashable a, Eq a) => Int -> a -> IntMultiMap a -> IntMultiMap a
+ IntMultimap: delete :: (Hashable a, Eq a) => Int -> a -> IntMultimap a -> IntMultimap a
- IntMultimap: elems :: IntMultiMap a -> [a]
+ IntMultimap: elems :: IntMultimap a -> [a]
- IntMultimap: empty :: IntMultiMap a
+ IntMultimap: empty :: IntMultimap a
- IntMultimap: fromList :: (Eq a, Hashable a) => [(Int, a)] -> 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: insert :: (Hashable a, Eq a) => Int -> a -> IntMultimap a -> IntMultimap a
- IntMultimap: keys :: IntMultiMap a -> [Int]
+ IntMultimap: keys :: IntMultimap a -> [Int]
- IntMultimap: map :: (Eq b, Hashable b) => (a -> b) -> IntMultiMap a -> IntMultiMap b
+ IntMultimap: map :: (Eq b, Hashable b) => (a -> b) -> IntMultimap a -> IntMultimap b
- IntMultimap: member :: Int -> IntMultiMap a -> Bool
+ IntMultimap: member :: Int -> IntMultimap a -> Bool
- IntMultimap: null :: IntMultiMap a -> Bool
+ IntMultimap: null :: IntMultimap a -> Bool
- IntMultimap: singleton :: (Hashable a) => Int -> a -> IntMultiMap a
+ IntMultimap: singleton :: (Hashable a) => Int -> a -> IntMultimap a
- IntMultimap: size :: IntMultiMap a -> Int
+ IntMultimap: size :: IntMultimap a -> Int
- IntMultimap: split :: Int -> IntMultiMap a -> (IntMultiMap a, IntMultiMap a)
+ IntMultimap: split :: Int -> IntMultimap a -> (IntMultimap a, IntMultimap a)
- IntMultimap: splitLookup :: Int -> IntMultiMap a -> (IntMultiMap a, Maybe (HashSet a), IntMultiMap a)
+ IntMultimap: splitLookup :: Int -> IntMultimap a -> (IntMultimap a, Maybe (HashSet a), IntMultimap a)
- IntMultimap: toList :: IntMultiMap a -> [(Int, a)]
+ IntMultimap: toList :: IntMultimap a -> [(Int, a)]
Files
- int-multimap.cabal +1/−1
- library/IntMultimap.hs +34/−34
int-multimap.cabal view
@@ -1,7 +1,7 @@ name: int-multimap version:- 0.2.1+ 0.3 synopsis: A data structure that associates each Int key with a set of values category:
library/IntMultimap.hs view
@@ -1,6 +1,6 @@ module IntMultimap (- IntMultiMap,+ IntMultimap, -- * Construction empty,@@ -46,67 +46,67 @@ {-| A multi map of integers to values a. -}-newtype IntMultiMap a =- IntMultiMap (A.IntMap (B.HashSet 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 $+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)+-------------------------IntMultimap -------------------------------------------}+instance (Eq a, Hashable a) => G.IsList (IntMultimap a) where+ type Item (IntMultimap a) = (Int, a) toList = toList fromList = fromList -toList :: IntMultiMap a -> [(Int, a)]-toList (IntMultiMap multiMap) = do+toList :: IntMultimap a -> [(Int, a)]+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)+ [(Int, a)] -> IntMultimap a+fromList = IntMultimap . A.fromListWith B.union . fmap (fmap B.singleton) {-------------------------------------------------------------------- Construction --------------------------------------------------------------------}-empty :: IntMultiMap a-empty = IntMultiMap A.empty+empty :: IntMultimap a+empty = IntMultimap A.empty -singleton :: (Hashable a) => Int -> a -> IntMultiMap a-singleton k v = IntMultiMap $ A.singleton k $ B.singleton v+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+null :: IntMultimap a -> Bool+null (IntMultimap intMap) = A.null intMap {-# INLINE null #-} -size :: IntMultiMap a -> Int+size :: IntMultimap a -> Int size = length . toList -member :: Int -> IntMultiMap a -> Bool-member key (IntMultiMap intMap) = A.member key intMap+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.insertWith (f value) key (B.singleton value) intMap+insert :: (Hashable a, Eq a) => Int -> a -> IntMultimap a -> IntMultimap a+insert key value (IntMultimap intMap) =+ IntMultimap $ A.insertWith (f value) key (B.singleton value) intMap where f v new old = B.insert v old -delete :: (Hashable a, Eq a) => Int {-^ Key -} -> a -> IntMultiMap a -> IntMultiMap a-delete key value (IntMultiMap intMap) =- IntMultiMap $ A.update f 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@@ -114,21 +114,21 @@ {-------------------------------------------------------------------- Conversions --------------------------------------------------------------------}-elems :: IntMultiMap a -> [a]+elems :: IntMultimap a -> [a] elems = foldr (:) [] -keys :: IntMultiMap a -> [Int]-keys (IntMultiMap intMap) = A.keys intMap+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)+split :: Int -> IntMultimap a -> (IntMultimap a, IntMultimap a)+split key (IntMultimap intMap) = (IntMultimap oldMap, IntMultimap newMap) where (oldMap, newMap) = A.split key intMap -splitLookup :: Int -> IntMultiMap a -> (IntMultiMap a, Maybe (B.HashSet a), IntMultiMap a)-splitLookup key (IntMultiMap intMap) = (IntMultiMap oldMap, elemHashSet, IntMultiMap newMap)+splitLookup :: Int -> IntMultimap a -> (IntMultimap a, Maybe (B.HashSet a), IntMultimap a)+splitLookup key (IntMultimap intMap) = (IntMultimap oldMap, elemHashSet, IntMultimap newMap) where (oldMap, elemHashSet, newMap) = A.splitLookup key intMap