Created
September 26, 2025 22:02
-
-
Save jweinst1/523cf455eac3653d5b20e6d48abc5cae to your computer and use it in GitHub Desktop.
get the next greatest neighbor in bitset
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <bitset> | |
int next_ge(uint64_t S, int k) { | |
uint64_t mask = ~((1ULL << k) - 1); | |
uint64_t candidates = S & mask; | |
return __builtin_ctzll(candidates); | |
} | |
int main(int argc, char const *argv[]) | |
{ | |
std::cout << size_t(next_ge(((uint64_t)1 << 32) | (1 << 26), 23)) << "\n"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment