1 unstable release
0.1.0 | Jun 12, 2021 |
---|
#2530 in Data structures
17KB
425 lines
LowMap
A convenient wrapper around a Vec<Option<T>>
. It abstracts the optional presence of an element as being a non contiguous vector.
let mut map = LowMap::new();
map.insert(0, "hey");
map.insert(2, "hoy");
map.insert(3, "foo");
map.insert(2, "bar");
assert_eq!(map.get(0), Some(&"hey"));
assert_eq!(map.get(1), None);
assert_eq!(map.get(2), Some(&"bar"));
assert_eq!(map.get(3), Some(&"foo"));
map[2] = "hoho";
assert_eq!(map.get(2), Some(&"hoho"));
lib.rs
:
A non contiguous Vec
that optionally holds a value for a given index.
It is called a LowMap
because it maps a given index to a value, and this
index must be small as it will be used as the inner Vec
index.