Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add Sieve of Eratosthenes algorithm snippet in C++ #160

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

Closed
muriloguizelin wants to merge 3 commits into quicksnip-dev:main from muriloguizelin:main

Conversation

Copy link

@muriloguizelin muriloguizelin commented Jan 3, 2025

Description

Added a new snippet for the Sieve of Eratosthenes algorithm, which efficiently generates all prime numbers up to a given maximum value. The code demonstrates the classic sieve approach with an optimized marking process for identifying primes.

Type of Change

  • ✨ New snippet
  • 🛠 Improvement to an existing snippet
  • 🐞 Bug fix
  • 📖 Documentation update
  • 🔧 Other (please describe):

Checklist

  • I have tested my code and verified it works as expected.
  • My code follows the style and contribution guidelines of this project.
  • Comments are added where necessary for clarity.
  • Documentation has been updated (if applicable).
  • There are no new warnings or errors from my changes.

Related Issues

Closes #

Additional Context

This snippet provides an efficient implementation of the Sieve of Eratosthenes to calculate primes. It's suitable for use in applications that require prime number generation up to a specified maximum limit.

Screenshots (Optional)

Click to view screenshots

}
}

// Usage:.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove the dot . after the colon :

Copy link
Collaborator

@majvax majvax left a comment

Choose a reason for hiding this comment

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

Hey, Thanks for you contribution.

This seems to be a promising PR. However I have few comments to make

  1. Fix the issue on line 26

  2. Performance improvement discussion
    I’ve benchmarked your snippet, and it currently takes up to 500ms to calculate all prime numbers up to 1e7 + 1. While this is functional, I believe there’s room for optimization.

    • Have you considered using the C++20 consteval keyword to compute the primes at compile time? This could significantly improve runtime performance by shifting the computation to compile time.
    • Additionally, I’ve observed better performance when using std::bitset, which is a fixed-size array. It might be worth exploring this as an alternative to your current implementation.

Fix the issue, let me know your thoughts on these suggestions, and feel free to reach out if you’d like to discuss them further.

technoph1le and Mathys-Gasnier reacted with thumbs up emoji
@majvax majvax added the Guidelines Issue Your PR has been found to not follow the CONTRIBUTING.md guidelines label Jan 3, 2025
}

// Usage:
computeSieve();
Copy link
Collaborator

Choose a reason for hiding this comment

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

You need to update this line too

Copy link
Collaborator

@majvax majvax left a comment

Choose a reason for hiding this comment

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

When I say to update the usage section, I meant to update the way you call it. Since isPrime is no longer a global variable, you need to get it from the return value of computeSieve...

Copy link
Collaborator

majvax commented Jan 17, 2025

Hi @muriloguizelin,

I'm closing this PR due to inactivity. There hasn't been any response or updates in the past week despite the requested changes.

If you'd like to continue working on this feature, please feel free to open a new PR when you have time to address the feedback. We appreciate your contribution attempt and welcome future submissions.

Thanks for understanding!

Closing as stale. 👋

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

@majvax majvax majvax requested changes

@saminjay saminjay Awaiting requested review from saminjay saminjay is a code owner

Assignees
No one assigned
Labels
Guidelines Issue Your PR has been found to not follow the CONTRIBUTING.md guidelines Snippets
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /