11 releases
0.4.1 | Jul 4, 2023 |
---|---|
0.3.1 | May 22, 2023 |
0.3.0 | Jan 21, 2022 |
0.2.6 | Dec 8, 2020 |
0.2.3 | Nov 15, 2019 |
#100 in #key-value
60 downloads per month
Used in tea-keyvalue-provider
18KB
414 lines
key_vec
Vec of key-value pairs sorted by key
let mut v = KeyVec::<i32, char>::new();
v.extend (vec![(10i32, 'a'), (-1, 'b'), (3, 'c'), (-1, 'd')].into_iter());
assert_eq!(*v, vec![(-1i32, 'd'), (3, 'c'), (10, 'a')]);
lib.rs
:
Vec-backed container of key-value pairs sorted by key for order 'log n' lookup.
use key_vec::KeyVec;
let v = KeyVec::from (vec![(5, 'a'), (1, 'b'), (-1, 'c')]);
assert_eq!(*v, vec![(-1, 'c'), (1, 'b'), (5, 'a')]);
assert_eq!(&'c', v.get (&-1).unwrap());
assert!(v.get (&-2).is_none());
When constructing from a vec with duplicate keys, the first of any duplicates will be retained:
use key_vec::KeyVec;
let v = KeyVec::from (vec![(5, 'a'), (-10, 'b'), (2, 'c'), (5, 'd')]);
assert_eq!(*v, vec![(-10, 'b'), (2, 'c'), (5, '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::KeyVec;
let mut v = KeyVec::new();
assert!(v.insert (5, 'a').is_none());
v.extend (vec![(10, 'b'), (5, 'c'), (2, 'd'), (5, 'e')]);
assert_eq!(*v, vec![(2, 'd'), (5, 'e'), (10, 'b')]);
Dependencies
~170KB