-
Notifications
You must be signed in to change notification settings - Fork 573
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
CPP/solution_2: add mask implementation #985
Conversation
PrimeCPP/solution_2/PrimeCPP_PAR.cpp
Outdated
@@ -61,7 +61,55 @@ class BitArray { | |||
array[index(n)] |= (uint8_t(1) << (n % 8)); | |||
} | |||
|
|||
constexpr size_t size() const | |||
static constexpr uint32_t buildSkipMask(size_t skip, size_t offset) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a backwards-Kernigan way to do this? Seems like someone has probably thought about how to create a mask before, and there's likely a better way. Like maybe as bits are moved to the mask, you clear them from i and stop when i is zero?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
This splits solution_2 into two distinct solutions:
solution_2, which now uses bit masking and direct array access
solutiion_2a, which uses half as much memory, no direct array access, and is faster
Why keep solution_2 at all? Because one day I hope to learn SIMD and will need direct array access, so want to keep the basic methodology around
drag-race
as the target branch.