Struct ppom::rc::OMap [−][src]
pub struct OMap<K, V> { /* fields omitted */ }
Expand description
Fully Persistent array using Left-leaning-red-black tree.
Refer package level documentation for brief description.
Implementations
Set value for key. If there is an existing entry for key, overwrite the old value with new value and return the old value.
Remove key from this instance and return its value. If key is not present, then delete is effectively a no-op.
Get value for key.
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);
}
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())));
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())));
Return whether this instance is thread-safe.
Trait Implementations
Auto Trait Implementations
impl<K, V> !RefUnwindSafe for OMap<K, V>
impl<K, V> !UnwindSafe for OMap<K, V>
Blanket Implementations
Mutably borrows from an owned value. Read more