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

Method to iterate over set bits #5

Open
Imberflur opened this issue Mar 25, 2022 · 0 comments
Open

Method to iterate over set bits #5

Imberflur opened this issue Mar 25, 2022 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@Imberflur
Copy link

The only method I can find is into_usizes which creates a new allocation.

I can manually accomplish this via iterating over all indices and using .filter(|i| matches!(bitset.get(i), Some(true)) but it seems like this is potentially not the most efficient implementation.

Would it be possible to add a method for this? Perhaps one that returns the iterator currently used internally in into_usizes?

        v.storage
            .into_iter()
            .flat_map(|x| x.to_array())
            .flat_map(|x| { (0..A::Item::ELEMENT_BIT_WIDTH).map(move |i| (x.wrapping_shr(i as u32)) & A::Item::ONE_ELEMENT != A::Item::ZERO_ELEMENT) })
            .take(v.nbits)
            .enumerate()
            .filter(|(_, b)| *b)
            .map(|(i, _)| i)
@GCCFeli GCCFeli self-assigned this Mar 28, 2022
@GCCFeli GCCFeli added the enhancement New feature or request label Mar 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants