This is an automated email from the git hooks/post-receive script.

ppm-guest pushed a commit to annotated tag v0.28
in repository libmath-prime-util-perl.

commit efa7895ee64d11045c106b12f04010c0a6962c92
Author: Dana Jacobsen <d...@acm.org>
Date:   Wed May 22 01:36:29 2013 -0700

    Document the prime iterator
---
 TODO                              |  2 ++
 XS.xs                             |  2 +-
 lib/Math/Prime/Util.pm            | 27 ++++++++++++++++++++++++---
 lib/Math/Prime/Util/PrimeArray.pm |  3 +--
 4 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/TODO b/TODO
index b2bce1a..bc275d1 100644
--- a/TODO
+++ b/TODO
@@ -54,3 +54,5 @@
 
 - Figure out a way to make the internal FOR_EACH_PRIME macros use a segmented
   sieve.
+
+- prime_count_approx on a 100-digit bigint is really slow without MPFR.
diff --git a/XS.xs b/XS.xs
index 491b6f3..f395c63 100644
--- a/XS.xs
+++ b/XS.xs
@@ -1,5 +1,5 @@
 
-#define PERL_NO_GET_CONTEXT  /* Define at top for more efficiency. */
+#define PERL_NO_GET_CONTEXT 1 /* Define at top for more efficiency. */
 
 #include "EXTERN.h"
 #include "perl.h"
diff --git a/lib/Math/Prime/Util.pm b/lib/Math/Prime/Util.pm
index 1347132..3af8fa8 100644
--- a/lib/Math/Prime/Util.pm
+++ b/lib/Math/Prime/Util.pm
@@ -1371,9 +1371,7 @@ sub prime_iterator {
   if (ref($p) ne 'Math::BigInt' && $p <= $_XS_MAXVAL) {
     return sub { $p = _XS_next_prime($p); return $p; };
   } elsif ($_HAVE_GMP) {
-    return sub { my $next = Math::Prime::Util::GMP::next_prime($p);
-                 $p = $p-$p+$next;
-                 return $p; };
+    return sub { $p = $p-$p+Math::Prime::Util::GMP::next_prime($p); return 
$p;};
   } else {
     return sub { $p = Math::Prime::Util::PP::next_prime($p); return $p; }
   }
@@ -2692,6 +2690,29 @@ block for each prime in the range.  Compared to getting 
a big array of primes
 and iterating through it, this is more memory efficient and perhaps more
 convenient.
 
+Inside the block, you may use C<last> to exit early, or C<return> to skip to
+the next entry.
+
+
+=head2 prime_iterator
+
+  my $it = prime_iterator;
+  $sum += $it->() for 1..100000;
+
+Returns a closure-style iterator.  The start value defaults to the first
+prime (2) but an initial value may be given as an argument, which will result
+in the first value returned being the next prime greater than or equal to the
+argument.  For example, this:
+
+  my $it = prime_iterator(200);  say $it->();  say $it->();
+
+will return 211 followed by 223, as those are the next primes E<gt>= 200.
+On each call, the iterator returns the current value and increments to
+the next prime.
+
+In general, L</forprimes> will be more efficient, but the generic iterator has
+a little more flexibility.
+
 
 =head2 prime_count
 
diff --git a/lib/Math/Prime/Util/PrimeArray.pm 
b/lib/Math/Prime/Util/PrimeArray.pm
index 39fa38a..377b418 100644
--- a/lib/Math/Prime/Util/PrimeArray.pm
+++ b/lib/Math/Prime/Util/PrimeArray.pm
@@ -269,8 +269,7 @@ for reasonably small numbers.  It does not support random 
access.  It is
 very fast for small values, but is very slow with large counts.
 
 L<Math::Primes::TiedArray> is remarkably impractical for anything other
-than very small numbers.  The sieve used is incredibly slow, and the memory
-use is crazy.
+than very small numbers.
 
 
 =head1 SEE ALSO

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-perl/packages/libmath-prime-util-perl.git

_______________________________________________
Pkg-perl-cvs-commits mailing list
Pkg-perl-cvs-commits@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-perl-cvs-commits

Reply via email to