containers-verified-0.5.11.0: Formally verified drop-in replacement of containers

Safe HaskellSafe
LanguageHaskell2010

Data.IntSet

Contents

Description

Please see the documentation of containers for details.

Synopsis

Set type

data IntSet :: * #

A set of integers.

Instances

IsList IntSet

Since: 0.5.6.2

Associated Types

type Item IntSet :: * #

Eq IntSet 

Methods

(==) :: IntSet -> IntSet -> Bool #

(/=) :: IntSet -> IntSet -> Bool #

Data IntSet 

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> IntSet -> c IntSet #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c IntSet #

toConstr :: IntSet -> Constr #

dataTypeOf :: IntSet -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c IntSet) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c IntSet) #

gmapT :: (forall b. Data b => b -> b) -> IntSet -> IntSet #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> IntSet -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> IntSet -> r #

gmapQ :: (forall d. Data d => d -> u) -> IntSet -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> IntSet -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> IntSet -> m IntSet #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> IntSet -> m IntSet #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> IntSet -> m IntSet #

Ord IntSet 
Read IntSet 
Show IntSet 
Semigroup IntSet

Since: 0.5.7

Monoid IntSet 
NFData IntSet 

Methods

rnf :: IntSet -> () #

type Item IntSet 
type Item IntSet = Key

type Key = Int #

Operators

(\\) :: IntSet -> IntSet -> IntSet infixl 9 #

O(n+m). See difference.

Query

null :: IntSet -> Bool #

O(1). Is the set empty?

size :: IntSet -> Int #

O(n). Cardinality of the set.

member :: Key -> IntSet -> Bool #

O(min(n,W)). Is the value a member of the set?

notMember :: Key -> IntSet -> Bool #

O(min(n,W)). Is the element not in the set?

isSubsetOf :: IntSet -> IntSet -> Bool #

O(n+m). Is this a subset? (s1 isSubsetOf s2) tells whether s1 is a subset of s2.

isProperSubsetOf :: IntSet -> IntSet -> Bool #

O(n+m). Is this a proper subset? (ie. a subset but not equal).

disjoint :: IntSet -> IntSet -> Bool #

O(n+m). Check whether two sets are disjoint (i.e. their intersection is empty).

disjoint (fromList [2,4,6])   (fromList [1,3])     == True
disjoint (fromList [2,4,6,8]) (fromList [2,3,5,7]) == False
disjoint (fromList [1,2])     (fromList [1,2,3,4]) == False
disjoint (fromList [])        (fromList [])        == True

Since: 0.5.11

Construction

empty :: IntSet #

O(1). The empty set.

singleton :: Key -> IntSet #

O(1). A set of one element.

insert :: Key -> IntSet -> IntSet #

O(min(n,W)). Add a value to the set. There is no left- or right bias for IntSets.

delete :: Key -> IntSet -> IntSet #

O(min(n,W)). Delete a value in the set. Returns the original set when the value was not present.

Combine

union :: IntSet -> IntSet -> IntSet #

O(n+m). The union of two sets.

difference :: IntSet -> IntSet -> IntSet #

O(n+m). Difference between two sets.

intersection :: IntSet -> IntSet -> IntSet #

O(n+m). The intersection of two sets.

Filter

filter :: (Key -> Bool) -> IntSet -> IntSet #

O(n). Filter all elements that satisfy some predicate.

partition :: (Key -> Bool) -> IntSet -> (IntSet, IntSet) #

O(n). partition the set according to some predicate.

split :: Key -> IntSet -> (IntSet, IntSet) #

O(min(n,W)). The expression (split x set) is a pair (set1,set2) where set1 comprises the elements of set less than x and set2 comprises the elements of set greater than x.

split 3 (fromList [1..5]) == (fromList [1,2], fromList [4,5])

splitMember :: Key -> IntSet -> (IntSet, Bool, IntSet) #

O(min(n,W)). Performs a split but also returns whether the pivot element was found in the original set.

Map

Folds

foldr :: (Key -> b -> b) -> b -> IntSet -> b #

O(n). Fold the elements in the set using the given right-associative binary operator, such that foldr f z == foldr f z . toAscList.

For example,

toAscList set = foldr (:) [] set

foldl :: (a -> Key -> a) -> a -> IntSet -> a #

O(n). Fold the elements in the set using the given left-associative binary operator, such that foldl f z == foldl f z . toAscList.

For example,

toDescList set = foldl (flip (:)) [] set

Strict folds

foldr' :: (Key -> b -> b) -> b -> IntSet -> b #

O(n). A strict version of foldr. Each application of the operator is evaluated before using the result in the next application. This function is strict in the starting value.

foldl' :: (a -> Key -> a) -> a -> IntSet -> a #

O(n). A strict version of foldl. Each application of the operator is evaluated before using the result in the next application. This function is strict in the starting value.

Legacy folds

fold :: (Key -> b -> b) -> b -> IntSet -> b #

O(n). Fold the elements in the set using the given right-associative binary operator. This function is an equivalent of foldr and is present for compatibility only.

Please note that fold will be deprecated in the future and removed.

Conversion

List

elems :: IntSet -> [Key] #

O(n). An alias of toAscList. The elements of a set in ascending order. Subject to list fusion.

toList :: IntSet -> [Key] #

O(n). Convert the set to a list of elements. Subject to list fusion.

fromList :: [Key] -> IntSet #

O(n*min(n,W)). Create a set from a list of integers.

Ordered list

toAscList :: IntSet -> [Key] #

O(n). Convert the set to an ascending list of elements. Subject to list fusion.

toDescList :: IntSet -> [Key] #

O(n). Convert the set to a descending list of elements. Subject to list fusion.