Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid Index after inverting a bitmap #18

Open
MaximilianMoeller opened this issue Sep 13, 2022 · 0 comments
Open

Invalid Index after inverting a bitmap #18

MaximilianMoeller opened this issue Sep 13, 2022 · 0 comments

Comments

@MaximilianMoeller
Copy link

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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant