petgraph / fixedbitset

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

Add iter_ones() and iter_zeros() iterator. #7

Closed mneumann closed 1 year ago

mneumann commented 7 years ago

Having an iterator over the bits that are set to 1 (or 0) would be a nice addition. For example, it would speed up this loop of my Kuhn-Munkres implementation. I could implement it myself by using the as_slice() method, but this would make assumptions about the order in which bits are stored in the u32. This can be efficiently implemented using bsf (bit-scan-forward x86) or equivalent operations.

bluss commented 7 years ago

bit index when accessed like block & (1 << i) is arch independent, though.