petgraph / fixedbitset

A simple bitset container for Rust
https://docs.rs/fixedbitset/
Apache License 2.0
124 stars 47 forks source link

New constructor with blocks #42

Closed luizirber closed 4 years ago

luizirber commented 4 years ago

This PR adds a new constructor taking capacity and blocks. I needed this because loading big bitsets using .from_iter or .extend was slow, and with this change it is much faster because it avoids all the conversions to find what bit to set. (Incidentally, if anyone has good approaches to load data from disk that avoids this PR, I'm interested).

I really like all the other features in fixedbitset, and didn't want to lose them by switching to another crate... But I also understand that this is an invasive change, because it exposes internals and makes it harder to change how data is stored or accessed in the future.

Additional changes: maybe make the signature pub unsafe fn with_capacity_and_blocks(bits: usize, data: Vec<Block>) -> Self to indicate the caller is responsible for passing Vec<block> in the right format?

bluss commented 4 years ago

Reasonable suggestion, even if it does expose the fact that we use 32-bit blocks. Last chance to revisit that decision - is u64 better? The method signature would be able to be supported even if we switch to u64 internally, though.

bluss commented 4 years ago

Thank you, nice.

Feel free to poke me if this doesn't get released "soon".