[libmath-prime-util-perl] 22/181: forcomposites using sieve
Partha P. Mukherjee
ppm-guest at moszumanska.debian.org
Thu May 21 18:51:02 UTC 2015
This is an automated email from the git hooks/post-receive script.
ppm-guest pushed a commit to annotated tag v0.36
in repository libmath-prime-util-perl.
commit 8a0928d9fabc9fbd6c81f484cab483941ba89e8e
Author: Dana Jacobsen <dana at acm.org>
Date: Wed Dec 18 23:35:05 2013 -0800
forcomposites using sieve
---
TODO | 2 --
XS.xs | 25 +++++++++++++++++++------
lib/Math/Prime/Util.pm | 2 +-
3 files changed, 20 insertions(+), 9 deletions(-)
diff --git a/TODO b/TODO
index a7d6a01..6c8682a 100644
--- a/TODO
+++ b/TODO
@@ -61,5 +61,3 @@
- look at sieve.c style prime walking
- Add Inverse Li and Legendre Phi to API?
-
-- More efficient forcomposites
diff --git a/XS.xs b/XS.xs
index 67e2567..33b4eaa 100644
--- a/XS.xs
+++ b/XS.xs
@@ -963,16 +963,29 @@ forcomposites (SV* block, IN SV* svbeg, IN SV* svend = 0)
svarg = newSVuv(0);
#if USE_MULTICALL
if (!CvISXSUB(cv)) {
+ unsigned char* segment;
+ UV seg_base, seg_low, seg_high, c, cbeg, cend, last;
+ void* ctx;
dMULTICALL;
I32 gimme = G_VOID;
PUSH_MULTICALL(cv);
- for (i = beg; i <= end; i++) {
- if (!_XS_is_prob_prime(i)) {
- sv_setuv(svarg, i);
- GvSV(PL_defgv) = svarg;
- MULTICALL;
- }
+ if (beg <= 4) { /* sieve starts at 7, so handle this here */
+ sv_setuv(svarg, 4); GvSV(PL_defgv) = svarg; MULTICALL;
+ beg = 6;
}
+ last = _XS_prev_prime(beg);
+ ctx = start_segment_primes(beg, _XS_next_prime(end), &segment);
+ while (next_segment_primes(ctx, &seg_base, &seg_low, &seg_high)) {
+ START_DO_FOR_EACH_SIEVE_PRIME( segment, seg_low - seg_base, seg_high - seg_base ) {
+ cbeg = (last+1 < beg) ? beg : last+1;
+ last = seg_base + p;
+ cend = (last-1 > end) ? end : last-1;
+ for (c = cbeg; c <= cend; c++) {
+ sv_setuv(svarg, c); GvSV(PL_defgv) = svarg; MULTICALL;
+ }
+ } END_DO_FOR_EACH_SIEVE_PRIME
+ }
+ end_segment_primes(ctx);
FIX_MULTICALL_REFCOUNT;
POP_MULTICALL;
}
diff --git a/lib/Math/Prime/Util.pm b/lib/Math/Prime/Util.pm
index 75f17bb..b0ff55d 100644
--- a/lib/Math/Prime/Util.pm
+++ b/lib/Math/Prime/Util.pm
@@ -2538,7 +2538,7 @@ __END__
=encoding utf8
-=for stopwords forprimes Möbius Deléglise totient moebius mertens liouville znorder irand primesieve uniqued k-tuples von SoE pari yafu fonction qui compte le nombre nombres voor PhD superset sqrt(N) gcd(A^M k-th (10001st primegen libtommath
+=for stopwords forprimes forcomposites fordivisors Möbius Deléglise totient moebius mertens liouville znorder irand primesieve uniqued k-tuples von SoE pari yafu fonction qui compte le nombre nombres voor PhD superset sqrt(N) gcd(A^M k-th (10001st primegen libtommath
=head1 NAME
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libmath-prime-util-perl.git
More information about the Pkg-perl-cvs-commits
mailing list