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

The Set(a) type represents a set of elements of type a.

pub type Set(a) =
  red_black_tree_set.Set(a)

Values

pub fn contains(
  in set: red_black_tree_set.Set(a),
  this member: a,
) -> Bool

Checks if the set contains a given element.

pub fn count(set: red_black_tree_set.Set(a)) -> Int

Returns the number of elements in the set. Time complexity: O(n)

pub fn delete(
  from set: red_black_tree_set.Set(a),
  this member: a,
) -> red_black_tree_set.Set(a)

Removes an element from the set, if it exists.

pub fn difference(
  from set: red_black_tree_set.Set(a),
  remove removal: red_black_tree_set.Set(a),
) -> red_black_tree_set.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: red_black_tree_set.Set(a),
  for property: fn(a) -> Bool,
) -> red_black_tree_set.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: red_black_tree_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.Order,
) -> red_black_tree_set.Set(a)

Creates a new set from a list of elements and a comparison function.

pub fn insert(
  into set: red_black_tree_set.Set(a),
  this member: a,
) -> red_black_tree_set.Set(a)

Inserts a new element into the set, if it is not already present.

pub fn intersection(
  of first: red_black_tree_set.Set(a),
  and second: red_black_tree_set.Set(a),
) -> red_black_tree_set.Set(a)

Creates a new set containing the intersection (common elements) of two sets.

pub fn new(
  compare: fn(a, a) -> order.Order,
) -> red_black_tree_set.Set(a)

Creates a new empty set with the provided comparison function.

pub fn to_list(set: red_black_tree_set.Set(a)) -> List(a)

Converts the set to a list of its elements.

pub fn union(
  of first: red_black_tree_set.Set(a),
  and second: red_black_tree_set.Set(a),
) -> red_black_tree_set.Set(a)

Creates a new set containing the union (all elements) of two sets.

Search Document