Wado

core:collections

Maps and sets that iterate in insertion order. TreeMap<K, V> and TreeSet<T> find a key by ordering it; HashMap<K, V> and HashSet<T> by hashing it under a HashSeed. map[key] = value overwrites; try_insert / get_or_insert insert only when the key is absent.

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);

let mut seen = HashSet::<String>::new();
assert seen.insert("b");
assert seen.insert("a");
assert !seen.insert("b");
assert seen.iter_value().collect() == ["b", "a"];

Structs

pub struct MapKeysRefIter<K, V>

A map's keys, or a set's elements, by reference.

Fields are private.

pub fn iter_value(&self) -> MapKeysValueIter<K, V>

impl Iterator for MapKeysRefIter<K, V>

fn next(&mut self) -> Option<&K>

pub struct MapKeysValueIter<K, V>

A map's keys, or a set's elements, by value.

Fields are private.

impl Iterator for MapKeysValueIter<K, V>

fn next(&mut self) -> Option<K>

pub struct MapValuesRefIter<K, V>

A map's values, by reference.

Fields are private.

pub fn iter_value(&self) -> MapValuesValueIter<K, V>

impl Iterator for MapValuesRefIter<K, V>

fn next(&mut self) -> Option<&V>

pub struct MapValuesValueIter<K, V>

A map's values, by value. The doubled word is the axis meeting a projection already named values.

Fields are private.

impl Iterator for MapValuesValueIter<K, V>

fn next(&mut self) -> Option<V>

pub struct MapEntriesRefIter<K, V>

A map's key-value pairs, by reference.

Fields are private.

pub fn iter_value(&self) -> MapEntriesValueIter<K, V>

impl Iterator for MapEntriesRefIter<K, V>

fn next(&mut self) -> Option<[&K, &V]>

#[compiler_item("map_entries_iter_next")]

pub struct MapEntriesValueIter<K, V>

A map's key-value pairs, by value.

Fields are private.

impl Iterator for MapEntriesValueIter<K, V>

fn next(&mut self) -> Option<[K, V]>

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>

#[compiler_item("tree_map_new")]

Creates a new empty TreeMap.

pub fn len(&self) -> i32

#[compiler_item("tree_map_len")]

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 try_insert(&mut self, key: K, value: V) -> bool

Inserts only if key is absent, and reports whether it was inserted. The losing insert keeps the existing value, unlike map[key] = value.

pub fn get_or_insert(&mut self, key: K, value: V) -> V

The value already stored under key, or value inserted and returned. The shape of TC39's Map.prototype.getOrInsert; for whether it inserted, use try_insert.

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) -> MapKeysRefIter<K, V>

The keys, in insertion order. A map traversal yields references and carries no axis suffix: keys already says what it yields, and a caller wanting owned keys takes iter_value() off the result.

pub fn values(&self) -> MapValuesRefIter<K, V>

The values, in insertion order.

pub fn entries(&self) -> MapEntriesRefIter<K, V>

#[compiler_item("tree_map_entries")]

The key-value pairs, in insertion order.

pub fn clear(&mut self)

Removes all key-value pairs from the map.

pub fn get_str<S: AsStrSlice>(&self, key: S) -> Option<V>

Returns the value stored under text equal to key, or null.

pub fn contains_key_str<S: AsStrSlice>(&self, key: S) -> bool

Returns true if some key spells the same text as key.

pub fn get_ref_str<S: AsStrSlice>(&self, key: S) -> Option<&V>

Returns a reference to the value stored under text equal to key.

impl Eq for TreeMap<K, V>

fn eq(&self, other: &TreeMap<K, V>) -> bool

impl Ord for TreeMap<K, V>

fn cmp(&self, other: &TreeMap<K, V>) -> Ordering

impl IndexAssign<K> for TreeMap<K, V>

fn index_assign(&mut self, key: K, value: Self::Output)

#[compiler_item("tree_map_index_assign")]

impl IndexValue<K> for TreeMap<K, V>

fn index_value(&self, key: K) -> Self::Output

impl IndexRef<K> for TreeMap<K, V>

fn index_ref(&self, key: K) -> &V

impl IndexRefMut<K> for TreeMap<K, V>

fn index_ref_mut(&mut self, key: K) -> &mut V

impl From<Array<[String, V]>> for TreeMap<String, V>

fn from(entries: Array<[String, V]>) -> TreeMap<String, V>

impl LiteralSpread for TreeMap<String, V>

fn spread_literal(&mut self, base: TreeMap<String, V>)

impl Serialize for TreeMap<K, V>

fn serialize<S: Serializer>(&self, s: &mut S) -> Result<(), SerializeError>

impl Deserialize for TreeMap<K, V>

fn deserialize<D: Deserializer>(d: &mut D) -> Result<TreeMap<K, V>, DeserializeError>

impl Inspect for TreeMap<K, V>

