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

CPP/solution_2: add mask implementation #985

Merged
merged 11 commits into from
Nov 8, 2024
Merged

CPP/solution_2: add mask implementation #985

merged 11 commits into from
Nov 8, 2024

Conversation

davepl
Copy link
Contributor

@davepl davepl commented Nov 6, 2024

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

  • I read the contribution guidelines in CONTRIBUTING.md.
  • I placed my solution in the correct solution folder.
  • I added a README.md with the right badge(s).
  • I added a Dockerfile that builds and runs my solution.
  • I selected drag-race as the target branch.
  • All code herein is licensed compatible with BSD-3.

@@ -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)
Copy link
Contributor Author

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?

@rbergen rbergen marked this pull request as draft November 7, 2024 12:40
@rbergen rbergen marked this pull request as ready for review November 7, 2024 20:25
Copy link
Contributor

@rbergen rbergen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@rbergen rbergen changed the title Split solution2 of PrimeCPP CPP/solution_2: add mask implementation Nov 8, 2024
@rbergen rbergen merged commit fed6d05 into drag-race Nov 8, 2024
330 checks passed
@rbergen rbergen deleted the sol2 branch November 8, 2024 05:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants