Skip to content
CryoCryo home
Stdlibcollections

btree_set

import std::collections::btree_set; · source

Types

BTreeSet<T, A>

type struct BTreeSet<T, A = GlobalAllocator> where A: Allocator {
    private map: BTreeMap<T, (), A>;
}

A set of distinct values kept in ascending order: a BTreeMap whose values are (). Values need Ord; finding, inserting, and removing are O(log n), and iteration runs in ascending order from either end.

import std::collections::btree_set::{ BTreeSet };

mut seen: BTreeSet<i64> = BTreeSet::new();
seen.insert(3);
seen.insert(1);
const added: boolean = seen.insert(3);           // false: already present
const smallest: Option<i64*> = seen.first();     // 1

insert returns true when the value was not already present — a value already there is kept, and the new one released — and remove returns true when it was present. first and last borrow the smallest and greatest values; pop_first and pop_last take them out. iter() yields by value and needs T: Copy; iterate_references() and range(bounds) borrow. Every iterator is a DoubleEndedIterator.

Constructors

static new() -> BTreeSet<T, GlobalAllocator>;

An empty set backed by GlobalAllocator. Allocates nothing until the first insert.

static new_in(alloc: A) -> BTreeSet<T, A>;

An empty set that allocates through alloc.

Methods

length(&this) -> i64;

The number of values in the set.

is_empty(&this) -> boolean;

True when the set holds no values.

contains(&this, value: &T) -> boolean where T: Ord;

True when value is a member.

insert(mut &this, value: T) -> boolean where T: Ord;

Add value. Returns true if it was not already present; a value already present is kept and value is released. Panics on allocation failure.

try_insert(mut &this, value: T) -> Result<boolean, AllocationError> where T: Ord;

insert that returns Err(AllocationError) instead of panicking when a node cannot be allocated.

remove(mut &this, value: &T) -> boolean where T: Ord;

Remove value. Returns true if it was present.

first(&this) -> Option<T*>;

The smallest value, or None when empty.

last(&this) -> Option<T*>;

The greatest value, or None when empty.

pop_first(mut &this) -> Option<T> where T: Ord;

Remove and return the smallest value, or None when empty.

pop_last(mut &this) -> Option<T> where T: Ord;

Remove and return the greatest value, or None when empty.

clear(mut &this) -> void;

Release every value.

iter(&this) -> implement Iterator<T> + DoubleEndedIterator where T: Copy;

Every value by value, in ascending order. Gated on T: Copy: the values are bit copies of the stored ones. iterate_references walks any set.

iterate_references(&this) -> implement Iterator<T*> + DoubleEndedIterator;

Every value by borrow, in ascending order.

range<R>(&this, bounds: R) -> implement Iterator<T*> + DoubleEndedIterator where T: Ord, R: RangeBounds<T>;

The values in bounds, by borrow, in ascending order and from either end: set.range(low..high), set.range(low..=high), set.range(..high), set.range(..), with bounds of the value type.

Trait implementations

implement<T> trait Clone for struct BTreeSet<T, GlobalAllocator> where T: Ord + Clone
implement<T> trait BitOr<BTreeSet<T, GlobalAllocator>, BTreeSet<T, GlobalAllocator>> for struct BTreeSet<T, GlobalAllocator> where T: Ord + Clone
implement<T> trait BitAnd<BTreeSet<T, GlobalAllocator>, BTreeSet<T, GlobalAllocator>> for struct BTreeSet<T, GlobalAllocator> where T: Ord + Clone
implement<T> trait Sub<BTreeSet<T, GlobalAllocator>, BTreeSet<T, GlobalAllocator>> for struct BTreeSet<T, GlobalAllocator> where T: Ord + Clone
implement<T> trait BitXor<BTreeSet<T, GlobalAllocator>, BTreeSet<T, GlobalAllocator>> for struct BTreeSet<T, GlobalAllocator> where T: Ord + Clone
implement<T> trait Default for struct BTreeSet<T, GlobalAllocator>
implement<T> trait FromIterator<T> for struct BTreeSet<T, GlobalAllocator> where T: Ord
implement<T, A> trait Iterable for struct BTreeSet<T, A> where T: Copy, A: Allocator
implement<T, A> trait Display for struct BTreeSet<T, A> where T: Display, A: Allocator
std::fmt::display
implement<T, A> trait Debug for struct BTreeSet<T, A> where T: Debug, A: Allocator
std::fmt::display