pub fn inspect(&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 keeps a B-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

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_ref(&self) -> MapKeysRefIter<T, ()>

The elements, in insertion order.

pub fn iter_value(&self) -> MapKeysValueIter<T, ()>

The elements, in insertion order.

pub fn contains_str<S: AsStrSlice>(&self, value: S) -> bool

Returns true if some element spells the same text as value.

impl IntoIterator for TreeSet<T>

fn into_iter(&self) -> MapKeysValueIter<T, ()>

impl From<Array<T>> for TreeSet<T>

fn from(elements: Array<T>) -> TreeSet<T>

impl Serialize for TreeSet<T>

fn serialize<S: Serializer>(&self, s: &mut S) -> Result<(), SerializeError>

impl Deserialize for TreeSet<T>

fn deserialize<D: Deserializer>(d: &mut D) -> Result<TreeSet<T>, DeserializeError>

impl Inspect for TreeSet<T>

pub fn inspect(&self, f: &mut Formatter)

impl Default for TreeSet<T>

pub fn default() -> TreeSet<T>

pub struct HashSeed

The key to a HashMap's hash function. A seed nobody outside the program can predict keeps keys an attacker chooses from colliding.

Fields are private.

pub fn fixed(k0: u64, k1: u64) -> HashSeed

A seed of the caller's choosing, for a map whose keys the program trusts and whose hashing must be the same on every run.

pub struct HashMap<K, V>

A map that iterates in insertion order, found by hashing its keys.

Its hash function is keyed by a HashSeed: the host's under new(), which holds up against keys an attacker chooses, or the caller's under with_seed.

Fields are private.

pub fn new() -> HashMap<K, V>

An empty map hashing under the host's seed.

pub fn with_seed(seed: HashSeed) -> HashMap<K, V>

An empty map hashing with seed.

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 try_insert(&mut self, key: K, value: V) -> bool

Inserts only if key is absent, and reports whether it was inserted. The losing insert keeps the existing value, unlike map[key] = value.

pub fn get_or_insert(&mut self, key: K, value: V) -> V

The value already stored under key, or value inserted and returned.

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) -> MapKeysRefIter<K, V>

The keys, in insertion order.

pub fn values(&self) -> MapValuesRefIter<K, V>

The values, in insertion order.

pub fn entries(&self) -> MapEntriesRefIter<K, V>

The key-value pairs, in insertion order.

pub fn clear(&mut self)

Removes all key-value pairs from the map. The seed stays.

pub fn get_str<S: AsStrSlice>(&self, key: S) -> Option<V>

Returns the value stored under text equal to key, or null.

pub fn contains_key_str<S: AsStrSlice>(&self, key: S) -> bool

Returns true if some key spells the same text as key.

pub fn get_ref_str<S: AsStrSlice>(&self, key: S) -> Option<&V>

Returns a reference to the value stored under text equal to key.

impl Eq for HashMap<K, V>

fn eq(&self, other: &HashMap<K, V>) -> bool

impl Ord for HashMap<K, V>

fn cmp(&self, other: &HashMap<K, V>) -> Ordering

impl Inspect for HashMap<K, V>

fn inspect(&self, f: &mut Formatter)

impl IndexAssign<K> for HashMap<K, V>

fn index_assign(&mut self, key: K, value: Self::Output)

impl IndexValue<K> for HashMap<K, V>

fn index_value(&self, key: K) -> Self::Output

impl IndexRef<K> for HashMap<K, V>

fn index_ref(&self, key: K) -> &V

impl IndexRefMut<K> for HashMap<K, V>

fn index_ref_mut(&mut self, key: K) -> &mut V

impl From<Array<[String, V]>> for HashMap<String, V>

fn from(entries: Array<[String, V]>) -> HashMap<String, V>

impl LiteralSpread for HashMap<String, V>

fn spread_literal(&mut self, base: HashMap<String, V>)

impl Default for HashMap<K, V>

fn default() -> HashMap<K, V>

impl Serialize for HashMap<K, V>

fn serialize<S: Serializer>(&self, s: &mut S) -> Result<(), SerializeError>

impl Deserialize for HashMap<K, V>

fn deserialize<D: Deserializer>(d: &mut D) -> Result<HashMap<K, V>, DeserializeError>

pub struct HashSet<T>

A set that iterates in insertion order, found by hashing its elements.

Fields are private.

pub fn new() -> HashSet<T>

An empty set hashing under the host's seed.

pub fn with_seed(seed: HashSeed) -> HashSet<T>

An empty set hashing with seed.

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

Inserts a value, and reports whether it was absent.

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, and reports whether it was present.

pub fn clear(&mut self)

Removes all elements from the set.

pub fn iter_ref(&self) -> MapKeysRefIter<T, ()>

The elements, in insertion order.

pub fn iter_value(&self) -> MapKeysValueIter<T, ()>

The elements, in insertion order.

pub fn contains_str<S: AsStrSlice>(&self, value: S) -> bool

Returns true if some element spells the same text as value.

impl Inspect for HashSet<T>

fn inspect(&self, f: &mut Formatter)

impl IntoIterator for HashSet<T>

fn into_iter(&self) -> MapKeysValueIter<T, ()>

impl From<Array<T>> for HashSet<T>

fn from(elements: Array<T>) -> HashSet<T>

impl Default for HashSet<T>

fn default() -> HashSet<T>

impl Serialize for HashSet<T>

fn serialize<S: Serializer>(&self, s: &mut S) -> Result<(), SerializeError>

impl Deserialize for HashSet<T>

fn deserialize<D: Deserializer>(d: &mut D) -> Result<HashSet<T>, DeserializeError>