This is an automated email from the git hooks/post-receive script. ppm-guest pushed a commit to annotated tag v0.08 in repository libmath-prime-util-perl.
commit f90078875cc4d6fb894ab9a6be2494f09a799fc1 Author: Dana Jacobsen <d...@acm.org> Date: Mon Jun 18 17:05:53 2012 -0600 Remove simple sieve --- Changes | 2 ++ MANIFEST | 1 - TODO | 2 -- XS.xs | 28 ---------------------------- bitarray.h | 16 ---------------- lib/Math/Prime/Util.pm | 6 +++++- sieve.c | 27 --------------------------- sieve.h | 1 - t/11-primes.t | 4 ++-- t/92-release-pod-coverage.t | 2 +- 10 files changed, 10 insertions(+), 79 deletions(-) diff --git a/Changes b/Changes index 2eeaf46..20a9897 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,8 @@ Revision history for Perl extension Math::Prime::Util. 0.08 20 June 2012 - Added thread scaffolding. - Accuracy improvement and measurements for math functions. + - Remove simple sieve -- it wasn't being used, and was just around for + performance comparisons. 0.07 17 June 2012 - Fixed a bug in next_prime found by Lou Godio (thank you VERY much!). diff --git a/MANIFEST b/MANIFEST index 6432974..f0cc009 100644 --- a/MANIFEST +++ b/MANIFEST @@ -6,7 +6,6 @@ MANIFEST README TODO XS.xs -bitarray.h ptypes.h cache.h cache.c diff --git a/TODO b/TODO index 93c3a6a..917a298 100644 --- a/TODO +++ b/TODO @@ -35,5 +35,3 @@ version does it in a painful way. Something simpler to be had? - Iterator or tie? - -- Get rid of erat_simple and bitarray.h. They're only there for comparison. diff --git a/XS.xs b/XS.xs index d0fcb4f..f7a76c9 100644 --- a/XS.xs +++ b/XS.xs @@ -7,7 +7,6 @@ #include "cache.h" #include "sieve.h" #include "util.h" -#include "bitarray.h" #include "factor.h" MODULE = Math::Prime::Util PACKAGE = Math::Prime::Util @@ -210,33 +209,6 @@ erat_primes(IN UV low, IN UV high) RETVAL -SV* -erat_simple_primes(IN UV low, IN UV high) - PREINIT: - UV* sieve; - UV s; - AV* av = newAV(); - CODE: - if (low <= high) { - sieve = sieve_erat(high); - if (sieve == 0) { - croak("Could not generate sieve for %"UVuf, high); - } else { - if (low <= 2) { av_push(av, newSVuv( 2 )); low = 3; } - low = low/2; - high = (high-1)/2; - for (s = low; s <= high; s++) { - if ( ! IS_SET_ARRAY_BIT(sieve, s) ) { - av_push(av,newSVuv( 2*s+1 )); - } - } - Safefree(sieve); - } - } - RETVAL = newRV_noinc( (SV*) av ); - OUTPUT: - RETVAL - void factor(IN UV n) PPCODE: diff --git a/bitarray.h b/bitarray.h deleted file mode 100644 index ff117b6..0000000 --- a/bitarray.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef MPU_BITARRAY_H -#define MPU_BITARRAY_H - -#include "ptypes.h" - -/* The mod-30 wheel is byte-based so doesn't use these. */ -#define SET_ARRAY_BIT(ar,n) \ - ar[(n)/BITS_PER_WORD] |= (UVCONST(1) << ((n)%BITS_PER_WORD)) -#define XOR_ARRAY_BIT(ar,n) \ - ar[(n)/BITS_PER_WORD] ^= (UVCONST(1) << ((n)%BITS_PER_WORD)) -#define CLR_ARRAY_BIT(ar,n) \ - ar[(n)/BITS_PER_WORD] &= ~(UVCONST(1) << ((n)%BITS_PER_WORD)) -#define IS_SET_ARRAY_BIT(ar,n) \ - (ar[(n)/BITS_PER_WORD] & (UVCONST(1) << ((n)%BITS_PER_WORD)) ) - -#endif diff --git a/lib/Math/Prime/Util.pm b/lib/Math/Prime/Util.pm index fa0c2c6..64f290f 100644 --- a/lib/Math/Prime/Util.pm +++ b/lib/Math/Prime/Util.pm @@ -92,9 +92,13 @@ sub primes { } } + if ($method =~ /^Simple\w*$/i) { + warn "Method 'Simple' is deprecated."; + $method = 'Erat'; + } + if ($method =~ /^Trial$/i) { $sref = trial_primes($low, $high); } elsif ($method =~ /^Erat\w*$/i) { $sref = erat_primes($low, $high); } - elsif ($method =~ /^Simple\w*$/i) { $sref = erat_simple_primes($low, $high); } elsif ($method =~ /^Seg\w*$/i) { $sref = segment_primes($low, $high); } elsif ($method =~ /^Sieve$/i) { $sref = sieve_primes($low, $high); } else { croak "Unknown prime method: $method"; } diff --git a/sieve.c b/sieve.c index 196bf2f..3679d1d 100644 --- a/sieve.c +++ b/sieve.c @@ -5,36 +5,9 @@ #include "sieve.h" #include "ptypes.h" -#include "bitarray.h" -UV* sieve_erat(UV end) -{ - UV* mem; - UV n, s; - UV last = (end+1)/2; - - Newz(0, mem, NWORDS(last), UV ); - if (mem == 0) { - croak("allocation failure in sieve_erat: could not alloc %"UVuf" bits", last); - return 0; - } - - n = 3; - /* TODO: overflow */ - while ( (n*n) <= end) { - for (s = n*n; s <= end; s += 2*n) - SET_ARRAY_BIT(mem,s/2); - do { n += 2; } while (IS_SET_ARRAY_BIT(mem,n/2)); - } - - SET_ARRAY_BIT(mem, 1/2); /* 1 is composite */ - - return mem; -} - - /* Wheel 30 sieve. Ideas from Terje Mathisen and Quesada / Van Pelt. */ unsigned char* sieve_erat30(UV end) { diff --git a/sieve.h b/sieve.h index c61b0d3..9bf8c49 100644 --- a/sieve.h +++ b/sieve.h @@ -4,7 +4,6 @@ #include "EXTERN.h" #include "perl.h" -extern UV* sieve_erat(UV end); extern unsigned char* sieve_erat30(UV end); extern int sieve_segment(unsigned char* mem, UV startd, UV endd); diff --git a/t/11-primes.t b/t/11-primes.t index 5d36d63..a63b213 100644 --- a/t/11-primes.t +++ b/t/11-primes.t @@ -8,7 +8,7 @@ use Math::Prime::Util qw/primes prime_count/; my $use64 = Math::Prime::Util::_maxbits > 32; my $extra = defined $ENV{RELEASE_TESTING} && $ENV{RELEASE_TESTING}; -plan tests => 12+3 + 12 + 1 + 19 + ($use64 ? 1 : 0) + 1 + 13*6; +plan tests => 12+3 + 12 + 1 + 19 + ($use64 ? 1 : 0) + 1 + 13*5; ok(!eval { primes(undef); }, "primes(undef)"); ok(!eval { primes("a"); }, "primes(a)"); @@ -113,7 +113,7 @@ if ($use64) { is( scalar @{primes(474973,838390)}, prime_count(838390) - prime_count(474973), "count primes within a range" ); -foreach my $method (qw/trial erat simple segment sieve dynamic/) { +foreach my $method (qw/trial erat segment sieve dynamic/) { is_deeply( primes({method=>$method}, 0, 3572), \@small_primes, "Primes between 0 and 3572" ); is_deeply( primes({method=>$method}, 2, 20), [2,3,5,7,11,13,17,19], "Primes between 2 and 20" ); is_deeply( primes({method=>$method}, 30, 70), [31,37,41,43,47,53,59,61,67], "Primes between 30 and 70" ); diff --git a/t/92-release-pod-coverage.t b/t/92-release-pod-coverage.t index 4590319..7599dd1 100644 --- a/t/92-release-pod-coverage.t +++ b/t/92-release-pod-coverage.t @@ -21,5 +21,5 @@ my @modules = Test::Pod::Coverage::all_modules(); plan tests => scalar @modules; foreach my $m (@modules) { - pod_coverage_ok( $m, { also_private => [ qr/^(erat|erat_simple|segment|trial|sieve)_primes$/ ] } ); + pod_coverage_ok( $m, { also_private => [ qr/^(erat|segment|trial|sieve)_primes$/ ] } ); } -- 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