rust-embedded / rust-embedded/heapless

Add `View` version of `IndexMap` and `IndexSet`

Open
#594 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
2k
Forks
253
Avg merge
1d 2h
Merged PRs (30d)
1

Description

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?).

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the existing CoreMap, IndexMap, IndexSet, and View implementations to understand how the const generic N is represented and erased. Compare the proposed separate-index and inlined-index layouts, then determine the required design before implementing View support for IndexMap and IndexSet.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.