Module MSet

This module is undocumented. This is a list of its definitions.

add :: MSet.T a -> a -> <Proc> Boolean

Adds the given value to the set. Returns True if the set did not already contain it.

addAll :: MSet.T a -> [a] -> <Proc> Boolean

Adds all values of the given list to the set. Returns True if the set changed. It is the set given as the first argument that is mutated.

Example:

> s = MSet.fromList [1, 2]
> MSet.addAll s [9, 1]
True
> sort (MSet.toList s)
[1, 2, 9]
addAllS :: MSet.T a -> MSet.T a -> <Proc> Boolean

Adds all values of the second set to the first one. Returns True if the first set changed.

It is the first argument that is mutated; the second one is only read.

Example:

> a = MSet.fromList [1, 2]
> b = MSet.fromList [3]
> MSet.addAllS a b
True
> sort (MSet.toList a)
[1, 2, 3]
> sort (MSet.toList b)
[3]
all :: (a -> <b> Boolean) -> MSet.T a -> <b,Proc> Boolean

Returns True if all values of the set satisfy the given predicate.

clear :: MSet.T a -> <Proc> ()

Removes all values from the set.

concatMap :: (a -> <c> MSet.T b) -> MSet.T a -> <Proc,c> MSet.T b

Creates a new set containing all values of all sets produced by the given function.

contains :: MSet.T a -> a -> <Proc> Boolean

Returns True if the set contains the given value.

create :: () -> <Proc> MSet.T a

Creates a new empty set.

createC :: Integer -> <Proc> MSet.T a

Creates a new empty set with room for the given number of values.

createConcurrentHashMapKeySet :: () -> <Proc> MSet.T a

Creates a new empty set that is safe to use from multiple threads.

createConcurrentSkipListSet :: () -> <Proc> MSet.T a

Creates a new empty set that is safe to use from multiple threads and keeps its values in ascending order.

filterInPlace :: (a -> <b> Boolean) -> MSet.T a -> <b,Proc> ()

Removes from the set all values that do not satisfy the given predicate.

Unlike Prelude.filter, this returns no new set: it mutates the given set and returns (). The predicate says which values to keep, not which to remove, so despite the name the values passing the predicate are the survivors.

Example:

> s = MSet.fromList [1, 2, 3, 4, 5]
> MSet.filterInPlace (\x -> mod x 2 == 0) s
> sort (MSet.toList s)
[2, 4]
fold :: (a -> b -> <c> a) -> a -> MSet.T b -> <Proc,c> a

Folds over all values of the set starting with the given initial value.

freeze :: MSet.T a -> <Proc> Set.T a

Converts the mutable set into an immutable one without copying the underlying data. This only changes how the structure is treated by the SCL type system; it is an O(1) operation, not a copy. The original mutable set must not be used anymore after this.

The result aliases the original: it is the same object, only retyped. Every subsequent mutation of the mutable set is visible through the supposedly immutable one, as the first example below shows. That is why the original must be dropped. When both are needed, take a copy with toList instead.

Examples:

> s = MSet.fromList [1]
> i = MSet.freeze s
> ignore (MSet.add s 2)
> sort (Set.toList i)
[1, 2]

toList copies, so the set stays usable and the result does not change:

> s = MSet.fromList [1]
> l = MSet.toList s
> ignore (MSet.add s 2)
> l
[1]
fromList :: [a] -> <Proc> MSet.T a

Creates a new set containing the values of the given list.

isEmpty :: MSet.T a -> <Proc> Boolean

Returns True if the set contains no values.

iter :: (a -> <c> b) -> MSet.T a -> <c,Proc> ()

Calls the given function with all values of the set.

iterB :: (a -> <b> Boolean) -> MSet.T a -> <b,Proc> Boolean

Calls the given function with the values of the set until it returns False. Returns False if the iteration was interrupted this way and True if the function accepted all values.

The result means "was not interrupted", not "found something". See MMap.iterB for a worked example of the same pattern.

map :: (a -> <c> b) -> MSet.T a -> <c,Proc> MSet.T b

Creates a new set containing the values of the given set mapped with the given function.

The result can be smaller than the input: if the function maps two distinct values to the same result, the set keeps only one of them. This is a set, not a list, so there is no size-preservation guarantee.

Example:

> s = MSet.fromList [1, 2, 3, 4]
> r = MSet.map (\x -> mod x 2) s
> MSet.size r
2
> sort (MSet.toList r)
[0, 1]
mapFirst :: (a -> <c> Maybe b) -> MSet.T a -> <c,Proc> Maybe b

Applies the given function to the values of the set until it returns Just and returns that result. Returns Nothing if the function returns Nothing for all values.

Despite the name, "first" is meaningless here: this is a hash set, so its iteration order is not a contract. If the function returns Just for more than one value, which of those results is returned is nondeterministic. Only use this when at most one value can match, or when any match will do.

Example:

> s = MSet.fromList [1, 2, 3]
> MSet.mapFirst (\x -> if x == 2 then Just "two" else Nothing) s
Just "two"
> MSet.mapFirst (\x -> if x > 10 then Just x else Nothing) s
Nothing
remove :: MSet.T a -> a -> <Proc> Boolean

Removes the given value from the set. Returns True if the set contained it.

removeAll :: MSet.T a -> [a] -> <Proc> Boolean

Removes all values of the given list from the set. Returns True if the set changed.

singleton :: a -> <Proc> MSet.T a

Creates a new set containing just the given value.

size :: MSet.T a -> <Proc> Integer

The number of values in the set.

toList :: MSet.T a -> <Proc> [a]

The values of the set as a list. This copies: the returned list is independent of the set, which stays usable. Contrast freeze, which does not copy.

The set is hash-based, so the order of the returned list is not a contract. sort the result if a stable order is needed.