/** * Get the value of the bit at the specified index. */ private boolean get(int bitIndex) { int unitIndex = unitIndex(bitIndex); return ((bits[unitIndex] & bit(bitIndex)) != 0); }
/** * Set the bit at the specified index. */ private void set(int bitIndex) { int unitIndex = unitIndex(bitIndex); bits[unitIndex] |= bit(bitIndex); }
/** * Get the value of the bit at the specified index. */ private boolean get(int bitIndex) { int unitIndex = unitIndex(bitIndex); return ((bits[unitIndex] & bit(bitIndex)) != 0); }
/** * Set the bit at the specified index. */ private void set(int bitIndex) { int unitIndex = unitIndex(bitIndex); bits[unitIndex] |= bit(bitIndex); }
/** * Construct a "small sieve" with a base of 0. This constructor is * used internally to generate the set of "small primes" whose multiples * are excluded from sieves generated by the main (package private) * constructor, BitSieve(BigInteger base, int searchLen). The length * of the sieve generated by this constructor was chosen for performance; * it controls a tradeoff between how much time is spent constructing * other sieves, and how much time is wasted testing composite candidates * for primality. The length was chosen experimentally to yield good * performance. */ private BitSieve() { length = 150 * 64; bits = new long[(unitIndex(length - 1) + 1)]; // Mark 1 as composite set(0); int nextIndex = 1; int nextPrime = 3; // Find primes and remove their multiples from sieve do { sieveSingle(length, nextIndex + nextPrime, nextPrime); nextIndex = sieveSearch(length, nextIndex + 1); nextPrime = 2*nextIndex + 1; } while((nextIndex > 0) && (nextPrime < length)); }
/** * Construct a "small sieve" with a base of 0. This constructor is * used internally to generate the set of "small primes" whose multiples * are excluded from sieves generated by the main (package private) * constructor, BitSieve(BigInteger base, int searchLen). The length * of the sieve generated by this constructor was chosen for performance; * it controls a tradeoff between how much time is spent constructing * other sieves, and how much time is wasted testing composite candidates * for primality. The length was chosen experimentally to yield good * performance. */ private BitSieve() { length = 150 * 64; bits = new long[(unitIndex(length - 1) + 1)]; // Mark 1 as composite set(0); int nextIndex = 1; int nextPrime = 3; // Find primes and remove their multiples from sieve do { sieveSingle(length, nextIndex + nextPrime, nextPrime); nextIndex = sieveSearch(length, nextIndex + 1); nextPrime = 2*nextIndex + 1; } while((nextIndex > 0) && (nextPrime < length)); }
bits = new long[(unitIndex(searchLen-1) + 1)]; length = searchLen; int start = 0;
bits = new long[(unitIndex(searchLen-1) + 1)]; length = searchLen; int start = 0;