gleamy/set
This module provides an implementation of an ordered set data structure based on red-black trees. A set is a collection of unique values, ordered by the comparison function.
Types
Functions
pub fn contains(in set: Set(a), this member: a) -> Bool
Checks if the set contains a given element.
pub fn count(set: Set(a)) -> Int
Returns the number of elements in the set. Time complexity: O(n)
pub fn delete(from set: Set(a), this member: a) -> Set(a)
Removes an element from the set, if it exists.
pub fn difference(
from set: Set(a),
remove removal: Set(a),
) -> Set(a)
Creates a new set containing the elements of the first set except for elements that are also in the second set.
pub fn filter(
in set: Set(a),
for property: fn(a) -> Bool,
) -> Set(a)
Creates a new set containing only the elements from the original set that satisfy a given predicate function.
pub fn fold(
over set: Set(a),
from initial: b,
with reducer: fn(b, a) -> b,
) -> b
Applies a function to every element in the set, accumulating the results with the provided initial accumulator value.
pub fn from_list(
members: List(a),
compare: fn(a, a) -> Order,
) -> Set(a)
Creates a new set from a list of elements and a comparison function.
pub fn insert(into set: Set(a), this member: a) -> Set(a)
Inserts a new element into the set, if it is not already present.
pub fn intersection(
of first: Set(a),
and second: Set(a),
) -> Set(a)
Creates a new set containing the intersection (common elements) of two sets.
pub fn new(compare: fn(a, a) -> Order) -> Set(a)
Creates a new empty set with the provided comparison function.