Module key_vec::partial

source ·
Expand description

Types in this module accept keys with partial ordering and will generate a runtime panic if keys are incomparable.

use key_vec::partial::KeyVec;
let v = KeyVec::from (vec![(5.0, 'a'), (1.0, 'b'), (-1.0, 'c')]);
assert_eq!(*v, vec![(-1.0, 'c'), (1.0, 'b'), (5.0, 'a')]);
assert_eq!(&'c', v.get (&-1.0).unwrap());
assert!(v.get (&-2.0).is_none());

When constructing from a vec with duplicate keys, the first of any duplicates will be retained:

use key_vec::partial::KeyVec;
let v = KeyVec::from (vec![(5.0, 'a'), (-10.0, 'b'), (2.0, 'c'), (5.0, 'd')]);
assert_eq!(*v, vec![(-10.0, 'b'), (2.0, 'c'), (5.0, 'a')]);

When building or extending from an iterator, the last value to appear in the iterator will supercede any previous values with the same key:

use key_vec::partial::KeyVec;
let mut v = KeyVec::new();
assert!(v.insert (5.0, 'a').is_none());
v.extend (vec![(10.0, 'b'), (5.0, 'c'), (2.0, 'd'), (5.0, 'e')]);
assert_eq!(*v, vec![(2.0, 'd'), (5.0, 'e'), (10.0, 'b')]);

Structs