Skip to content

Bug: IndexMap fails to insert more than u16::MAX keys. #579

@ValouBambou

Description

@ValouBambou

I ran into this bug when inserting a lot of keys in an IndexMap, and it turns out that when my keys are bigger than an u16 they are not inserted properly. Here is a minimal reproducible code.

use heapless::FnvIndexMap;

fn main() {
    const N: usize = 1 << 17;
    let mut map = FnvIndexMap::<u32, usize, N>::new();
    for i in 1..(0xffff + 3) {
        let block = i;
        let idx = i as usize - 1;
        map.insert(block, idx).unwrap();
        assert!(map.contains_key(&block), "{}", i);
    }
}

I have no idea on why this happens. Does anyone have an idea ?
EDIT: the issue is not the values but the number of keys to insert shifting the start and end of the loop leads to the same bug
EDIT 2: the bug is present in the 0.8.0 version but fixed in 0.9.0 and on the latest commit on master.
EDIT 3: the bug is not fixed in any versions

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions