Skip to content

Could we have a find_prev() as well? #102

Closed

Description

@rhalbersma

Hi! Could we have a find_prev() to go along the find_next()? That would allow efficient reverse iteration over all 1-bits. The code should be pretty much the reverse of find_next(), and using countl_zero instead of countr_zero as the bit intrinsic function.

Activity

  1. gennaroprota commented on Jan 5, 2026

    @gennaroprota
    Collaborator

    Hi Rein! Thanks for the suggestion :-).

    Apparently, some people are confused by the name of find_first_off() (they mix it up with find_first_of(), although the latter wouldn't make much sense for a bitset), so I'm thinking of the following renames:

    • find_first() → find_first_one()
    • find_first_off() → find_first_zero()
    • find_next() → find_next_one()
    • find_next_off() → find_next_zero()

    Once I have decided on that, I'll implement the member you suggested. It will likely be named find_previous_one().

  2. gennaroprota commented on Jan 9, 2026

    @gennaroprota
    Collaborator

    @rhalbersma: I sketched an implementation in PR #103. It adds a find_last_one(), too, although that's logically unnecessary, because a b.find_previous_one( i ) with i >= b.size() (e.g. i == npos) would find the last 1 bit. Please let me know what you think.

  3. gennaroprota commented on Apr 28, 2026

    @gennaroprota
    Collaborator

    This has been open for a long time without feedback. Going to close it.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions