Struct ppom::OMap[][src]

pub struct OMap<K, V> { /* fields omitted */ }
Expand description

Ephemeral ordered-map type using left-leaning-red-black tree.

Refer package level documentation for brief description.

Implementations

Return number of entries in index.

Check whether this index is empty.

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.

Validate OMap tree with following rules:

  • From root to any leaf, no consecutive reds allowed in its path.
  • Number of blacks should be same under left child and right child.
  • Make sure keys are in sorted order.

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 a random entry from this index.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Returns the “default value” for a type. Read more

Extends a collection with the contents of an iterator. Read more

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 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

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.