Skip to content

Method to iterate over set bits #5

Description

@Imberflur

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions