pub struct IndexTreeMap<K, V> {
    pub root: Box<Node<K, V>>,
    pub size: usize,
}

Fields§

§root: Box<Node<K, V>>§size: usize

Implementations§

source§

impl<K: Key, V: Value> IndexTreeMap<K, V>

source

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

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>

source

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

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

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

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

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

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

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

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

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

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

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>

source

pub fn insert(&mut self, key: K, value: V)

source§

impl<K: Key, V: Value> IndexTreeMap<K, V>

source

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>

source

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

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>

source

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

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>

source

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

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

pub fn len(&self) -> usize

Clears the map, removing all elements.

Example

Basic usage:

use indextreemap::IndexTreeMap;

let mut map = IndexTreeMap::new();

map.insert(1, "a".to_string());
assert_eq!(map.len(), 1);
source

pub fn is_empty(&self) -> bool

Returns true if the map contains no elements.

Example

Basic usage:

use indextreemap::IndexTreeMap;

let mut map = IndexTreeMap::new();
assert!(map.is_empty());
map.insert(1, "a".to_string());
assert!(!map.is_empty());

Trait Implementations§

source§

impl<K: Clone, V: Clone> Clone for IndexTreeMap<K, V>

source§

fn clone(&self) -> IndexTreeMap<K, V>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<K: Debug, V: Debug> Debug for IndexTreeMap<K, V>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<K: Default, V: Default> Default for IndexTreeMap<K, V>

source§

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

Returns the “default value” for a type. Read more
source§

impl<K: Key, V: Value> Display for IndexTreeMap<K, V>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<K: Key, V: Value> IntoIterator for IndexTreeMap<K, V>

source§

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")]);
§

type Item = (Option<K>, Option<V>)

The type of the elements being iterated over.
§

type IntoIter = IndexTreeIntoIterator<K, V>

Which kind of iterator are we turning this into?

Auto Trait Implementations§

§

impl<K, V> RefUnwindSafe for IndexTreeMap<K, V>where K: RefUnwindSafe, V: RefUnwindSafe,

§

impl<K, V> Send for IndexTreeMap<K, V>where K: Send, V: Send,

§

impl<K, V> Sync for IndexTreeMap<K, V>where K: Sync, V: Sync,

§

impl<K, V> Unpin for IndexTreeMap<K, V>

§

impl<K, V> UnwindSafe for IndexTreeMap<K, V>where K: UnwindSafe, V: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.