{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module GHC.Cmm.Dataflow.Collections
( IsSet(..)
, setInsertList, setDeleteList, setUnions
, IsMap(..)
, mapInsertList, mapDeleteList, mapUnions
, UniqueMap, UniqueSet
) where
import GHC.Prelude
import qualified Data.IntMap.Strict as M
import qualified Data.IntSet as S
import Data.List (foldl1')
class IsSet set where
type ElemOf set
setNull :: set -> Bool
setSize :: set -> Int
setMember :: ElemOf set -> set -> Bool
setEmpty :: set
setSingleton :: ElemOf set -> set
setInsert :: ElemOf set -> set -> set
setDelete :: ElemOf set -> set -> set
setUnion :: set -> set -> set
setDifference :: set -> set -> set
setIntersection :: set -> set -> set
setIsSubsetOf :: set -> set -> Bool
setFilter :: (ElemOf set -> Bool) -> set -> set
setFoldl :: (b -> ElemOf set -> b) -> b -> set -> b
setFoldr :: (ElemOf set -> b -> b) -> b -> set -> b
setElems :: set -> [ElemOf set]
setFromList :: [ElemOf set] -> set
setInsertList :: IsSet set => [ElemOf set] -> set -> set
setInsertList :: forall set. IsSet set => [ElemOf set] -> set -> set
setInsertList [ElemOf set]
keys set
set = (set -> ElemOf set -> set) -> set -> [ElemOf set] -> set
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' ((ElemOf set -> set -> set) -> set -> ElemOf set -> set
forall a b c. (a -> b -> c) -> b -> a -> c
flip ElemOf set -> set -> set
forall set. IsSet set => ElemOf set -> set -> set
setInsert) set
set [ElemOf set]
keys
setDeleteList :: IsSet set => [ElemOf set] -> set -> set
setDeleteList :: forall set. IsSet set => [ElemOf set] -> set -> set
setDeleteList [ElemOf set]
keys set
set = (set -> ElemOf set -> set) -> set -> [ElemOf set] -> set
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' ((ElemOf set -> set -> set) -> set -> ElemOf set -> set
forall a b c. (a -> b -> c) -> b -> a -> c
flip ElemOf set -> set -> set
forall set. IsSet set => ElemOf set -> set -> set
setDelete) set
set [ElemOf set]
keys
setUnions :: IsSet set => [set] -> set
setUnions :: forall set. IsSet set => [set] -> set
setUnions [] = set
forall set. IsSet set => set
setEmpty
setUnions [set]
sets = (set -> set -> set) -> [set] -> set
forall a. (a -> a -> a) -> [a] -> a
foldl1' set -> set -> set
forall set. IsSet set => set -> set -> set
setUnion [set]
sets
class IsMap map where
type KeyOf map
mapNull :: map a -> Bool
mapSize :: map a -> Int
mapMember :: KeyOf map -> map a -> Bool
mapLookup :: KeyOf map -> map a -> Maybe a
mapFindWithDefault :: a -> KeyOf map -> map a -> a
mapEmpty :: map a
mapSingleton :: KeyOf map -> a -> map a
mapInsert :: KeyOf map -> a -> map a -> map a
mapInsertWith :: (a -> a -> a) -> KeyOf map -> a -> map a -> map a
mapDelete :: KeyOf map -> map a -> map a
mapAlter :: (Maybe a -> Maybe a) -> KeyOf map -> map a -> map a
mapAdjust :: (a -> a) -> KeyOf map -> map a -> map a
mapUnion :: map a -> map a -> map a
mapUnionWithKey :: (KeyOf map -> a -> a -> a) -> map a -> map a -> map a
mapDifference :: map a -> map a -> map a
mapIntersection :: map a -> map a -> map a
mapIsSubmapOf :: Eq a => map a -> map a -> Bool
mapMap :: (a -> b) -> map a -> map b
mapMapWithKey :: (KeyOf map -> a -> b) -> map a -> map b
mapFoldl :: (b -> a -> b) -> b -> map a -> b
mapFoldr :: (a -> b -> b) -> b -> map a -> b
mapFoldlWithKey :: (b -> KeyOf map -> a -> b) -> b -> map a -> b
mapFoldMapWithKey :: Monoid m => (KeyOf map -> a -> m) -> map a -> m
mapFilter :: (a -> Bool) -> map a -> map a
mapFilterWithKey :: (KeyOf map -> a -> Bool) -> map a -> map a
mapElems :: map a -> [a]
mapKeys :: map a -> [KeyOf map]
mapToList :: map a -> [(KeyOf map, a)]
mapFromList :: [(KeyOf map, a)] -> map a
mapFromListWith :: (a -> a -> a) -> [(KeyOf map,a)] -> map a
mapInsertList :: IsMap map => [(KeyOf map, a)] -> map a -> map a
mapInsertList :: forall (map :: * -> *) a.
IsMap map =>
[(KeyOf map, a)] -> map a -> map a
mapInsertList [(KeyOf map, a)]
assocs map a
map = (map a -> (KeyOf map, a) -> map a)
-> map a -> [(KeyOf map, a)] -> map a
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' (((KeyOf map, a) -> map a -> map a)
-> map a -> (KeyOf map, a) -> map a
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((KeyOf map -> a -> map a -> map a)
-> (KeyOf map, a) -> map a -> map a
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry KeyOf map -> a -> map a -> map a
forall (map :: * -> *) a.
IsMap map =>
KeyOf map -> a -> map a -> map a
mapInsert)) map a
map [(KeyOf map, a)]
assocs
mapDeleteList :: IsMap map => [KeyOf map] -> map a -> map a
mapDeleteList :: forall (map :: * -> *) a.
IsMap map =>
[KeyOf map] -> map a -> map a
mapDeleteList [KeyOf map]
keys map a
map = (map a -> KeyOf map -> map a) -> map a -> [KeyOf map] -> map a
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' ((KeyOf map -> map a -> map a) -> map a -> KeyOf map -> map a
forall a b c. (a -> b -> c) -> b -> a -> c
flip KeyOf map -> map a -> map a
forall (map :: * -> *) a. IsMap map => KeyOf map -> map a -> map a
mapDelete) map a
map [KeyOf map]
keys
mapUnions :: IsMap map => [map a] -> map a
mapUnions :: forall (map :: * -> *) a. IsMap map => [map a] -> map a
mapUnions [] = map a
forall (map :: * -> *) a. IsMap map => map a
mapEmpty
mapUnions [map a]
maps = (map a -> map a -> map a) -> [map a] -> map a
forall a. (a -> a -> a) -> [a] -> a
foldl1' map a -> map a -> map a
forall (map :: * -> *) a. IsMap map => map a -> map a -> map a
mapUnion [map a]
maps
newtype UniqueSet = US S.IntSet deriving (UniqueSet -> UniqueSet -> Bool
(UniqueSet -> UniqueSet -> Bool)
-> (UniqueSet -> UniqueSet -> Bool) -> Eq UniqueSet
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UniqueSet -> UniqueSet -> Bool
$c/= :: UniqueSet -> UniqueSet -> Bool
== :: UniqueSet -> UniqueSet -> Bool
$c== :: UniqueSet -> UniqueSet -> Bool
Eq, Eq UniqueSet
Eq UniqueSet
-> (UniqueSet -> UniqueSet -> Ordering)
-> (UniqueSet -> UniqueSet -> Bool)
-> (UniqueSet -> UniqueSet -> Bool)
-> (UniqueSet -> UniqueSet -> Bool)
-> (UniqueSet -> UniqueSet -> Bool)
-> (UniqueSet -> UniqueSet -> UniqueSet)
-> (UniqueSet -> UniqueSet -> UniqueSet)
-> Ord UniqueSet
UniqueSet -> UniqueSet -> Bool
UniqueSet -> UniqueSet -> Ordering
UniqueSet -> UniqueSet -> UniqueSet
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: UniqueSet -> UniqueSet -> UniqueSet
$cmin :: UniqueSet -> UniqueSet -> UniqueSet
max :: UniqueSet -> UniqueSet -> UniqueSet
$cmax :: UniqueSet -> UniqueSet -> UniqueSet
>= :: UniqueSet -> UniqueSet -> Bool
$c>= :: UniqueSet -> UniqueSet -> Bool
> :: UniqueSet -> UniqueSet -> Bool
$c> :: UniqueSet -> UniqueSet -> Bool
<= :: UniqueSet -> UniqueSet -> Bool
$c<= :: UniqueSet -> UniqueSet -> Bool
< :: UniqueSet -> UniqueSet -> Bool
$c< :: UniqueSet -> UniqueSet -> Bool
compare :: UniqueSet -> UniqueSet -> Ordering
$ccompare :: UniqueSet -> UniqueSet -> Ordering
Ord, Int -> UniqueSet -> ShowS
[UniqueSet] -> ShowS
UniqueSet -> String
(Int -> UniqueSet -> ShowS)
-> (UniqueSet -> String)
-> ([UniqueSet] -> ShowS)
-> Show UniqueSet
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UniqueSet] -> ShowS
$cshowList :: [UniqueSet] -> ShowS
show :: UniqueSet -> String
$cshow :: UniqueSet -> String
showsPrec :: Int -> UniqueSet -> ShowS
$cshowsPrec :: Int -> UniqueSet -> ShowS
Show, NonEmpty UniqueSet -> UniqueSet
UniqueSet -> UniqueSet -> UniqueSet
(UniqueSet -> UniqueSet -> UniqueSet)
-> (NonEmpty UniqueSet -> UniqueSet)
-> (forall b. Integral b => b -> UniqueSet -> UniqueSet)
-> Semigroup UniqueSet
forall b. Integral b => b -> UniqueSet -> UniqueSet
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
stimes :: forall b. Integral b => b -> UniqueSet -> UniqueSet
$cstimes :: forall b. Integral b => b -> UniqueSet -> UniqueSet
sconcat :: NonEmpty UniqueSet -> UniqueSet
$csconcat :: NonEmpty UniqueSet -> UniqueSet
<> :: UniqueSet -> UniqueSet -> UniqueSet
$c<> :: UniqueSet -> UniqueSet -> UniqueSet
Semigroup, Semigroup UniqueSet
UniqueSet
Semigroup UniqueSet
-> UniqueSet
-> (UniqueSet -> UniqueSet -> UniqueSet)
-> ([UniqueSet] -> UniqueSet)
-> Monoid UniqueSet
[UniqueSet] -> UniqueSet
UniqueSet -> UniqueSet -> UniqueSet
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
mconcat :: [UniqueSet] -> UniqueSet
$cmconcat :: [UniqueSet] -> UniqueSet
mappend :: UniqueSet -> UniqueSet -> UniqueSet
$cmappend :: UniqueSet -> UniqueSet -> UniqueSet
mempty :: UniqueSet
$cmempty :: UniqueSet
Monoid)
instance IsSet UniqueSet where
type ElemOf UniqueSet = Int
setNull :: UniqueSet -> Bool
setNull (US IntSet
s) = IntSet -> Bool
S.null IntSet
s
setSize :: UniqueSet -> Int
setSize (US IntSet
s) = IntSet -> Int
S.size IntSet
s
setMember :: ElemOf UniqueSet -> UniqueSet -> Bool
setMember ElemOf UniqueSet
k (US IntSet
s) = Int -> IntSet -> Bool
S.member Int
ElemOf UniqueSet
k IntSet
s
setEmpty :: UniqueSet
setEmpty = IntSet -> UniqueSet
US IntSet
S.empty
setSingleton :: ElemOf UniqueSet -> UniqueSet
setSingleton ElemOf UniqueSet
k = IntSet -> UniqueSet
US (Int -> IntSet
S.singleton Int
ElemOf UniqueSet
k)
setInsert :: ElemOf UniqueSet -> UniqueSet -> UniqueSet
setInsert ElemOf UniqueSet
k (US IntSet
s) = IntSet -> UniqueSet
US (Int -> IntSet -> IntSet
S.insert Int
ElemOf UniqueSet
k IntSet
s)
setDelete :: ElemOf UniqueSet -> UniqueSet -> UniqueSet
setDelete ElemOf UniqueSet
k (US IntSet
s) = IntSet -> UniqueSet
US (Int -> IntSet -> IntSet
S.delete Int
ElemOf UniqueSet
k IntSet
s)
setUnion :: UniqueSet -> UniqueSet -> UniqueSet
setUnion (US IntSet
x) (US IntSet
y) = IntSet -> UniqueSet
US (IntSet -> IntSet -> IntSet
S.union IntSet
x IntSet
y)
setDifference :: UniqueSet -> UniqueSet -> UniqueSet
setDifference (US IntSet
x) (US IntSet
y) = IntSet -> UniqueSet
US (IntSet -> IntSet -> IntSet
S.difference IntSet
x IntSet
y)
setIntersection :: UniqueSet -> UniqueSet -> UniqueSet
setIntersection (US IntSet
x) (US IntSet
y) = IntSet -> UniqueSet
US (IntSet -> IntSet -> IntSet
S.intersection IntSet
x IntSet
y)
setIsSubsetOf :: UniqueSet -> UniqueSet -> Bool
setIsSubsetOf (US IntSet
x) (US IntSet
y) = IntSet -> IntSet -> Bool
S.isSubsetOf IntSet
x IntSet
y
setFilter :: (ElemOf UniqueSet -> Bool) -> UniqueSet -> UniqueSet
setFilter ElemOf UniqueSet -> Bool
f (US IntSet
s) = IntSet -> UniqueSet
US ((Int -> Bool) -> IntSet -> IntSet
S.filter Int -> Bool
ElemOf UniqueSet -> Bool
f IntSet
s)
setFoldl :: forall b. (b -> ElemOf UniqueSet -> b) -> b -> UniqueSet -> b
setFoldl b -> ElemOf UniqueSet -> b
k b
z (US IntSet
s) = (b -> Int -> b) -> b -> IntSet -> b
forall a. (a -> Int -> a) -> a -> IntSet -> a
S.foldl' b -> Int -> b
b -> ElemOf UniqueSet -> b
k b
z IntSet
s
setFoldr :: forall b. (ElemOf UniqueSet -> b -> b) -> b -> UniqueSet -> b
setFoldr ElemOf UniqueSet -> b -> b
k b
z (US IntSet
s) = (Int -> b -> b) -> b -> IntSet -> b
forall b. (Int -> b -> b) -> b -> IntSet -> b
S.foldr Int -> b -> b
ElemOf UniqueSet -> b -> b
k b
z IntSet
s
setElems :: UniqueSet -> [ElemOf UniqueSet]
setElems (US IntSet
s) = IntSet -> [Int]
S.elems IntSet
s
setFromList :: [ElemOf UniqueSet] -> UniqueSet
setFromList [ElemOf UniqueSet]
ks = IntSet -> UniqueSet
US ([Int] -> IntSet
S.fromList [Int]
[ElemOf UniqueSet]
ks)
newtype UniqueMap v = UM (M.IntMap v)
deriving (UniqueMap v -> UniqueMap v -> Bool
(UniqueMap v -> UniqueMap v -> Bool)
-> (UniqueMap v -> UniqueMap v -> Bool) -> Eq (UniqueMap v)
forall v. Eq v => UniqueMap v -> UniqueMap v -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UniqueMap v -> UniqueMap v -> Bool
$c/= :: forall v. Eq v => UniqueMap v -> UniqueMap v -> Bool
== :: UniqueMap v -> UniqueMap v -> Bool
$c== :: forall v. Eq v => UniqueMap v -> UniqueMap v -> Bool
Eq, Eq (UniqueMap v)
Eq (UniqueMap v)
-> (UniqueMap v -> UniqueMap v -> Ordering)
-> (UniqueMap v -> UniqueMap v -> Bool)
-> (UniqueMap v -> UniqueMap v -> Bool)
-> (UniqueMap v -> UniqueMap v -> Bool)
-> (UniqueMap v -> UniqueMap v -> Bool)
-> (UniqueMap v -> UniqueMap v -> UniqueMap v)
-> (UniqueMap v -> UniqueMap v -> UniqueMap v)
-> Ord (UniqueMap v)
UniqueMap v -> UniqueMap v -> Bool
UniqueMap v -> UniqueMap v -> Ordering
UniqueMap v -> UniqueMap v -> UniqueMap v
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {v}. Ord v => Eq (UniqueMap v)
forall v. Ord v => UniqueMap v -> UniqueMap v -> Bool
forall v. Ord v => UniqueMap v -> UniqueMap v -> Ordering
forall v. Ord v => UniqueMap v -> UniqueMap v -> UniqueMap v
min :: UniqueMap v -> UniqueMap v -> UniqueMap v
$cmin :: forall v. Ord v => UniqueMap v -> UniqueMap v -> UniqueMap v
max :: UniqueMap v -> UniqueMap v -> UniqueMap v
$cmax :: forall v. Ord v => UniqueMap v -> UniqueMap v -> UniqueMap v
>= :: UniqueMap v -> UniqueMap v -> Bool
$c>= :: forall v. Ord v => UniqueMap v -> UniqueMap v -> Bool
> :: UniqueMap v -> UniqueMap v -> Bool
$c> :: forall v. Ord v => UniqueMap v -> UniqueMap v -> Bool
<= :: UniqueMap v -> UniqueMap v -> Bool
$c<= :: forall v. Ord v => UniqueMap v -> UniqueMap v -> Bool
< :: UniqueMap v -> UniqueMap v -> Bool
$c< :: forall v. Ord v => UniqueMap v -> UniqueMap v -> Bool
compare :: UniqueMap v -> UniqueMap v -> Ordering
$ccompare :: forall v. Ord v => UniqueMap v -> UniqueMap v -> Ordering
Ord, Int -> UniqueMap v -> ShowS
[UniqueMap v] -> ShowS
UniqueMap v -> String
(Int -> UniqueMap v -> ShowS)
-> (UniqueMap v -> String)
-> ([UniqueMap v] -> ShowS)
-> Show (UniqueMap v)
forall v. Show v => Int -> UniqueMap v -> ShowS
forall v. Show v => [UniqueMap v] -> ShowS
forall v. Show v => UniqueMap v -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UniqueMap v] -> ShowS
$cshowList :: forall v. Show v => [UniqueMap v] -> ShowS
show :: UniqueMap v -> String
$cshow :: forall v. Show v => UniqueMap v -> String
showsPrec :: Int -> UniqueMap v -> ShowS
$cshowsPrec :: forall v. Show v => Int -> UniqueMap v -> ShowS
Show, (forall a b. (a -> b) -> UniqueMap a -> UniqueMap b)
-> (forall a b. a -> UniqueMap b -> UniqueMap a)
-> Functor UniqueMap
forall a b. a -> UniqueMap b -> UniqueMap a
forall a b. (a -> b) -> UniqueMap a -> UniqueMap b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> UniqueMap b -> UniqueMap a
$c<$ :: forall a b. a -> UniqueMap b -> UniqueMap a
fmap :: forall a b. (a -> b) -> UniqueMap a -> UniqueMap b
$cfmap :: forall a b. (a -> b) -> UniqueMap a -> UniqueMap b
Functor, (forall m. Monoid m => UniqueMap m -> m)
-> (forall m a. Monoid m => (a -> m) -> UniqueMap a -> m)
-> (forall m a. Monoid m => (a -> m) -> UniqueMap a -> m)
-> (forall a b. (a -> b -> b) -> b -> UniqueMap a -> b)
-> (forall a b. (a -> b -> b) -> b -> UniqueMap a -> b)
-> (forall b a. (b -> a -> b) -> b -> UniqueMap a -> b)
-> (forall b a. (b -> a -> b) -> b -> UniqueMap a -> b)
-> (forall a. (a -> a -> a) -> UniqueMap a -> a)
-> (forall a. (a -> a -> a) -> UniqueMap a -> a)
-> (forall a. UniqueMap a -> [a])
-> (forall a. UniqueMap a -> Bool)
-> (forall a. UniqueMap a -> Int)
-> (forall a. Eq a => a -> UniqueMap a -> Bool)
-> (forall a. Ord a => UniqueMap a -> a)
-> (forall a. Ord a => UniqueMap a -> a)
-> (forall a. Num a => UniqueMap a -> a)
-> (forall a. Num a => UniqueMap a -> a)
-> Foldable UniqueMap
forall a. Eq a => a -> UniqueMap a -> Bool
forall a. Num a => UniqueMap a -> a
forall a. Ord a => UniqueMap a -> a
forall m. Monoid m => UniqueMap m -> m
forall a. UniqueMap a -> Bool
forall a. UniqueMap a -> Int
forall a. UniqueMap a -> [a]
forall a. (a -> a -> a) -> UniqueMap a -> a
forall m a. Monoid m => (a -> m) -> UniqueMap a -> m
forall b a. (b -> a -> b) -> b -> UniqueMap a -> b
forall a b. (a -> b -> b) -> b -> UniqueMap a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: forall a. Num a => UniqueMap a -> a
$cproduct :: forall a. Num a => UniqueMap a -> a
sum :: forall a. Num a => UniqueMap a -> a
$csum :: forall a. Num a => UniqueMap a -> a
minimum :: forall a. Ord a => UniqueMap a -> a
$cminimum :: forall a. Ord a => UniqueMap a -> a
maximum :: forall a. Ord a => UniqueMap a -> a
$cmaximum :: forall a. Ord a => UniqueMap a -> a
elem :: forall a. Eq a => a -> UniqueMap a -> Bool
$celem :: forall a. Eq a => a -> UniqueMap a -> Bool
length :: forall a. UniqueMap a -> Int
$clength :: forall a. UniqueMap a -> Int
null :: forall a. UniqueMap a -> Bool
$cnull :: forall a. UniqueMap a -> Bool
toList :: forall a. UniqueMap a -> [a]
$ctoList :: forall a. UniqueMap a -> [a]
foldl1 :: forall a. (a -> a -> a) -> UniqueMap a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> UniqueMap a -> a
foldr1 :: forall a. (a -> a -> a) -> UniqueMap a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> UniqueMap a -> a
foldl' :: forall b a. (b -> a -> b) -> b -> UniqueMap a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> UniqueMap a -> b
foldl :: forall b a. (b -> a -> b) -> b -> UniqueMap a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> UniqueMap a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> UniqueMap a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> UniqueMap a -> b
foldr :: forall a b. (a -> b -> b) -> b -> UniqueMap a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> UniqueMap a -> b
foldMap' :: forall m a. Monoid m => (a -> m) -> UniqueMap a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> UniqueMap a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> UniqueMap a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> UniqueMap a -> m
fold :: forall m. Monoid m => UniqueMap m -> m
$cfold :: forall m. Monoid m => UniqueMap m -> m
Foldable, Functor UniqueMap
Foldable UniqueMap
Functor UniqueMap
-> Foldable UniqueMap
-> (forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> UniqueMap a -> f (UniqueMap b))
-> (forall (f :: * -> *) a.
Applicative f =>
UniqueMap (f a) -> f (UniqueMap a))
-> (forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> UniqueMap a -> m (UniqueMap b))
-> (forall (m :: * -> *) a.
Monad m =>
UniqueMap (m a) -> m (UniqueMap a))
-> Traversable UniqueMap
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
UniqueMap (m a) -> m (UniqueMap a)
forall (f :: * -> *) a.
Applicative f =>
UniqueMap (f a) -> f (UniqueMap a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> UniqueMap a -> m (UniqueMap b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> UniqueMap a -> f (UniqueMap b)
sequence :: forall (m :: * -> *) a.
Monad m =>
UniqueMap (m a) -> m (UniqueMap a)
$csequence :: forall (m :: * -> *) a.
Monad m =>
UniqueMap (m a) -> m (UniqueMap a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> UniqueMap a -> m (UniqueMap b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> UniqueMap a -> m (UniqueMap b)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
UniqueMap (f a) -> f (UniqueMap a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
UniqueMap (f a) -> f (UniqueMap a)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> UniqueMap a -> f (UniqueMap b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> UniqueMap a -> f (UniqueMap b)
Traversable)
instance IsMap UniqueMap where
type KeyOf UniqueMap = Int
mapNull :: forall a. UniqueMap a -> Bool
mapNull (UM IntMap a
m) = IntMap a -> Bool
forall a. IntMap a -> Bool
M.null IntMap a
m
mapSize :: forall a. UniqueMap a -> Int
mapSize (UM IntMap a
m) = IntMap a -> Int
forall a. IntMap a -> Int
M.size IntMap a
m
mapMember :: forall a. KeyOf UniqueMap -> UniqueMap a -> Bool
mapMember KeyOf UniqueMap
k (UM IntMap a
m) = Int -> IntMap a -> Bool
forall a. Int -> IntMap a -> Bool
M.member Int
KeyOf UniqueMap
k IntMap a
m
mapLookup :: forall a. KeyOf UniqueMap -> UniqueMap a -> Maybe a
mapLookup KeyOf UniqueMap
k (UM IntMap a
m) = Int -> IntMap a -> Maybe a
forall a. Int -> IntMap a -> Maybe a
M.lookup Int
KeyOf UniqueMap
k IntMap a
m
mapFindWithDefault :: forall a. a -> KeyOf UniqueMap -> UniqueMap a -> a
mapFindWithDefault a
def KeyOf UniqueMap
k (UM IntMap a
m) = a -> Int -> IntMap a -> a
forall a. a -> Int -> IntMap a -> a
M.findWithDefault a
def Int
KeyOf UniqueMap
k IntMap a
m
mapEmpty :: forall a. UniqueMap a
mapEmpty = IntMap a -> UniqueMap a
forall v. IntMap v -> UniqueMap v
UM IntMap a
forall a. IntMap a
M.empty
mapSingleton :: forall a. KeyOf UniqueMap -> a -> UniqueMap a
mapSingleton KeyOf UniqueMap
k a
v = IntMap a -> UniqueMap a
forall v. IntMap v -> UniqueMap v
UM (Int -> a -> IntMap a
forall a. Int -> a -> IntMap a
M.singleton Int
KeyOf UniqueMap
k a
v)
mapInsert :: forall a. KeyOf UniqueMap -> a -> UniqueMap a -> UniqueMap a
mapInsert KeyOf UniqueMap
k a
v (UM IntMap a
m) = IntMap a -> UniqueMap a
forall v. IntMap v -> UniqueMap v
UM (Int -> a -> IntMap a -> IntMap a
forall a. Int -> a -> IntMap a -> IntMap a
M.insert Int
KeyOf UniqueMap
k a
v IntMap a
m)
mapInsertWith :: forall a.
(a -> a -> a) -> KeyOf UniqueMap -> a -> UniqueMap a -> UniqueMap a
mapInsertWith a -> a -> a
f KeyOf UniqueMap
k a
v (UM IntMap a
m) = IntMap a -> UniqueMap a
forall v. IntMap v -> UniqueMap v
UM ((a -> a -> a) -> Int -> a -> IntMap a -> IntMap a
forall a. (a -> a -> a) -> Int -> a -> IntMap a -> IntMap a
M.insertWith a -> a -> a
f Int
KeyOf UniqueMap
k a
v IntMap a
m)
mapDelete :: forall a. KeyOf UniqueMap -> UniqueMap a -> UniqueMap a
mapDelete KeyOf UniqueMap
k (UM IntMap a
m) = IntMap a -> UniqueMap a
forall v. IntMap v -> UniqueMap v
UM (Int -> IntMap a -> IntMap a
forall a. Int -> IntMap a -> IntMap a
M.delete Int
KeyOf UniqueMap
k IntMap a
m)
mapAlter :: forall a.
(Maybe a -> Maybe a)
-> KeyOf UniqueMap -> UniqueMap a -> UniqueMap a
mapAlter Maybe a -> Maybe a
f KeyOf UniqueMap
k (UM IntMap a
m) = IntMap a -> UniqueMap a
forall v. IntMap v -> UniqueMap v
UM ((Maybe a -> Maybe a) -> Int -> IntMap a -> IntMap a
forall a. (Maybe a -> Maybe a) -> Int -> IntMap a -> IntMap a
M.alter Maybe a -> Maybe a
f Int
KeyOf UniqueMap
k IntMap a
m)
mapAdjust :: forall a. (a -> a) -> KeyOf UniqueMap -> UniqueMap a -> UniqueMap a
mapAdjust a -> a
f KeyOf UniqueMap
k (UM IntMap a
m) = IntMap a -> UniqueMap a
forall v. IntMap v -> UniqueMap v
UM ((a -> a) -> Int -> IntMap a -> IntMap a
forall a. (a -> a) -> Int -> IntMap a -> IntMap a
M.adjust a -> a
f Int
KeyOf UniqueMap
k IntMap a
m)
mapUnion :: forall a. UniqueMap a -> UniqueMap a -> UniqueMap a
mapUnion (UM IntMap a
x) (UM IntMap a
y) = IntMap a -> UniqueMap a
forall v. IntMap v -> UniqueMap v
UM (IntMap a -> IntMap a -> IntMap a
forall a. IntMap a -> IntMap a -> IntMap a
M.union IntMap a
x IntMap a
y)
mapUnionWithKey :: forall a.
(KeyOf UniqueMap -> a -> a -> a)
-> UniqueMap a -> UniqueMap a -> UniqueMap a
mapUnionWithKey KeyOf UniqueMap -> a -> a -> a
f (UM IntMap a
x) (UM IntMap a
y) = IntMap a -> UniqueMap a
forall v. IntMap v -> UniqueMap v
UM ((Int -> a -> a -> a) -> IntMap a -> IntMap a -> IntMap a
forall a. (Int -> a -> a -> a) -> IntMap a -> IntMap a -> IntMap a
M.unionWithKey Int -> a -> a -> a
KeyOf UniqueMap -> a -> a -> a
f IntMap a
x IntMap a
y)
mapDifference :: forall a. UniqueMap a -> UniqueMap a -> UniqueMap a
mapDifference (UM IntMap a
x) (UM IntMap a
y) = IntMap a -> UniqueMap a
forall v. IntMap v -> UniqueMap v
UM (IntMap a -> IntMap a -> IntMap a
forall a b. IntMap a -> IntMap b -> IntMap a
M.difference IntMap a
x IntMap a
y)
mapIntersection :: forall a. UniqueMap a -> UniqueMap a -> UniqueMap a
mapIntersection (UM IntMap a
x) (UM IntMap a
y) = IntMap a -> UniqueMap a
forall v. IntMap v -> UniqueMap v
UM (IntMap a -> IntMap a -> IntMap a
forall a b. IntMap a -> IntMap b -> IntMap a
M.intersection IntMap a
x IntMap a
y)
mapIsSubmapOf :: forall v. Eq v => UniqueMap v -> UniqueMap v -> Bool
mapIsSubmapOf (UM IntMap a
x) (UM IntMap a
y) = IntMap a -> IntMap a -> Bool
forall a. Eq a => IntMap a -> IntMap a -> Bool
M.isSubmapOf IntMap a
x IntMap a
y
mapMap :: forall a b. (a -> b) -> UniqueMap a -> UniqueMap b
mapMap a -> b
f (UM IntMap a
m) = IntMap b -> UniqueMap b
forall v. IntMap v -> UniqueMap v
UM ((a -> b) -> IntMap a -> IntMap b
forall a b. (a -> b) -> IntMap a -> IntMap b
M.map a -> b
f IntMap a
m)
mapMapWithKey :: forall a b.
(KeyOf UniqueMap -> a -> b) -> UniqueMap a -> UniqueMap b
mapMapWithKey KeyOf UniqueMap -> a -> b
f (UM IntMap a
m) = IntMap b -> UniqueMap b
forall v. IntMap v -> UniqueMap v
UM ((Int -> a -> b) -> IntMap a -> IntMap b
forall a b. (Int -> a -> b) -> IntMap a -> IntMap b
M.mapWithKey Int -> a -> b
KeyOf UniqueMap -> a -> b
f IntMap a
m)
mapFoldl :: forall b a. (b -> a -> b) -> b -> UniqueMap a -> b
mapFoldl b -> a -> b
k b
z (UM IntMap a
m) = (b -> a -> b) -> b -> IntMap a -> b
forall a b. (a -> b -> a) -> a -> IntMap b -> a
M.foldl' b -> a -> b
k b
z IntMap a
m
mapFoldr :: forall a b. (a -> b -> b) -> b -> UniqueMap a -> b
mapFoldr a -> b -> b
k b
z (UM IntMap a
m) = (a -> b -> b) -> b -> IntMap a -> b
forall a b. (a -> b -> b) -> b -> IntMap a -> b
M.foldr a -> b -> b
k b
z IntMap a
m
mapFoldlWithKey :: forall b a.
(b -> KeyOf UniqueMap -> a -> b) -> b -> UniqueMap a -> b
mapFoldlWithKey b -> KeyOf UniqueMap -> a -> b
k b
z (UM IntMap a
m) = (b -> Int -> a -> b) -> b -> IntMap a -> b
forall a b. (a -> Int -> b -> a) -> a -> IntMap b -> a
M.foldlWithKey' b -> Int -> a -> b
b -> KeyOf UniqueMap -> a -> b
k b
z IntMap a
m
mapFoldMapWithKey :: forall m a.
Monoid m =>
(KeyOf UniqueMap -> a -> m) -> UniqueMap a -> m
mapFoldMapWithKey KeyOf UniqueMap -> a -> m
f (UM IntMap a
m) = (Int -> a -> m) -> IntMap a -> m
forall m a. Monoid m => (Int -> a -> m) -> IntMap a -> m
M.foldMapWithKey Int -> a -> m
KeyOf UniqueMap -> a -> m
f IntMap a
m
{-# INLINEABLE mapFilter #-}
mapFilter :: forall a. (a -> Bool) -> UniqueMap a -> UniqueMap a
mapFilter a -> Bool
f (UM IntMap a
m) = IntMap a -> UniqueMap a
forall v. IntMap v -> UniqueMap v
UM ((a -> Bool) -> IntMap a -> IntMap a
forall a. (a -> Bool) -> IntMap a -> IntMap a
M.filter a -> Bool
f IntMap a
m)
{-# INLINEABLE mapFilterWithKey #-}
mapFilterWithKey :: forall a.
(KeyOf UniqueMap -> a -> Bool) -> UniqueMap a -> UniqueMap a
mapFilterWithKey KeyOf UniqueMap -> a -> Bool
f (UM IntMap a
m) = IntMap a -> UniqueMap a
forall v. IntMap v -> UniqueMap v
UM ((Int -> a -> Bool) -> IntMap a -> IntMap a
forall a. (Int -> a -> Bool) -> IntMap a -> IntMap a
M.filterWithKey Int -> a -> Bool
KeyOf UniqueMap -> a -> Bool
f IntMap a
m)
mapElems :: forall a. UniqueMap a -> [a]
mapElems (UM IntMap a
m) = IntMap a -> [a]
forall a. IntMap a -> [a]
M.elems IntMap a
m
mapKeys :: forall a. UniqueMap a -> [KeyOf UniqueMap]
mapKeys (UM IntMap a
m) = IntMap a -> [Int]
forall a. IntMap a -> [Int]
M.keys IntMap a
m
{-# INLINEABLE mapToList #-}
mapToList :: forall a. UniqueMap a -> [(KeyOf UniqueMap, a)]
mapToList (UM IntMap a
m) = IntMap a -> [(Int, a)]
forall a. IntMap a -> [(Int, a)]
M.toList IntMap a
m
mapFromList :: forall a. [(KeyOf UniqueMap, a)] -> UniqueMap a
mapFromList [(KeyOf UniqueMap, a)]
assocs = IntMap a -> UniqueMap a
forall v. IntMap v -> UniqueMap v
UM ([(Int, a)] -> IntMap a
forall a. [(Int, a)] -> IntMap a
M.fromList [(Int, a)]
[(KeyOf UniqueMap, a)]
assocs)
mapFromListWith :: forall a. (a -> a -> a) -> [(KeyOf UniqueMap, a)] -> UniqueMap a
mapFromListWith a -> a -> a
f [(KeyOf UniqueMap, a)]
assocs = IntMap a -> UniqueMap a
forall v. IntMap v -> UniqueMap v
UM ((a -> a -> a) -> [(Int, a)] -> IntMap a
forall a. (a -> a -> a) -> [(Int, a)] -> IntMap a
M.fromListWith a -> a -> a
f [(Int, a)]
[(KeyOf UniqueMap, a)]
assocs)