bitmaps icon indicating copy to clipboard operation
bitmaps copied to clipboard

Invalid Index after inverting a bitmap

Open MaximilianMoeller opened this issue 2 years ago • 0 comments

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"

MaximilianMoeller avatar Sep 13 '22 15:09 MaximilianMoeller