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

chunks_exact_mut() occasionally doesn't return the last chunk when step_by() is involved #231

Open
justindhales opened this issue Jun 19, 2023 · 0 comments

Comments

@justindhales
Copy link

When iterating over a BitSlice using chunks_exact_mut() and step_by() with a step value greater than 1 and the last chunk lands perfectly at the end of the BitSlice, the last chunk is not returned.

let chunk_size = 2usize;
let step_by = 3usize;

let mut indexes = vec![0, 1, 2, 3, 4, 5, 6, 7];
let mut bits = bitvec![0, 0, 0, 1, 1, 0, 1, 1];

assert_eq!(indexes.len(), bits.len());

println!("indexes.chunks_exact()");
for s in indexes.chunks_exact(chunk_size).step_by(step_by) {
    println!("{:?}", s);
}

println!("indexes.chunks_exact_mut()");
for s in indexes.chunks_exact_mut(chunk_size).step_by(step_by) {
    println!("{:?}", s);
}

println!("bits.chunks_exact()");
for s in bits.chunks_exact(chunk_size).step_by(step_by) {
    println!("{}", s);
}

println!("bits.chunks_exact_mut()");
for s in bits.chunks_exact_mut(chunk_size).step_by(step_by) {
    println!("{}", s);
}

This prints

indexes.chunks_exact()
[0, 1]
[6, 7]
indexes.chunks_exact_mut()
[0, 1]
[6, 7]
bits.chunks_exact()
[0, 0]
[1, 1]
bits.chunks_exact_mut()
[0, 0]

A similar error occurs when

let chunk_size = 1usize;
let step_by = 7usize;

but not when

let chunk_size = 1usize;
let step_by = 6usize;
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