A small utility crate when you have a list of unique but not dense indexes for which to each you want to associates a value.
In the documentation the indexes are referred as key
. Not an indexed map!
It can be considered a slower but more compact version of BTreeMap
.
A brief example of the crate's capacities ```rust use mapofindexes::{MapOfIndexes, MapOfIndexesError, KeyValue};
let v = vec![(3, 4), (1, 2), (5, 6)]; let mut map: MapOfIndexes::<(u8, u16)> = v.try_into()?;
map.push((7,8)); let pushres = map.pushchecked((0,9)); asserteq!(pushres, Err(MapOfIndexesError::SmallerKey));
let oldkeyvalue = map.set((1,9))?;
asserteq!(oldkeyvalue.key(), &1);
asserteq!(oldkeyvalue.value(), &2);
[`CombinedKeyValue`](crate::CombinedKeyValue) is a compact representation when you need to save space.
rust
use mapofindexes::{CombinedKeyValue};
// We have keys that take up to 40 bits, and value up to 24;
// Using (u64, u64) would have wasted 8 byte per entry.
type CombinedU64 = CombinedKeyValue
let v = vec![CombinedU64::new(3u64, 4u32), CombinedU64::new(1u64, 2u32), CombinedU64::new(5u64, 6u32)];
let map: MapOfIndexes<_> = v.tryinto()?;
let innerraw: Vec
For an even more compact representation, consider using the [
bitvec`](https://docs.rs/bitvec/latest/bitvec/index.html) crate.
License: AGPL-3.0+