Skip to content

Invalid Index after inverting a bitmap #18

@MaximilianMoeller

Description

@MaximilianMoeller

When using .invert() on a Bitmap<SIZE> and then iterating over the indices, SIZE appears as an index.
Minimal working example:

use bitmaps::{
	Bitmap,
};
fn main() {

    let mut my_map: Bitmap<4> = Bitmap::new();
    my_map.set(0,true);
    my_map.set(2,true);
    println!("== TRUE =============");
    for index in &my_map{
        println!("index: {}", index);
        //println!("value: {}", my_map.get(index));
    }

    my_map.invert();
    println!("== FALSE ============");
    for index in &my_map{
        println!("index: {}", index);
        //println!("value: {}", my_map.get(index));
    }
}

Expected Output:

== TRUE =============
index: 0
index: 2
== FALSE ============
index: 1
index: 3

Actual Output:

== TRUE =============
index: 0
index: 2
== FALSE ============
index: 1
index: 3
index: 4

This becomes especially dramatic when you un-comment lines 12 and 19 as it results in the program panicking.

Cargo.toml:

[Dependencies]
bitmaps = "3.2.0"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions