pub struct OMap<K, V> { /* private fields */ }Expand description
Ephemeral ordered-map type using left-leaning-red-black tree.
Refer package level documentation for brief description.
Implementations§
Source§impl<K, V> OMap<K, V>
impl<K, V> OMap<K, V>
Sourcepub fn set(&mut self, key: K, value: V) -> Option<V>
pub fn set(&mut self, key: K, value: V) -> Option<V>
Set value for key. If there is an existing entry for key, overwrite the old value with new value and return the old value.
Source§impl<K, V> OMap<K, V>
impl<K, V> OMap<K, V>
Sourcepub fn iter(&self) -> Iter<'_, K, V>
pub fn iter(&self) -> Iter<'_, K, V>
Return an iterator over all entries in this instance.
use ppom::OMap;
let mut index: OMap<String,String> = OMap::new();
index.set("key1".to_string(), "value1".to_string());
index.set("key2".to_string(), "value2".to_string());
for (i, (key, value)) in index.iter().enumerate() {
let refkey = format!("key{}", i+1);
let refval = format!("value{}", i+1);
assert_eq!(refkey, key);
assert_eq!(refval, value);
}Sourcepub fn range<Q, R>(&self, range: R) -> Range<'_, K, V, R, Q>
pub fn range<Q, R>(&self, range: R) -> Range<'_, K, V, R, Q>
Range over all entries from low to high, specified by range.
use std::ops::Bound;
use ppom::OMap;
let mut index: OMap<String,String> = OMap::new();
index.set("key1".to_string(), "value1".to_string());
index.set("key2".to_string(), "value2".to_string());
index.set("key3".to_string(), "value3".to_string());
let low = Bound::Excluded("key1");
let high = Bound::Excluded("key2");
let item = index.range::<str, _>((low, high)).next();
assert_eq!(item, None);
let low = Bound::Excluded("key1");
let high = Bound::Excluded("key3");
let item = index.range::<str, _>((low, high)).next();
assert_eq!(item, Some(("key2".to_string(), "value2".to_string())));
let low = Bound::Included("key1");
let high = Bound::Included("key3");
let mut ranger = index.range::<str, _>((low, high));
let item = ranger.next();
assert_eq!(item, Some(("key1".to_string(), "value1".to_string())));
let item = ranger.last();
assert_eq!(item, Some(("key3".to_string(), "value3".to_string())));Sourcepub fn reverse<R, Q>(&self, range: R) -> Reverse<'_, K, V, R, Q>
pub fn reverse<R, Q>(&self, range: R) -> Reverse<'_, K, V, R, Q>
Reverse range over all entries from high to low, specified by range.
use std::ops::Bound;
use ppom::OMap;
let mut index: OMap<String,String> = OMap::new();
index.set("key1".to_string(), "value1".to_string());
index.set("key2".to_string(), "value2".to_string());
index.set("key3".to_string(), "value3".to_string());
let low = Bound::Included("key1");
let high = Bound::Included("key3");
let mut iter = index.reverse::<_, str>((low, high));
let item = iter.next();
assert_eq!(item, Some(("key3".to_string(), "value3".to_string())));
let item = iter.last();
assert_eq!(item, Some(("key1".to_string(), "value1".to_string())));Trait Implementations§
Source§impl<K, V> Extend<(K, V)> for OMap<K, V>
impl<K, V> Extend<(K, V)> for OMap<K, V>
Source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = (K, V)>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = (K, V)>,
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one)Reserves capacity in a collection for the given number of additional elements. Read more
Auto Trait Implementations§
impl<K, V> Freeze for OMap<K, V>
impl<K, V> RefUnwindSafe for OMap<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for OMap<K, V>
impl<K, V> Sync for OMap<K, V>
impl<K, V> Unpin for OMap<K, V>
impl<K, V> UnwindSafe for OMap<K, V>where
K: UnwindSafe,
V: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more