Struct indextreemap::IndexTreeMap
source · pub struct IndexTreeMap<K, V> {
pub root: Box<Node<K, V>>,
pub size: usize,
}Fields§
§root: Box<Node<K, V>>§size: usizeImplementations§
source§impl<K: Key, V: Value> IndexTreeMap<K, V>
impl<K: Key, V: Value> IndexTreeMap<K, V>
sourcepub fn contains_key(&self, key: &K) -> bool
pub fn contains_key(&self, key: &K) -> bool
Returns true if the map contains a value for the specified key.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.
Example
Basic usage:
use indextreemap::IndexTreeMap;
let mut tree = IndexTreeMap::new();
tree.insert(1, "a".to_string());
assert_eq!(tree.contains_key(&1), true);
assert_eq!(tree.contains_key(&2), false);sourcepub fn contains_index(&self, index: usize) -> bool
pub fn contains_index(&self, index: usize) -> bool
Returns true if the map contains an item in the index position.
Example
Basic usage:
use indextreemap::IndexTreeMap;
let mut tree = IndexTreeMap::new();
tree.insert(1, "a".to_string());
assert_eq!(tree.contains_index(0), true);
assert_eq!(tree.contains_index(1), false);source§impl<K: Key, V: Value> IndexTreeMap<K, V>
impl<K: Key, V: Value> IndexTreeMap<K, V>
sourcepub fn get(&self, key: &K) -> Option<&V>
pub fn get(&self, key: &K) -> Option<&V>
Returns a reference to the value corresponding to the key.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.
Example
Basic usage:
use indextreemap::IndexTreeMap;
let mut tree = IndexTreeMap::new();
tree.insert(1, "a".to_string());
assert_eq!(tree.get(&1), Some(&"a".to_string()));
assert_eq!(tree.get(&2), None);sourcepub fn get_key_value(&self, key: &K) -> (Option<&K>, Option<&V>)
pub fn get_key_value(&self, key: &K) -> (Option<&K>, Option<&V>)
Returns the key-value pair corresponding to the supplied key.
The supplied key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.
Example
Basic usage:
use indextreemap::IndexTreeMap;
let mut tree = IndexTreeMap::new();
tree.insert(1, "a".to_string());
assert_eq!(tree.get_key_value(&1), (Some(&1), Some(&"a".to_string())));
assert_eq!(tree.get_key_value(&2), (None, None));sourcepub fn get_from_index(&self, id: usize) -> Option<&V>
pub fn get_from_index(&self, id: usize) -> Option<&V>
Returns a reference to the value corresponding to the index.
Example
Basic usage:
use indextreemap::IndexTreeMap;
let mut tree = IndexTreeMap::new();
tree.insert(1, "a".to_string());
assert_eq!(tree.get_from_index(0), Some(&"a".to_string()));
assert_eq!(tree.get_from_index(1), None);sourcepub fn get_key_from_index(&self, id: usize) -> Option<&K>
pub fn get_key_from_index(&self, id: usize) -> Option<&K>
Returns a reference to the key corresponding to the index.
Example
Basic usage:
use indextreemap::IndexTreeMap;
let mut tree = IndexTreeMap::new();
tree.insert(1, "a".to_string());
assert_eq!(tree.get_key_from_index(0), Some(&1));
assert_eq!(tree.get_key_from_index(1), None);sourcepub fn get_key_value_from_index(&self, id: usize) -> (Option<&K>, Option<&V>)
pub fn get_key_value_from_index(&self, id: usize) -> (Option<&K>, Option<&V>)
Returns a reference to the key-value pair corresponding to the index.
Example
Basic usage:
use indextreemap::IndexTreeMap;
let mut tree = IndexTreeMap::new();
tree.insert(1, "a".to_string());
assert_eq!(tree.get_key_value_from_index(0), (Some(&1), Some(&"a".to_string())));
assert_eq!(tree.get_key_value_from_index(1), (None, None));sourcepub fn get_first_key(&self) -> Option<&K>
pub fn get_first_key(&self) -> Option<&K>
Returns a reference to the first key in the map.
Example
Basic usage:
use indextreemap::IndexTreeMap;
let mut tree = IndexTreeMap::new();
tree.insert(1, "a".to_string());
assert_eq!(tree.get_first_key(), Some(&1));sourcepub fn get_first_value(&self) -> Option<&V>
pub fn get_first_value(&self) -> Option<&V>
Returns a reference to the first value in the map.
Example
Basic usage:
use indextreemap::IndexTreeMap;
let mut tree = IndexTreeMap::new();
tree.insert(1, "a".to_string());
assert_eq!(tree.get_first_value(), Some(&"a".to_string()));sourcepub fn get_first_key_value(&self) -> (Option<&K>, Option<&V>)
pub fn get_first_key_value(&self) -> (Option<&K>, Option<&V>)
Returns a reference to the first key-value pair in the map.
Example
Basic usage:
use indextreemap::IndexTreeMap;
let mut tree = IndexTreeMap::new();
tree.insert(1, "a".to_string());
assert_eq!(tree.get_first_key_value(), (Some(&1),Some(&"a".to_string())));sourcepub fn get_last_key(&self) -> Option<&K>
pub fn get_last_key(&self) -> Option<&K>
Returns a reference to the last key in the map.
Example
Basic usage:
use indextreemap::IndexTreeMap;
let mut tree = IndexTreeMap::new();
tree.insert(1, "a".to_string());
tree.insert(2, "b".to_string());
assert_eq!(tree.get_last_key(), Some(&2));sourcepub fn get_last_value(&self) -> Option<&V>
pub fn get_last_value(&self) -> Option<&V>
Returns a reference to the first value in the map.
Example
Basic usage:
use indextreemap::IndexTreeMap;
let mut tree = IndexTreeMap::new();
tree.insert(1, "a".to_string());
tree.insert(2, "b".to_string());
assert_eq!(tree.get_last_value(), Some(&"b".to_string()));sourcepub fn get_last_key_value(&self) -> (Option<&K>, Option<&V>)
pub fn get_last_key_value(&self) -> (Option<&K>, Option<&V>)
Returns a reference to the last key-value pair in the map.
Example
Basic usage:
use indextreemap::IndexTreeMap;
let mut tree = IndexTreeMap::new();
tree.insert(1, "a".to_string());
tree.insert(2, "b".to_string());
assert_eq!(tree.get_last_key_value(), (Some(&2),Some(&"b".to_string())));source§impl<K: Key, V: Value> IndexTreeMap<K, V>
impl<K: Key, V: Value> IndexTreeMap<K, V>
sourcepub fn iter(&self) -> IndexTreeIterator<'_, K, V> ⓘ
pub fn iter(&self) -> IndexTreeIterator<'_, K, V> ⓘ
Gets an iterator over the entries of the map, sorted by key.
Example
Basic usage:
use std::collections::BTreeMap;
let mut map = BTreeMap::new();
map.insert(3, "c");
map.insert(2, "b");
map.insert(1, "a");
for (key, value) in map.iter() {
println!("{key}: {value}");
}
let (first_key, first_value) = map.iter().next().unwrap();
assert_eq!((*first_key, *first_value), (1, "a"));source§impl<K: Key, V: Value> IndexTreeMap<K, V>
impl<K: Key, V: Value> IndexTreeMap<K, V>
sourcepub fn remove(&mut self, key: &K) -> (Option<K>, Option<V>)
pub fn remove(&mut self, key: &K) -> (Option<K>, Option<V>)
Removes an item from the map from it’s corresponding key, returning the key-value pair was previously in the map.
Example
Basic usage:
use indextreemap::IndexTreeMap;
let mut tree = IndexTreeMap::new();
tree.insert(1, "a".to_string());
assert_eq!(tree.remove(&1), (Some(1), Some("a".to_string())));
assert_eq!(tree.remove(&2), (None, None));sourcepub fn remove_from_index(&mut self, index: usize) -> (Option<K>, Option<V>)
pub fn remove_from_index(&mut self, index: usize) -> (Option<K>, Option<V>)
Removes an item from the map from it’s corresponding index, returning the key-value pair was previously in the map.
Example
Basic usage:
use indextreemap::IndexTreeMap;
let mut tree = IndexTreeMap::new();
tree.insert(1, "a".to_string());
assert_eq!(tree.remove_from_index(0), (Some(1), Some("a".to_string())));
assert_eq!(tree.remove_from_index(1), (None, None));source§impl<K: Key, V: Value> IndexTreeMap<K, V>
impl<K: Key, V: Value> IndexTreeMap<K, V>
sourcepub fn replace(&mut self, key: K, value: V)
pub fn replace(&mut self, key: K, value: V)
Replaces an item from the map from it’s corresponding key, returning the key-value pair was previously in the map.
Example
Basic usage:
use indextreemap::IndexTreeMap;
let mut tree = IndexTreeMap::new();
tree.insert(1, "a".to_string());
tree.replace(1, "b".to_string());
assert_eq!(tree.get(&1), Some(&"b".to_string()));sourcepub fn replace_index(&mut self, index: usize, value: V)
pub fn replace_index(&mut self, index: usize, value: V)
Replaces an item from the map from it’s corresponding index, returning the key-value pair was previously in the map.
Example
Basic usage:
use indextreemap::IndexTreeMap;
let mut tree = IndexTreeMap::new();
tree.insert(1, "a".to_string());
tree.replace_index(0, "b".to_string());
assert_eq!(tree.get(&1), Some(&"b".to_string()));source§impl<K: Key, V: Value> IndexTreeMap<K, V>
impl<K: Key, V: Value> IndexTreeMap<K, V>
sourcepub fn new() -> IndexTreeMap<K, V>
pub fn new() -> IndexTreeMap<K, V>
Makes a new, empty IndexTreeMap.
Does not allocate anything on its own.
Example
Basic usage:
use indextreemap::IndexTreeMap;
let mut map = IndexTreeMap::new();
map.insert(1, "a".to_string());sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the map, removing all elements.
Does not allocate anything on its own.
Example
Basic usage:
use indextreemap::IndexTreeMap;
let mut map = IndexTreeMap::new();
map.insert(1, "a".to_string());
map.clear();
assert!(map.is_empty());Trait Implementations§
source§impl<K: Clone, V: Clone> Clone for IndexTreeMap<K, V>
impl<K: Clone, V: Clone> Clone for IndexTreeMap<K, V>
source§fn clone(&self) -> IndexTreeMap<K, V>
fn clone(&self) -> IndexTreeMap<K, V>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl<K: Default, V: Default> Default for IndexTreeMap<K, V>
impl<K: Default, V: Default> Default for IndexTreeMap<K, V>
source§fn default() -> IndexTreeMap<K, V>
fn default() -> IndexTreeMap<K, V>
source§impl<K: Key, V: Value> IntoIterator for IndexTreeMap<K, V>
impl<K: Key, V: Value> IntoIterator for IndexTreeMap<K, V>
source§fn into_iter(self) -> Self::IntoIter
fn into_iter(self) -> Self::IntoIter
Creates a consuming iterator visiting all the keys, in sorted order. The map cannot be used after calling this.
Example
Basic usage:
use std::collections::BTreeMap;
let mut map = BTreeMap::new();
map.insert(2, "b");
map.insert(1, "a");
let items: Vec<(i32, &str)> = map.into_iter().collect();
assert_eq!(items, [(1, "a"), (2, "b")]);