core:collections
Collection types: TreeMap<K, V> and TreeSet<T>, both iterating in
insertion order. TreeMap has no insert method — write map[key] = value
or build one from a { key: value, ... } literal. TreeSet has insert.
Synopsis
let mut sizes = { small: 1, medium: 2, large: 3 } as TreeMap<String, i32>;
assert sizes.len() == 3;
assert sizes["medium"] == 2;
assert sizes.get("small") matches { Some(v) && v == 1 };
sizes["xlarge"] = 4;
assert sizes.len() == 4;
let primes = [7, 2, 5, 2, 3] as TreeSet<i32>;
assert primes.len() == 4;
assert primes.contains(5);
assert !primes.contains(4);
Structs
pub struct TreeMap<K, V>
A map that iterates in insertion order.
Keys are stored in a tree for O(log n) lookups, while key-value pairs are stored in a dense array for fast, insertion-order iteration.
This is similar to Rust's indexmap::IndexMap but uses a tree instead
of a hash table for key lookups.
Fields are private.
pub fn new() -> TreeMap<K, V>
Creates a new empty TreeMap.
pub fn len(&self) -> i32
Returns the number of key-value pairs in the map.
pub fn is_empty(&self) -> bool
Returns true if the map contains no elements.
pub fn contains_key(&self, key: K) -> bool
Returns true if the map contains a value for the specified key.
pub fn get(&self, key: K) -> Option<V>
Returns the value corresponding to the key, or null if not found.
pub fn remove(&mut self, key: K) -> bool
Removes a key from the map and returns true if the key was present. Preserves insertion order of remaining elements.
pub fn keys(&self) -> List<K>
Returns all keys in insertion order.
pub fn values(&self) -> List<V>
Returns all values in insertion order.
pub fn entries(&self) -> List<[K, V]>
Returns all key-value pairs in insertion order.
pub fn clear(&mut self)
Removes all key-value pairs from the map.
impl IndexAssign<K> for TreeMap<K, V>
fn index_assign(&mut self, key: K, value: Self::Input)
impl IndexValue<K> for TreeMap<K, V>
fn index_value(&self, key: K) -> Self::Output
impl KeyValueLiteralBuilder for TreeMap<String, V>
fn new_literal(capacity: i32) -> TreeMap<String, V>
fn insert_literal(&mut self, key: String, value: Self::Value) with stores[value]
fn insert_all(&mut self, base: TreeMap<String, V>)
fn build(&self) -> TreeMap<String, V>
impl Serialize for TreeMap<String, V>
fn serialize<S: Serializer>(&self, s: &mut S) -> Result<(), SerializeError>
impl Deserialize for TreeMap<String, V>
fn deserialize<D: Deserializer>(d: &mut D) -> Result<TreeMap<String, V>, DeserializeError>
impl Inspect for TreeMap<K, V>
pub fn inspect(&self, f: &mut Formatter)
impl InspectAlt for TreeMap<K, V>
pub fn inspect_alt(&self, f: &mut Formatter)
impl Default for TreeMap<K, V>
pub fn default() -> TreeMap<K, V>
pub struct TreeSet<T>
A set that iterates in insertion order.
Backed by a TreeMap<T, ()> which uses a balanced binary search tree for
O(log n) membership tests and a dense array for O(1) insertion-order iteration.
Duplicate inserts are silently ignored (preserving the original position). Removing an element and re-inserting it appends it at the end.
T must implement Ord to use any of the methods.
Fields are private.
pub fn new() -> TreeSet<T>
Creates a new empty TreeSet.
pub fn len(&self) -> i32
Returns the number of elements in the set.
pub fn is_empty(&self) -> bool
Returns true if the set contains no elements.
pub fn insert(&mut self, value: T) -> bool with stores[value]
Inserts a value into the set.
Returns true if the value was newly inserted, false if it was already present.
pub fn contains(&self, value: T) -> bool
Returns true if the set contains the given value.
pub fn remove(&mut self, value: T) -> bool
Removes a value from the set.
Returns true if the value was present, false otherwise.
pub fn clear(&mut self)
Removes all elements from the set.
pub fn iter(&self) -> TreeSetIter<T>
Returns an iterator over the elements in insertion order.
