Skip to content

Commit

Permalink
In sieve example, end iteration sooner
Browse files Browse the repository at this point in the history
The Sieve algorithm only requires checking all elements up to and including the square root of the maximum prime you're looking for. After that, the remaining elements are guaranteed to be prime.
  • Loading branch information
gmfawcett committed Oct 9, 2014
1 parent e6cfb56 commit 7cf1f55
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/libcollections/bitv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
//! bv.set(0, false);
//! bv.set(1, false);
//!
//! for i in range(2, max_prime) {
//! for i in iter::range_inclusive(2, (max_prime as f64).sqrt() as uint) {
//! // if i is a prime
//! if bv[i] {
//! // Mark all multiples of i as non-prime (any multiples below i * i
Expand Down

5 comments on commit 7cf1f55

@bors
Copy link
Contributor

@bors bors commented on 7cf1f55 Oct 13, 2014

Choose a reason for hiding this comment

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

@bors
Copy link
Contributor

@bors bors commented on 7cf1f55 Oct 13, 2014

Choose a reason for hiding this comment

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

merging gmfawcett/rust/patch-1 = 7cf1f55 into auto

@bors
Copy link
Contributor

@bors bors commented on 7cf1f55 Oct 13, 2014

Choose a reason for hiding this comment

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

gmfawcett/rust/patch-1 = 7cf1f55 merged ok, testing candidate = 1c3ddd2

@bors
Copy link
Contributor

@bors bors commented on 7cf1f55 Oct 14, 2014

Choose a reason for hiding this comment

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

@bors
Copy link
Contributor

@bors bors commented on 7cf1f55 Oct 14, 2014

Choose a reason for hiding this comment

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

fast-forwarding master to auto = 1c3ddd2

Please sign in to comment.