31 * be constant to reduce overhead. All the bits of a new bitSieve are zero, and
32 * bits are removed from it by setting them.
33 *
34 * To reduce storage space and increase efficiency, no even numbers are
35 * represented in the sieve (each bit in the sieve represents an odd number).
36 * The relationship between the index of a bit and the number it represents is
37 * given by
38 * N = offset + (2*index + 1);
39 * Where N is the integer represented by a bit in the sieve, offset is some
40 * even integer offset indicating where the sieve begins, and index is the
41 * index of a bit in the sieve array.
42 *
43 * @see BigInteger
44 * @author Michael McCloskey
45 * @since 1.3
46 */
47 class BitSieve {
48 /**
49 * Stores the bits in this bitSieve.
50 */
51 private long bits[];
52
53 /**
54 * Length is how many bits this sieve holds.
55 */
56 private int length;
57
58 /**
59 * A small sieve used to filter out multiples of small primes in a search
60 * sieve.
61 */
62 private static BitSieve smallSieve = new BitSieve();
63
64 /**
65 * Construct a "small sieve" with a base of 0. This constructor is
66 * used internally to generate the set of "small primes" whose multiples
67 * are excluded from sieves generated by the main (package private)
68 * constructor, BitSieve(BigInteger base, int searchLen). The length
69 * of the sieve generated by this constructor was chosen for performance;
70 * it controls a tradeoff between how much time is spent constructing
71 * other sieves, and how much time is wasted testing composite candidates
|
31 * be constant to reduce overhead. All the bits of a new bitSieve are zero, and
32 * bits are removed from it by setting them.
33 *
34 * To reduce storage space and increase efficiency, no even numbers are
35 * represented in the sieve (each bit in the sieve represents an odd number).
36 * The relationship between the index of a bit and the number it represents is
37 * given by
38 * N = offset + (2*index + 1);
39 * Where N is the integer represented by a bit in the sieve, offset is some
40 * even integer offset indicating where the sieve begins, and index is the
41 * index of a bit in the sieve array.
42 *
43 * @see BigInteger
44 * @author Michael McCloskey
45 * @since 1.3
46 */
47 class BitSieve {
48 /**
49 * Stores the bits in this bitSieve.
50 */
51 private long[] bits;
52
53 /**
54 * Length is how many bits this sieve holds.
55 */
56 private int length;
57
58 /**
59 * A small sieve used to filter out multiples of small primes in a search
60 * sieve.
61 */
62 private static BitSieve smallSieve = new BitSieve();
63
64 /**
65 * Construct a "small sieve" with a base of 0. This constructor is
66 * used internally to generate the set of "small primes" whose multiples
67 * are excluded from sieves generated by the main (package private)
68 * constructor, BitSieve(BigInteger base, int searchLen). The length
69 * of the sieve generated by this constructor was chosen for performance;
70 * it controls a tradeoff between how much time is spent constructing
71 * other sieves, and how much time is wasted testing composite candidates
|