Struct sorted_list::SortedList
[−]
[src]
pub struct SortedList<K: Ord, V: PartialEq> { /* fields omitted */ }
SortedList
stores multiple (K, V)
tuples ordered by K, then in the order of insertion for V
.
Implmented using two Vec
this should be fast for in-order inserts and quite bad in the
worst-case of reverse insertion order.
Example
use sorted_list::SortedList; let mut list: SortedList<u32, u8> = SortedList::new(); list.insert(0, 0); list.insert(1, 1); list.insert(0, 2); assert_eq!( list.iter().collect::<Vec<_>>(), vec![(&0, &0), (&0, &2), (&1, &1)]);
Methods
impl<K: Ord, V: PartialEq> SortedList<K, V>
[src]
fn new() -> Self
Creates a new as small as possible SortedList
fn len(&self) -> usize
Returns the number of tuples
fn insert(&mut self, key: K, value: V) -> bool
Returns true
if the (key, value)
did not exist in the sorted list before and it exists now,
false
otherwise.
fn values_of(&self, key: &K) -> &[V]
Returns the values of a specific key as a slice
fn iter(&self) -> Tuples<K, V>
Iterate all stored tuples, keys in order, values in insertion order
fn keys(&self) -> Iter<K>
Iterate over all keys, can contain duplicates
fn values(&self) -> Iter<V>
Iterate over all values
fn first_value_of(&self, key: &K) -> Option<&V>
Returns the first (in insertion order) value of key
fn last_value_of(&self, key: &K) -> Option<&V>
Returns the last (in insertion order) value of key
Trait Implementations
impl<K: Ord + Clone, V: PartialEq + Clone> Clone for SortedList<K, V>
[src]
fn clone(&self) -> Self
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl<K: Ord, V: PartialEq> IntoIterator for SortedList<K, V>
[src]
type Item = (K, V)
The type of the elements being iterated over.
type IntoIter = IntoTuples<K, V>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
Creates an iterator from a value. Read more
impl<K: Clone + Ord, V: PartialEq> Extend<(K, V)> for SortedList<K, V>
[src]
fn extend<T>(&mut self, iter: T) where
T: IntoIterator<Item = (K, V)>,
T: IntoIterator<Item = (K, V)>,
Extends a collection with the contents of an iterator. Read more