heapless
heapless copied to clipboard
Add `View` version of `IndexMap` and `IndexSet`
IndexSet depends on the View type for IndexMap being available.
IndexMap is currently implemented with a CoreMaptype that looks like:
struct CoreMap<K, V, const N: usize> {
entries: Vec<Bucket<K, V>, N>,
indices: [Option<Pos>; N],
}
It is not possible to construct a View for this type like for Vec since the N would have to be erased twice.
We could solve that issue by "inlining" the indices into the entries:
struct CoreMap<K, V, const N: usize> {
entries_indices: [(MaybeUninit<Bucket<K, V>>, Option<Pos>); N],
len: usize,
}
Then only one N needs to be erased, and this can be implemented. However this requires changing the implementation significantly.
It might even be possible to get rid of the len field (I think an entry is initialised if and only if a index points to it, and only one index can point to it at a given time?).