gen_map
A customizable generational map that returns a Key upon inserting a value.
The key can be used to later access or remove the value, and removing a value bumps its slot's generation, so the old key no longer matches the slot.
The operations for inserting, removing and accessing a value are all O(1).
The crate never uses std, so it also works on targets that do not have it.
[]
= "0.3"
Example
use GenMap;
let mut map = new;
let a = map.insert;
let b = map.insert;
assert_eq!;
assert_eq!;
assert_eq!;
assert!; // A removed key never matches again.
let c = map.insert; // This takes the slot `a` had, but under a new key.
assert_ne!;
for in &map
Configuring the map
A KeyConfig picks the key's index and generation types and how the key
stores them. Split<Idx, Gen> keeps the two as separate fields, and
Packed<R, GEN_BITS> puts them in the bits of one integer and picks the
smallest types that can hold them. A MapConfig is used to decide the key
config, and a GenMapConfig is used to decide what happens when a slot's
generation runs out and where the slots live.
use ;
/// Maps with this config hand out four byte keys with 24 bits of index and 8
/// bits of generation.
;
// `S` is the slot the map keeps each value in.
let mut map = new_with_config;
let key = map.insert;
assert_eq!;
The documentation covers the rest, such as key configs, storage, what happens when a generation runs out, and limiting which maps can use a config.
Secondary maps
A SecondaryMap stores values under the keys a GenMap hands out, to add
data to a GenMap's values without changing their type. Like a GenMap, it
can be configured, and the documentation covers
how it can be configured.
use ;
let mut people = new;
let mut ages = new;
let alice = people.insert;
ages.insert.unwrap;
assert_eq!;
Cargo features
allocis on by default. It adds theVecstorage and the default config. Turn default features off and usearrayvecinstead to run without an allocator.arrayvecaddsArrayVecstorage for aGenMapor aSecondaryMap. AnArrayVechas a fixed capacity and never allocates.smallvecaddsSmallVecstorage for aGenMapor aSecondaryMap. ASmallVeckeeps a few slots inline before it allocates. The feature uses a beta of smallvec 2.0, so it is not covered by semver.
License
gen_map is released under the MIT license.