fixed-hashmap 0.1.0

A fixed-capacity, allocation-free hashmap for fixed-size byte keys and values
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use core::mem::MaybeUninit;
use fixed_hashmap::{EntryStorage, FixedMap};

const CAPACITY: usize = 4;

fn main() {
    let mut entries: [EntryStorage<4, 8>; CAPACITY * 2] =
        core::array::from_fn(|_| MaybeUninit::uninit());
    let mut tags = [0; CAPACITY * 2];
    let mut map = FixedMap::<CAPACITY, 4, 8>::new(&mut entries, &mut tags)
        .expect("backing storage has twice the entry capacity");

    map.insert(*b"key1", *b"value001")
        .expect("the map has free capacity");
    assert_eq!(map.get(b"key1"), Some(b"value001"));
    println!("{} entry stored", map.len());
}