From 7cf1f55426570582224e0568c838a29c5f7db5ea Mon Sep 17 00:00:00 2001 From: Graham Fawcett Date: Thu, 9 Oct 2014 10:02:07 -0400 Subject: [PATCH] In sieve example, end iteration sooner 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. --- src/libcollections/bitv.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcollections/bitv.rs b/src/libcollections/bitv.rs index 9f26c0980131f..6da998b136f9e 100644 --- a/src/libcollections/bitv.rs +++ b/src/libcollections/bitv.rs @@ -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