Module imm/sorted_set
Persistent immutable sorted set using a left-leaning red-black tree.
SortedSet(T) is a thin wrapper around SortedMap(T, bool), keeping
elements in sorted order. All mutations return new sets, leaving the
original unchanged.
Elements must implement Eq, Ord, and Send.
Examples
{ SortedSet } :: import "std/imm/sorted_set";
s := SortedSet(i32).new();
s = s.insert(i32(3));
s = s.insert(i32(1));
s = s.insert(i32(2));
// elements are always sorted: 1, 2, 3
Types
Persistent immutable sorted set backed by a left-leaning red-black tree.
Type Parameters
| Name | Type | Notes |
|---|---|---|
T | Type | comptime |
Trait Implementations
impl(forall(T : Type), where(T <: (Eq(T), Ord(T), Send)), SortedSet(T), ...)
new : (fn() -> Self)Create an empty sorted set.
Returns: Self
len : (fn(self: Self) -> usize)Number of elements.
Returns: usize
is_empty : (fn(self: Self) -> bool)Check if the set is empty.
Returns: bool
contains : (fn(self: Self, elem: T) -> bool)Check if the set contains elem.
Returns: bool
insert : (fn(self: Self, elem: T) -> Self)Return a new set with elem added.
Returns: Self
remove : (fn(self: Self, elem: T) -> Self)Return a new set with elem removed.
Returns: Self
min : (fn(self: Self) -> Option(T))Get the minimum element.
Returns: Option(T)
max : (fn(self: Self) -> Option(T))Get the maximum element.
Returns: Option(T)
to_list : (fn(self: Self) -> List(T))Return elements as a sorted List.
Returns: List(T)
union : (fn(self: Self, other: Self) -> Self)Return the union of two sorted sets.
Returns: Self
intersection : (fn(self: Self, other: Self) -> Self)Return the intersection of two sorted sets.
Returns: Self
difference : (fn(self: Self, other: Self) -> Self)Return the difference (self \ other).
Returns: Self
is_subset : (fn(self: Self, other: Self) -> bool)Check if self is a subset of other.
Returns: bool
is_disjoint : (fn(self: Self, other: Self) -> bool)Check if two sorted sets are disjoint.
Returns: bool
from_slice : (fn(s: Slice(T)) -> Self)Create a sorted set from a slice of elements.
Returns: Self