Struct litemap::LiteMap [−][src]
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 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]
K: Borrow<Q>,
Q: Ord,
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]
K: Borrow<Q>,
Q: Ord,
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]
K: Borrow<Q>,
Q: Ord,
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"));
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()); // out of order append: assert!(map.try_append(2, "dos").is_some()); assert_eq!(map.get(&1), Some(&"uno")); // 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]
K: Borrow<Q>,
Q: Ord,
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> Index<&'_ K> for LiteMap<K, V>
[src]
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,
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for LiteMap<K, V> where
K: Send,
V: Send,
K: Send,
V: Send,
impl<K, V> Sync for LiteMap<K, V> where
K: Sync,
V: Sync,
K: Sync,
V: Sync,
impl<K, V> Unpin for LiteMap<K, V> where
K: Unpin,
V: Unpin,
K: Unpin,
V: Unpin,
impl<K, V> UnwindSafe for LiteMap<K, V> where
K: UnwindSafe,
V: UnwindSafe,
K: UnwindSafe,
V: UnwindSafe,
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>,