Struct index_map::IndexMap [−][src]
A map of usize
to value, which allows efficient O(1) inserts, O(1) indexing and O(1) removal.
See crate level documentation for more information.
Implementations
impl<T> IndexMap<T>
[src]
pub fn keys(&self) -> Keys<'_, T>ⓘ
[src]
An iterator visiting all keys in ascending order.
The iterator element type is usize
.
Examples
use index_map::IndexMap; let mut map = IndexMap::new(); map.insert("a"); map.insert("b"); map.insert("c"); for key in map.keys() { println!("{}", key); }
pub fn values(&self) -> Values<'_, T>ⓘ
[src]
An iterator visiting all values in ascending order of their keys.
The iterator element type is &T
.
Examples
use index_map::IndexMap; let mut map = IndexMap::new(); map.insert("a"); map.insert("b"); map.insert("c"); for val in map.values() { println!("{}", val); }
pub fn values_mut(&mut self) -> ValuesMut<'_, T>ⓘ
[src]
An iterator visiting all values mutably in ascending order of their keys.
The iterator element type is &mut T
.
Examples
use index_map::IndexMap; let mut map = IndexMap::new(); map.insert(2); map.insert(4); map.insert(6); for val in map.values_mut() { *val *= 2; } for val in map.values() { println!("{}", val); }
pub fn iter(&self) -> Iter<'_, T>ⓘ
[src]
An iterator visiting all key-value pairs in ascending order of keys.
The iterator element type is (usize, &T)
.
Examples
use index_map::IndexMap; let mut map = IndexMap::new(); map.insert("a"); map.insert("b"); map.insert("c"); for (key, val) in map.iter() { println!("key: {} val: {}", key, val); }
pub fn iter_mut(&mut self) -> IterMut<'_, T>ⓘ
[src]
An iterator visiting all key-value pairs in ascending order of keys, with mutable references
to the values.
The iterator element type is (usize, &mut T)
.
Examples
use index_map::IndexMap; let mut map = IndexMap::new(); map.insert(2); map.insert(4); map.insert(6); // Update all values for (_, val) in map.iter_mut() { *val *= 2; } for (key, val) in map.iter() { println!("key: {} val: {}", key, val); }
pub fn drain(&mut self) -> Drain<'_, T>ⓘ
[src]
Clears the map, returning all key-value pairs as an iterator. Keeps the allocated memory for reuse.
Examples
use index_map::IndexMap; let mut a = IndexMap::new(); a.insert("a"); a.insert("b"); let mut iter = a.drain(); assert_eq!(iter.next(), Some((0, "a"))); assert_eq!(iter.next(), Some((1, "b"))); assert_eq!(iter.next(), None); assert!(a.is_empty());
impl<T> IndexMap<T>
[src]
pub fn new() -> Self
[src]
Creates a new IndexMap
.
It initially has a capacity of 0, and won't allocate until first inserted into.
Examples
use index_map::IndexMap; let mut map: IndexMap<&str> = IndexMap::new();
pub fn with_capacity(capacity: usize) -> Self
[src]
Creates an empty IndexMap
with the specified capacity.
The map will be able to hold at least capacity elements without reallocating. If capacity is 0, the map will not allocate.
Examples
use index_map::IndexMap; let mut map: IndexMap<&str> = IndexMap::with_capacity(10);
pub fn capacity(&self) -> usize
[src]
Returns the number of elements map can hold without reallocating.
Examples
use index_map::IndexMap; let mut map: IndexMap<&str> = IndexMap::with_capacity(10); assert!(map.capacity() >= 10);
pub fn len(&self) -> usize
[src]
Returns the number of elements present in the map.
Examples
use index_map::IndexMap; let mut map = IndexMap::new(); assert_eq!(map.len(), 0); map.insert("a"); assert_eq!(map.len(), 1);
pub fn is_empty(&self) -> bool
[src]
Returns true
if the map is empty.
Examples
use index_map::IndexMap; let mut map = IndexMap::new(); assert!(map.is_empty()); map.insert("a"); assert!(!map.is_empty());
pub fn clear(&mut self)
[src]
Clears the map, dropping all key-value pairs. Keeps the allocated memory for reuse.
Examples
use index_map::IndexMap; let mut map = IndexMap::new(); map.insert("a"); map.clear(); assert!(map.is_empty());
pub fn reserve(&mut self, additional: usize)
[src]
Reserves capacity for at least additional more elements to be inserted in the IndexMap
The collection may reserve more space to avoid frequent reallocations.
Panics
Panics if the new capacity exceeds isize::MAX
bytes.
Examples
use index_map::IndexMap; let mut map: IndexMap<&str> = IndexMap::new(); map.reserve(10); assert!(map.capacity() >= 10);
pub fn shrink_to_fit(&mut self)
[src]
Shrinks the capacity of the map as much as possible. It will drop down as much as possible while maintaining the internal rules and possibly leaving some space to keep keys valid.
Examples
use index_map::IndexMap; let mut map = IndexMap::with_capacity(100); map.insert("a"); map.insert("b"); assert!(map.capacity() >= 100); map.shrink_to_fit(); assert!(map.capacity() >= 2);
pub fn contains_key(&self, index: usize) -> bool
[src]
Returns true
if the map contains a value for the specified key.
Examples
use index_map::IndexMap; let mut map = IndexMap::new(); map.insert("a"); assert_eq!(map.contains_key(0), true); assert_eq!(map.contains_key(1), false);
pub fn insert(&mut self, value: T) -> usize
[src]
Inserts a value into the map, returning the generated key, for it.
Examples
use index_map::IndexMap; let mut map = IndexMap::new(); assert_eq!(map.insert("a"), 0); assert_eq!(map.is_empty(), false); let b = map.insert("b"); assert_eq!(map[b], "b");
pub fn remove(&mut self, index: usize) -> Option<T>
[src]
Removes a key from the map, returning the value at the key if the key was previously in the map.
Examples
use index_map::IndexMap; let mut map = IndexMap::new(); let a = map.insert("a"); assert_eq!(map.remove(a), Some("a")); assert_eq!(map.remove(a), None);
pub fn remove_entry(&mut self, index: usize) -> Option<(usize, T)>
[src]
Removes a key from the map, returning the key and value if the key was previously in the map.
Examples
use index_map::IndexMap; let mut map = IndexMap::new(); let a = map.insert("a"); assert_eq!(map.remove_entry(a), Some((0, "a"))); assert_eq!(map.remove(a), None);
pub fn get(&self, index: usize) -> Option<&T>
[src]
Returns a reference to the value corresponding to the key.
Examples
use index_map::IndexMap; let mut map = IndexMap::new(); map.insert("a"); assert_eq!(map.get(0), Some(&"a")); assert_eq!(map.get(1), None);
pub fn get_key_value(&self, index: usize) -> Option<(usize, &T)>
[src]
Returns the key-value pair corresponding to the key.
Examples
use index_map::IndexMap; let mut map = IndexMap::new(); map.insert("a"); assert_eq!(map.get_key_value(0), Some((0, &"a"))); assert_eq!(map.get_key_value(1), None);
pub fn get_mut(&mut self, index: usize) -> Option<&mut T>
[src]
Returns a mutable reference to the value corresponding to the key.
Examples
use index_map::IndexMap; let mut map = IndexMap::new(); let a = map.insert("a"); if let Some(x) = map.get_mut(a) { *x = "b"; } assert_eq!(map[a], "b");
pub fn retain<P>(&mut self, mut predicate: P) where
P: FnMut(usize, &mut T) -> bool,
[src]
P: FnMut(usize, &mut T) -> bool,
Retains only the elements specified by the predicate.
In other words, remove all pairs (k, v)
such that f(k, &mut v)
returns false
.
Examples
use index_map::IndexMap; let mut map = IndexMap::new(); for i in 0..6 { map.insert(i*2); } map.retain(|k, _| k % 2 == 0); assert_eq!(map.len(), 3);
Trait Implementations
impl<T: Clone> Clone for IndexMap<T>
[src]
fn clone(&self) -> Self
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T: Debug> Debug for IndexMap<T>
[src]
impl<T> Default for IndexMap<T>
[src]
impl<T: Eq> Eq for IndexMap<T>
[src]
impl<T> Index<usize> for IndexMap<T>
[src]
type Output = T
The returned type after indexing.
fn index(&self, key: usize) -> &T
[src]
Returns a reference to the value corresponding to the supplied key.
Panics
Panics if the key is not present in the IndexMap
.
impl<T> IndexMut<usize> for IndexMap<T>
[src]
fn index_mut(&mut self, key: usize) -> &mut T
[src]
Returns a mutable reference to the value corresponding to the supplied key.
Panics
Panics if the key is not present in the IndexMap
.
impl<'a, T> IntoIterator for &'a IndexMap<T>
[src]
type Item = (usize, &'a T)
The type of the elements being iterated over.
type IntoIter = Iter<'a, T>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<'a, T> IntoIterator for &'a mut IndexMap<T>
[src]
type Item = (usize, &'a mut T)
The type of the elements being iterated over.
type IntoIter = IterMut<'a, T>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<T> IntoIterator for IndexMap<T>
[src]
type Item = (usize, T)
The type of the elements being iterated over.
type IntoIter = IntoIter<T>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<T: Ord> Ord for IndexMap<T>
[src]
fn cmp(&self, other: &IndexMap<T>) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl<T: PartialEq> PartialEq<IndexMap<T>> for IndexMap<T>
[src]
impl<T: PartialOrd> PartialOrd<IndexMap<T>> for IndexMap<T>
[src]
fn partial_cmp(&self, other: &IndexMap<T>) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<T> StructuralEq for IndexMap<T>
[src]
impl<T> StructuralPartialEq for IndexMap<T>
[src]
Auto Trait Implementations
impl<T> Send for IndexMap<T> where
T: Send,
[src]
T: Send,
impl<T> Sync for IndexMap<T> where
T: Sync,
[src]
T: Sync,
impl<T> Unpin for IndexMap<T> where
T: Unpin,
[src]
T: Unpin,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,