Struct litemap::LiteMap[][src]

pub struct LiteMap<K, V> { /* fields omitted */ }

A simple “flat” map based on a sorted vector

See the module level documentation for why one should use this.

The API is roughly similar to that of std::collections::HashMap, though it requires Ord instead of Hash.

Implementations

impl<K, V> LiteMap<K, V>[src]

pub fn new() -> Self[src]

Construct a new LiteMap

pub fn with_capacity(capacity: usize) -> Self[src]

Construct a new LiteMap with a given capacity

pub fn len(&self) -> usize[src]

The number of elements in the LiteMap

pub fn is_empty(&self) -> bool[src]

Whether the LiteMap is empty

pub fn clear(&mut self)[src]

Remove all elements from the LiteMap

pub fn reserve(&mut self, additional: usize)[src]

Reserve capacity for additional more elements to be inserted into the LiteMap to avoid frequent reallocations.

See Vec::reserve() for more information.

impl<K: Ord, V> LiteMap<K, V>[src]

pub fn get<Q: ?Sized>(&self, key: &Q) -> Option<&V> where
    K: Borrow<Q>,
    Q: Ord
[src]

Get the value associated with key, if it exists.

use litemap::LiteMap;

let mut map = LiteMap::new();
map.insert(1, "one");
map.insert(2, "two");
assert_eq!(map.get(&1), Some(&"one"));
assert_eq!(map.get(&3), None);

pub fn contains_key<Q: ?Sized>(&self, key: &Q) -> bool where
    K: Borrow<Q>,
    Q: Ord
[src]

Returns whether key is contained in this map

use litemap::LiteMap;

let mut map = LiteMap::new();
map.insert(1, "one");
map.insert(2, "two");
assert_eq!(map.contains_key(&1), true);
assert_eq!(map.contains_key(&3), false);

pub fn get_mut<Q: ?Sized>(&mut self, key: &Q) -> Option<&mut V> where
    K: Borrow<Q>,
    Q: Ord
[src]

Get the value associated with key, if it exists, as a mutable reference.

use litemap::LiteMap;

let mut map = LiteMap::new();
map.insert(1, "one");
map.insert(2, "two");
if let Some(mut v) = map.get_mut(&1) {
    *v = "uno";
}
assert_eq!(map.get(&1), Some(&"uno"));

#[must_use]
pub fn try_append(&mut self, key: K, value: V) -> Option<(K, V)>
[src]

Appends value with key to the end of the underlying vector, returning key and value if it failed. Useful for extending with an existing sorted list.

use litemap::LiteMap;

let mut map = LiteMap::new();
assert!(map.try_append(1, "uno").is_none());
assert!(map.try_append(3, "tres").is_none());

assert!(
    matches!(map.try_append(3, "tres-updated"), Some((3, "tres-updated"))),
    "append duplicate of last key",
);

assert!(
    matches!(map.try_append(2, "dos"), Some((2, "dos"))),
    "append out of order"
);

assert_eq!(map.get(&1), Some(&"uno"));

// contains the original value for the key: 3
assert_eq!(map.get(&3), Some(&"tres"));

// not appended since it wasn't in order
assert_eq!(map.get(&2), None);

pub fn insert(&mut self, key: K, value: V) -> Option<V>[src]

Insert value with key, returning the existing value if it exists.

use litemap::LiteMap;

let mut map = LiteMap::new();
map.insert(1, "one");
map.insert(2, "two");
assert_eq!(map.get(&1), Some(&"one"));
assert_eq!(map.get(&3), None);

pub fn remove<Q: ?Sized>(&mut self, key: &Q) -> Option<V> where
    K: Borrow<Q>,
    Q: Ord
[src]

Remove the value at key, returning it if it exists.

use litemap::LiteMap;

let mut map = LiteMap::new();
map.insert(1, "one");
map.insert(2, "two");
assert_eq!(map.remove(&1), Some("one"));
assert_eq!(map.get(&1), None);

impl<K, V> LiteMap<K, V>[src]

pub fn iter(&self) -> impl Iterator<Item = (&K, &V)>[src]

Produce an ordered iterator over key-value pairs

pub fn iter_keys(&self) -> impl Iterator<Item = &K>[src]

Produce an ordered iterator over keys

pub fn iter_values(&self) -> impl Iterator<Item = &V>[src]

Produce an iterator over values, ordered by their keys

pub fn iter_mut(&mut self) -> impl Iterator<Item = (&K, &mut V)>[src]

Produce an ordered mutable iterator over key-value pairs

Trait Implementations

impl<K: Clone, V: Clone> Clone for LiteMap<K, V>[src]

impl<K: Debug, V: Debug> Debug for LiteMap<K, V>[src]

impl<K, V> Default for LiteMap<K, V>[src]

impl<K: Ord, V> FromIterator<(K, V)> for LiteMap<K, V>[src]

impl<K: Ord, V> Index<&'_ K> for LiteMap<K, V>[src]

type Output = V

The returned type after indexing.

impl<K: Ord, V> IndexMut<&'_ K> for LiteMap<K, V>[src]

impl<K: PartialEq, V: PartialEq> PartialEq<LiteMap<K, V>> for LiteMap<K, V>[src]

impl<K, V> StructuralPartialEq for LiteMap<K, V>[src]

Auto Trait Implementations

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

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

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

impl<K, V> Unpin for LiteMap<K, V> where
    K: Unpin,
    V: Unpin

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

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.