{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -Wno-redundant-constraints #-}
module Data.Series.Index.Definition (
Index(..),
singleton,
unfoldr,
range,
fromSet, toSet,
fromList, toAscList,
fromAscList, fromDistinctAscList,
fromVector, toAscVector,
fromAscVector, fromDistinctAscVector,
IsIndex(..),
null,
member,
notMember,
union,
intersection,
difference,
symmetricDifference,
cartesianProduct,
contains,
size,
take,
drop,
map,
mapMonotonic,
filter,
traverse,
findIndex,
lookupIndex,
elemAt,
insert,
delete,
) where
import Control.DeepSeq ( NFData )
import Control.Monad ( guard )
import Control.Monad.ST ( runST )
import Data.Coerce ( coerce )
import qualified Data.Foldable as Foldable
import Data.Functor ( ($>) )
import Data.IntSet ( IntSet )
import qualified Data.IntSet as IntSet
import qualified Data.List as List
import Data.Sequence ( Seq )
import qualified Data.Sequence as Seq
import Data.Set ( Set )
import qualified Data.Set as Set
import qualified Data.Traversable as Traversable
import qualified Data.Vector as Boxed
import Data.Vector.Algorithms.Intro ( sortUniq )
import Data.Vector.Generic ( Vector )
import qualified Data.Vector.Generic as Vector
import qualified Data.Vector.Generic.Mutable as M
import qualified Data.Vector.Unboxed as Unboxed
import GHC.Exts ( IsList )
import qualified GHC.Exts as Exts
import GHC.Stack ( HasCallStack )
import Prelude as P hiding ( null, take, drop, map, filter, traverse, product )
newtype Index k = MkIndex (Set k)
deriving (Index k -> Index k -> Bool
(Index k -> Index k -> Bool)
-> (Index k -> Index k -> Bool) -> Eq (Index k)
forall k. Eq k => Index k -> Index k -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall k. Eq k => Index k -> Index k -> Bool
== :: Index k -> Index k -> Bool
$c/= :: forall k. Eq k => Index k -> Index k -> Bool
/= :: Index k -> Index k -> Bool
Eq, Eq (Index k)
Eq (Index k) =>
(Index k -> Index k -> Ordering)
-> (Index k -> Index k -> Bool)
-> (Index k -> Index k -> Bool)
-> (Index k -> Index k -> Bool)
-> (Index k -> Index k -> Bool)
-> (Index k -> Index k -> Index k)
-> (Index k -> Index k -> Index k)
-> Ord (Index k)
Index k -> Index k -> Bool
Index k -> Index k -> Ordering
Index k -> Index k -> Index k
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 k. Ord k => Eq (Index k)
forall k. Ord k => Index k -> Index k -> Bool
forall k. Ord k => Index k -> Index k -> Ordering
forall k. Ord k => Index k -> Index k -> Index k
$ccompare :: forall k. Ord k => Index k -> Index k -> Ordering
compare :: Index k -> Index k -> Ordering
$c< :: forall k. Ord k => Index k -> Index k -> Bool
< :: Index k -> Index k -> Bool
$c<= :: forall k. Ord k => Index k -> Index k -> Bool
<= :: Index k -> Index k -> Bool
$c> :: forall k. Ord k => Index k -> Index k -> Bool
> :: Index k -> Index k -> Bool
$c>= :: forall k. Ord k => Index k -> Index k -> Bool
>= :: Index k -> Index k -> Bool
$cmax :: forall k. Ord k => Index k -> Index k -> Index k
max :: Index k -> Index k -> Index k
$cmin :: forall k. Ord k => Index k -> Index k -> Index k
min :: Index k -> Index k -> Index k
Ord, NonEmpty (Index k) -> Index k
Index k -> Index k -> Index k
(Index k -> Index k -> Index k)
-> (NonEmpty (Index k) -> Index k)
-> (forall b. Integral b => b -> Index k -> Index k)
-> Semigroup (Index k)
forall b. Integral b => b -> Index k -> Index k
forall k. Ord k => NonEmpty (Index k) -> Index k
forall k. Ord k => Index k -> Index k -> Index k
forall k b. (Ord k, Integral b) => b -> Index k -> Index k
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
$c<> :: forall k. Ord k => Index k -> Index k -> Index k
<> :: Index k -> Index k -> Index k
$csconcat :: forall k. Ord k => NonEmpty (Index k) -> Index k
sconcat :: NonEmpty (Index k) -> Index k
$cstimes :: forall k b. (Ord k, Integral b) => b -> Index k -> Index k
stimes :: forall b. Integral b => b -> Index k -> Index k
Semigroup, Semigroup (Index k)
Index k
Semigroup (Index k) =>
Index k
-> (Index k -> Index k -> Index k)
-> ([Index k] -> Index k)
-> Monoid (Index k)
[Index k] -> Index k
Index k -> Index k -> Index k
forall k. Ord k => Semigroup (Index k)
forall k. Ord k => Index k
forall k. Ord k => [Index k] -> Index k
forall k. Ord k => Index k -> Index k -> Index k
forall a.
Semigroup a =>
a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
$cmempty :: forall k. Ord k => Index k
mempty :: Index k
$cmappend :: forall k. Ord k => Index k -> Index k -> Index k
mappend :: Index k -> Index k -> Index k
$cmconcat :: forall k. Ord k => [Index k] -> Index k
mconcat :: [Index k] -> Index k
Monoid, (forall m. Monoid m => Index m -> m)
-> (forall m a. Monoid m => (a -> m) -> Index a -> m)
-> (forall m a. Monoid m => (a -> m) -> Index a -> m)
-> (forall a b. (a -> b -> b) -> b -> Index a -> b)
-> (forall a b. (a -> b -> b) -> b -> Index a -> b)
-> (forall b a. (b -> a -> b) -> b -> Index a -> b)
-> (forall b a. (b -> a -> b) -> b -> Index a -> b)
-> (forall a. (a -> a -> a) -> Index a -> a)
-> (forall a. (a -> a -> a) -> Index a -> a)
-> (forall a. Index a -> [a])
-> (forall a. Index a -> Bool)
-> (forall a. Index a -> Int)
-> (forall a. Eq a => a -> Index a -> Bool)
-> (forall a. Ord a => Index a -> a)
-> (forall a. Ord a => Index a -> a)
-> (forall a. Num a => Index a -> a)
-> (forall a. Num a => Index a -> a)
-> Foldable Index
forall a. Eq a => a -> Index a -> Bool
forall a. Num a => Index a -> a
forall a. Ord a => Index a -> a
forall m. Monoid m => Index m -> m
forall a. Index a -> Bool
forall a. Index a -> Int
forall a. Index a -> [a]
forall a. (a -> a -> a) -> Index a -> a
forall m a. Monoid m => (a -> m) -> Index a -> m
forall b a. (b -> a -> b) -> b -> Index a -> b
forall a b. (a -> b -> b) -> b -> Index 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
$cfold :: forall m. Monoid m => Index m -> m
fold :: forall m. Monoid m => Index m -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Index a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> Index a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Index a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> Index a -> m
$cfoldr :: forall a b. (a -> b -> b) -> b -> Index a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Index a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Index a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Index a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Index a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Index a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Index a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> Index a -> b
$cfoldr1 :: forall a. (a -> a -> a) -> Index a -> a
foldr1 :: forall a. (a -> a -> a) -> Index a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Index a -> a
foldl1 :: forall a. (a -> a -> a) -> Index a -> a
$ctoList :: forall a. Index a -> [a]
toList :: forall a. Index a -> [a]
$cnull :: forall a. Index a -> Bool
null :: forall a. Index a -> Bool
$clength :: forall a. Index a -> Int
length :: forall a. Index a -> Int
$celem :: forall a. Eq a => a -> Index a -> Bool
elem :: forall a. Eq a => a -> Index a -> Bool
$cmaximum :: forall a. Ord a => Index a -> a
maximum :: forall a. Ord a => Index a -> a
$cminimum :: forall a. Ord a => Index a -> a
minimum :: forall a. Ord a => Index a -> a
$csum :: forall a. Num a => Index a -> a
sum :: forall a. Num a => Index a -> a
$cproduct :: forall a. Num a => Index a -> a
product :: forall a. Num a => Index a -> a
Foldable, Index k -> ()
(Index k -> ()) -> NFData (Index k)
forall k. NFData k => Index k -> ()
forall a. (a -> ()) -> NFData a
$crnf :: forall k. NFData k => Index k -> ()
rnf :: Index k -> ()
NFData)
instance Ord k => IsList (Index k) where
type Item (Index k) = k
fromList :: [k] -> Index k
fromList :: [k] -> Index k
fromList = [k] -> Index k
forall k. Ord k => [k] -> Index k
fromList
toList :: Index k -> [Exts.Item (Index k)]
toList :: Index k -> [Item (Index k)]
toList = Index k -> [k]
Index k -> [Item (Index k)]
forall a. Index a -> [a]
toAscList
instance Show k => Show (Index k) where
show :: Index k -> String
show :: Index k -> String
show (MkIndex Set k
s) = String
"Index " String -> ShowS
forall a. [a] -> [a] -> [a]
++ [k] -> String
forall a. Show a => a -> String
show (Set k -> [k]
forall a. Set a -> [a]
Set.toList Set k
s)
singleton :: k -> Index k
singleton :: forall k. k -> Index k
singleton = Set k -> Index k
forall k. Set k -> Index k
MkIndex (Set k -> Index k) -> (k -> Set k) -> k -> Index k
forall b c a. (b -> c) -> (a -> b) -> a -> c
. k -> Set k
forall a. a -> Set a
Set.singleton
{-# INLINE singleton #-}
unfoldr :: Ord a => (b -> Maybe (a, b)) -> b -> Index a
unfoldr :: forall a b. Ord a => (b -> Maybe (a, b)) -> b -> Index a
unfoldr b -> Maybe (a, b)
f = [a] -> Index a
forall k. Ord k => [k] -> Index k
fromList ([a] -> Index a) -> (b -> [a]) -> b -> Index a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (b -> Maybe (a, b)) -> b -> [a]
forall b a. (b -> Maybe (a, b)) -> b -> [a]
List.unfoldr b -> Maybe (a, b)
f
{-# INLINE unfoldr #-}
range :: Ord a
=> (a -> a)
-> a
-> a
-> Index a
range :: forall a. Ord a => (a -> a) -> a -> a -> Index a
range a -> a
next a
start a
end
= (a -> Maybe (a, a)) -> a -> Index a
forall a b. Ord a => (b -> Maybe (a, b)) -> b -> Index a
unfoldr (\a
x -> Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
end) Maybe () -> (a, a) -> Maybe (a, a)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> (a
x, a -> a
next a
x)) a
start
{-# INLINE range #-}
class IsIndex t k where
toIndex :: t -> Index k
fromIndex :: Index k -> t
instance IsIndex (Set k) k where
toIndex :: Set k -> Index k
toIndex :: Set k -> Index k
toIndex = Set k -> Index k
forall a b. Coercible a b => a -> b
coerce
{-# INLINE toIndex #-}
fromIndex :: Index k -> Set k
fromIndex :: Index k -> Set k
fromIndex = Index k -> Set k
forall a b. Coercible a b => a -> b
coerce
{-# INLINE fromIndex #-}
instance Ord k => IsIndex [k] k where
toIndex :: [k] -> Index k
toIndex :: [k] -> Index k
toIndex = [k] -> Index k
forall k. Ord k => [k] -> Index k
fromList
{-# INLINE toIndex #-}
fromIndex :: Index k -> [k]
fromIndex :: Index k -> [k]
fromIndex = Index k -> [k]
forall a. Index a -> [a]
toAscList
{-# INLINE fromIndex #-}
instance Ord k => IsIndex (Seq k) k where
toIndex :: Seq k -> Index k
toIndex :: Seq k -> Index k
toIndex = [k] -> Index k
forall k. Ord k => [k] -> Index k
fromList ([k] -> Index k) -> (Seq k -> [k]) -> Seq k -> Index k
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Seq k -> [k]
forall a. Seq a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
Foldable.toList
{-# INLINE toIndex #-}
fromIndex :: Index k -> Seq k
fromIndex :: Index k -> Seq k
fromIndex = [k] -> Seq k
forall a. [a] -> Seq a
Seq.fromList ([k] -> Seq k) -> (Index k -> [k]) -> Index k -> Seq k
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Index k -> [k]
forall a. Index a -> [a]
toAscList
{-# INLINE fromIndex #-}
instance IsIndex IntSet Int where
toIndex :: IntSet -> Index Int
toIndex :: IntSet -> Index Int
toIndex = [Int] -> Index Int
forall k. [k] -> Index k
fromDistinctAscList ([Int] -> Index Int) -> (IntSet -> [Int]) -> IntSet -> Index Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IntSet -> [Int]
IntSet.toList
{-# INLINE toIndex #-}
fromIndex :: Index Int -> IntSet
fromIndex :: Index Int -> IntSet
fromIndex = [Int] -> IntSet
IntSet.fromDistinctAscList ([Int] -> IntSet) -> (Index Int -> [Int]) -> Index Int -> IntSet
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Index Int -> [Int]
forall a. Index a -> [a]
toAscList
{-# INLINE fromIndex #-}
instance (Ord k) => IsIndex (Boxed.Vector k) k where
toIndex :: Boxed.Vector k -> Index k
toIndex :: Vector k -> Index k
toIndex = Vector k -> Index k
forall (v :: * -> *) k. (Vector v k, Ord k) => v k -> Index k
fromVector
{-# INLINE toIndex #-}
fromIndex :: Index k -> Boxed.Vector k
fromIndex :: Index k -> Vector k
fromIndex = Index k -> Vector k
forall (v :: * -> *) k. Vector v k => Index k -> v k
toAscVector
{-# INLINE fromIndex #-}
instance (Ord k, Unboxed.Unbox k) => IsIndex (Unboxed.Vector k) k where
toIndex :: Unboxed.Vector k -> Index k
toIndex :: Vector k -> Index k
toIndex = Vector k -> Index k
forall (v :: * -> *) k. (Vector v k, Ord k) => v k -> Index k
fromVector
{-# INLINE toIndex #-}
fromIndex :: Index k -> Unboxed.Vector k
fromIndex :: Index k -> Vector k
fromIndex Index k
ix = (forall s. ST s (Vector k)) -> Vector k
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (Vector k)) -> Vector k)
-> (forall s. ST s (Vector k)) -> Vector k
forall a b. (a -> b) -> a -> b
$ Int -> (Int -> k) -> ST s (MVector (PrimState (ST s)) k)
forall (m :: * -> *) (v :: * -> * -> *) a.
(PrimMonad m, MVector v a) =>
Int -> (Int -> a) -> m (v (PrimState m) a)
M.generate (Index k -> Int
forall a. Index a -> Int
size Index k
ix) (Int -> Index k -> k
forall k. HasCallStack => Int -> Index k -> k
`elemAt` Index k
ix) ST s (MVector s k)
-> (MVector s k -> ST s (Vector k)) -> ST s (Vector k)
forall a b. ST s a -> (a -> ST s b) -> ST s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= MVector s k -> ST s (Vector k)
Mutable Vector (PrimState (ST s)) k -> ST s (Vector k)
forall (m :: * -> *) (v :: * -> *) a.
(PrimMonad m, Vector v a) =>
Mutable v (PrimState m) a -> m (v a)
Vector.freeze
{-# INLINE fromIndex #-}
fromSet :: Set k -> Index k
fromSet :: forall k. Set k -> Index k
fromSet = Set k -> Index k
forall t k. IsIndex t k => t -> Index k
toIndex
{-# INLINE fromSet #-}
fromList :: Ord k => [k] -> Index k
fromList :: forall k. Ord k => [k] -> Index k
fromList = Set k -> Index k
forall k. Set k -> Index k
fromSet (Set k -> Index k) -> ([k] -> Set k) -> [k] -> Index k
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [k] -> Set k
forall a. Ord a => [a] -> Set a
Set.fromList
{-# INLINE fromList #-}
fromAscList :: Eq k => [k] -> Index k
fromAscList :: forall k. Eq k => [k] -> Index k
fromAscList = Set k -> Index k
forall t k. IsIndex t k => t -> Index k
toIndex (Set k -> Index k) -> ([k] -> Set k) -> [k] -> Index k
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [k] -> Set k
forall a. Eq a => [a] -> Set a
Set.fromAscList
{-# INLINE fromAscList #-}
fromDistinctAscList :: [k] -> Index k
fromDistinctAscList :: forall k. [k] -> Index k
fromDistinctAscList = Set k -> Index k
forall k. Set k -> Index k
MkIndex (Set k -> Index k) -> ([k] -> Set k) -> [k] -> Index k
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [k] -> Set k
forall a. [a] -> Set a
Set.fromDistinctAscList
{-# INLINE fromDistinctAscList #-}
fromVector :: (Vector v k, Ord k) => v k -> Index k
fromVector :: forall (v :: * -> *) k. (Vector v k, Ord k) => v k -> Index k
fromVector v k
vs = v k -> Index k
forall (v :: * -> *) k. Vector v k => v k -> Index k
fromDistinctAscVector (v k -> Index k) -> v k -> Index k
forall a b. (a -> b) -> a -> b
$ (forall s. ST s (v k)) -> v k
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (v k)) -> v k) -> (forall s. ST s (v k)) -> v k
forall a b. (a -> b) -> a -> b
$ v k -> ST s (Mutable v (PrimState (ST s)) k)
forall (m :: * -> *) (v :: * -> *) a.
(PrimMonad m, Vector v a) =>
v a -> m (Mutable v (PrimState m) a)
Vector.thaw v k
vs ST s (Mutable v s k)
-> (Mutable v s k -> ST s (Mutable v s k)) -> ST s (Mutable v s k)
forall a b. ST s a -> (a -> ST s b) -> ST s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Mutable v s k -> ST s (Mutable v s k)
Mutable v (PrimState (ST s)) k
-> ST s (Mutable v (PrimState (ST s)) k)
forall (m :: * -> *) (v :: * -> * -> *) e.
(PrimMonad m, MVector v e, Ord e) =>
v (PrimState m) e -> m (v (PrimState m) e)
sortUniq ST s (Mutable v s k) -> (Mutable v s k -> ST s (v k)) -> ST s (v k)
forall a b. ST s a -> (a -> ST s b) -> ST s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Mutable v s k -> ST s (v k)
Mutable v (PrimState (ST s)) k -> ST s (v k)
forall (m :: * -> *) (v :: * -> *) a.
(PrimMonad m, Vector v a) =>
Mutable v (PrimState m) a -> m (v a)
Vector.freeze
{-# INLINE fromVector #-}
fromAscVector :: (Vector v k, Ord k) => v k -> Index k
fromAscVector :: forall (v :: * -> *) k. (Vector v k, Ord k) => v k -> Index k
fromAscVector = [k] -> Index k
forall k. Eq k => [k] -> Index k
fromAscList ([k] -> Index k) -> (v k -> [k]) -> v k -> Index k
forall b c a. (b -> c) -> (a -> b) -> a -> c
. v k -> [k]
forall (v :: * -> *) a. Vector v a => v a -> [a]
Vector.toList
{-# INLINE fromAscVector #-}
fromDistinctAscVector :: Vector v k => v k -> Index k
fromDistinctAscVector :: forall (v :: * -> *) k. Vector v k => v k -> Index k
fromDistinctAscVector = [k] -> Index k
forall k. [k] -> Index k
fromDistinctAscList ([k] -> Index k) -> (v k -> [k]) -> v k -> Index k
forall b c a. (b -> c) -> (a -> b) -> a -> c
. v k -> [k]
forall (v :: * -> *) a. Vector v a => v a -> [a]
Vector.toList
{-# INLINE fromDistinctAscVector #-}
toSet :: Index k -> Set k
toSet :: forall k. Index k -> Set k
toSet = Index k -> Set k
forall t k. IsIndex t k => Index k -> t
fromIndex
{-# INLINE toSet #-}
toAscList :: Index k -> [k]
toAscList :: forall a. Index a -> [a]
toAscList (MkIndex Set k
s) = Set k -> [k]
forall a. Set a -> [a]
Set.toAscList Set k
s
{-# INLINE toAscList #-}
toAscVector :: Vector v k => Index k -> v k
toAscVector :: forall (v :: * -> *) k. Vector v k => Index k -> v k
toAscVector Index k
ix = (forall s. ST s (v k)) -> v k
forall a. (forall s. ST s a) -> a
runST ((forall s. ST s (v k)) -> v k) -> (forall s. ST s (v k)) -> v k
forall a b. (a -> b) -> a -> b
$ Int -> (Int -> k) -> ST s (Mutable v (PrimState (ST s)) k)
forall (m :: * -> *) (v :: * -> * -> *) a.
(PrimMonad m, MVector v a) =>
Int -> (Int -> a) -> m (v (PrimState m) a)
M.generate (Index k -> Int
forall a. Index a -> Int
size Index k
ix) (Int -> Index k -> k
forall k. HasCallStack => Int -> Index k -> k
`elemAt` Index k
ix) ST s (Mutable v s k) -> (Mutable v s k -> ST s (v k)) -> ST s (v k)
forall a b. ST s a -> (a -> ST s b) -> ST s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Mutable v s k -> ST s (v k)
Mutable v (PrimState (ST s)) k -> ST s (v k)
forall (m :: * -> *) (v :: * -> *) a.
(PrimMonad m, Vector v a) =>
Mutable v (PrimState m) a -> m (v a)
Vector.freeze
{-# INLINE toAscVector #-}
null :: Index k -> Bool
null :: forall a. Index a -> Bool
null (MkIndex Set k
ix) = Set k -> Bool
forall a. Set a -> Bool
Set.null Set k
ix
{-# INLINE null #-}
member :: Ord k => k -> Index k -> Bool
member :: forall k. Ord k => k -> Index k -> Bool
member k
k (MkIndex Set k
ix) = k
k k -> Set k -> Bool
forall a. Ord a => a -> Set a -> Bool
`Set.member` Set k
ix
{-# INLINE member #-}
notMember :: Ord k => k -> Index k -> Bool
notMember :: forall k. Ord k => k -> Index k -> Bool
notMember k
k = Bool -> Bool
not (Bool -> Bool) -> (Index k -> Bool) -> Index k -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. k -> Index k -> Bool
forall k. Ord k => k -> Index k -> Bool
member k
k
{-# INLINE notMember #-}
union :: Ord k => Index k -> Index k -> Index k
union :: forall k. Ord k => Index k -> Index k -> Index k
union = Index k -> Index k -> Index k
forall a. Semigroup a => a -> a -> a
(<>)
{-# INLINE union #-}
intersection :: Ord k => Index k -> Index k -> Index k
intersection :: forall k. Ord k => Index k -> Index k -> Index k
intersection (MkIndex Set k
ix) (MkIndex Set k
jx) = Set k -> Index k
forall k. Set k -> Index k
MkIndex (Set k -> Index k) -> Set k -> Index k
forall a b. (a -> b) -> a -> b
$ Set k
ix Set k -> Set k -> Set k
forall a. Ord a => Set a -> Set a -> Set a
`Set.intersection` Set k
jx
{-# INLINE intersection #-}
difference :: Ord k => Index k -> Index k -> Index k
difference :: forall k. Ord k => Index k -> Index k -> Index k
difference (MkIndex Set k
ix) (MkIndex Set k
jx) = Set k -> Index k
forall k. Set k -> Index k
MkIndex (Set k -> Index k) -> Set k -> Index k
forall a b. (a -> b) -> a -> b
$ Set k -> Set k -> Set k
forall a. Ord a => Set a -> Set a -> Set a
Set.difference Set k
ix Set k
jx
{-# INLINE difference #-}
symmetricDifference :: Ord k => Index k -> Index k -> (Index k, Index k)
symmetricDifference :: forall k. Ord k => Index k -> Index k -> (Index k, Index k)
symmetricDifference Index k
left Index k
right = (Index k
left Index k -> Index k -> Index k
forall k. Ord k => Index k -> Index k -> Index k
`difference` Index k
right, Index k
right Index k -> Index k -> Index k
forall k. Ord k => Index k -> Index k -> Index k
`difference` Index k
left)
{-# INLINE symmetricDifference #-}
cartesianProduct :: Index k -> Index g -> Index (k, g)
cartesianProduct :: forall k g. Index k -> Index g -> Index (k, g)
cartesianProduct (MkIndex Set k
xs) (MkIndex Set g
ys)
= Set (k, g) -> Index (k, g)
forall k. Set k -> Index k
MkIndex (Set (k, g) -> Index (k, g)) -> Set (k, g) -> Index (k, g)
forall a b. (a -> b) -> a -> b
$ Set k -> Set g -> Set (k, g)
forall a b. Set a -> Set b -> Set (a, b)
Set.cartesianProduct Set k
xs Set g
ys
{-# INLINE cartesianProduct #-}
contains :: Ord k => Index k -> Index k -> Bool
contains :: forall k. Ord k => Index k -> Index k -> Bool
contains (MkIndex Set k
ix1) (MkIndex Set k
ix2)= Set k
ix2 Set k -> Set k -> Bool
forall a. Ord a => Set a -> Set a -> Bool
`Set.isSubsetOf` Set k
ix1
{-# INLINE contains #-}
size :: Index k -> Int
size :: forall a. Index a -> Int
size (MkIndex Set k
ix) = Set k -> Int
forall a. Set a -> Int
Set.size Set k
ix
{-# INLINE size #-}
take :: Int -> Index k -> Index k
take :: forall k. Int -> Index k -> Index k
take Int
n (MkIndex Set k
ix) = Set k -> Index k
forall k. Set k -> Index k
MkIndex (Int -> Set k -> Set k
forall a. Int -> Set a -> Set a
Set.take Int
n Set k
ix)
{-# INLINE take #-}
drop :: Int -> Index k -> Index k
drop :: forall k. Int -> Index k -> Index k
drop Int
n (MkIndex Set k
ix) = Set k -> Index k
forall k. Set k -> Index k
MkIndex (Int -> Set k -> Set k
forall a. Int -> Set a -> Set a
Set.drop Int
n Set k
ix)
{-# INLINE drop #-}
map :: Ord g => (k -> g) -> Index k -> Index g
map :: forall g k. Ord g => (k -> g) -> Index k -> Index g
map k -> g
f (MkIndex Set k
ix) = Set g -> Index g
forall k. Set k -> Index k
MkIndex (Set g -> Index g) -> Set g -> Index g
forall a b. (a -> b) -> a -> b
$ (k -> g) -> Set k -> Set g
forall b a. Ord b => (a -> b) -> Set a -> Set b
Set.map k -> g
f Set k
ix
{-# INLINE map #-}
mapMonotonic :: (k -> g) -> Index k -> Index g
mapMonotonic :: forall k g. (k -> g) -> Index k -> Index g
mapMonotonic k -> g
f (MkIndex Set k
ix) = Set g -> Index g
forall k. Set k -> Index k
MkIndex (Set g -> Index g) -> Set g -> Index g
forall a b. (a -> b) -> a -> b
$ (k -> g) -> Set k -> Set g
forall a b. (a -> b) -> Set a -> Set b
Set.mapMonotonic k -> g
f Set k
ix
{-# INLINE mapMonotonic #-}
filter :: (k -> Bool) -> Index k -> Index k
filter :: forall k. (k -> Bool) -> Index k -> Index k
filter k -> Bool
p (MkIndex Set k
ix) = Set k -> Index k
forall k. Set k -> Index k
MkIndex (Set k -> Index k) -> Set k -> Index k
forall a b. (a -> b) -> a -> b
$ (k -> Bool) -> Set k -> Set k
forall a. (a -> Bool) -> Set a -> Set a
Set.filter k -> Bool
p Set k
ix
{-# INLINE filter #-}
findIndex :: HasCallStack => Ord k => k -> Index k -> Int
findIndex :: forall k. (HasCallStack, Ord k) => k -> Index k -> Int
findIndex k
e (MkIndex Set k
ix) = k -> Set k -> Int
forall a. Ord a => a -> Set a -> Int
Set.findIndex k
e Set k
ix
{-# INLINE findIndex #-}
lookupIndex :: Ord k => k -> Index k -> Maybe Int
lookupIndex :: forall k. Ord k => k -> Index k -> Maybe Int
lookupIndex k
e (MkIndex Set k
ix) = k -> Set k -> Maybe Int
forall a. Ord a => a -> Set a -> Maybe Int
Set.lookupIndex k
e Set k
ix
{-# INLINE lookupIndex #-}
elemAt :: HasCallStack => Int -> Index k -> k
elemAt :: forall k. HasCallStack => Int -> Index k -> k
elemAt Int
n (MkIndex Set k
ix) = Int -> Set k -> k
forall a. Int -> Set a -> a
Set.elemAt Int
n Set k
ix
{-# INLINE elemAt #-}
insert :: Ord k => k -> Index k -> Index k
insert :: forall k. Ord k => k -> Index k -> Index k
insert k
k (MkIndex Set k
ix) = Set k -> Index k
forall k. Set k -> Index k
MkIndex (Set k -> Index k) -> Set k -> Index k
forall a b. (a -> b) -> a -> b
$ k
k k -> Set k -> Set k
forall a. Ord a => a -> Set a -> Set a
`Set.insert` Set k
ix
{-# INLINE insert #-}
delete :: Ord k => k -> Index k -> Index k
delete :: forall k. Ord k => k -> Index k -> Index k
delete k
k (MkIndex Set k
ix) = Set k -> Index k
forall k. Set k -> Index k
MkIndex (Set k -> Index k) -> Set k -> Index k
forall a b. (a -> b) -> a -> b
$ k
k k -> Set k -> Set k
forall a. Ord a => a -> Set a -> Set a
`Set.delete` Set k
ix
{-# INLINE delete #-}
traverse :: (Applicative f, Ord b) => (k -> f b) -> Index k -> f (Index b)
traverse :: forall (f :: * -> *) b k.
(Applicative f, Ord b) =>
(k -> f b) -> Index k -> f (Index b)
traverse k -> f b
f = ([b] -> Index b) -> f [b] -> f (Index b)
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [b] -> Index b
forall k. Ord k => [k] -> Index k
fromList (f [b] -> f (Index b))
-> (Index k -> f [b]) -> Index k -> f (Index b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (k -> f b) -> [k] -> f [b]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
Traversable.traverse k -> f b
f ([k] -> f [b]) -> (Index k -> [k]) -> Index k -> f [b]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Index k -> [k]
forall a. Index a -> [a]
toAscList
{-# INLINE traverse #-}