# Guidance about binary / data files for JTREG tests

Brian Burkhalter brian.burkhalter at oracle.com
Mon Apr 28 22:09:10 UTC 2014

```For grins here’s an alternative implementation of your algorithm that is slower but likely takes less memory:

private static BitSet primesBS(int n) {
int nbits = n + 1;
BitSet bs = new BitSet(nbits);
bs.set(0, 2, true);
for (int p = 2; p * p < n;) {
for (int i = 2 * p; i < nbits; i += p) {
bs.set(i, true);
}
do {
++p;
} while (bs.get(p));
}
return bs;
}

Note that in this case a set bit means NOT prime.

Brian

On Apr 28, 2014, at 11:52 AM, Florian Weimer <fweimer at redhat.com> wrote:

>    private static boolean[] primes(int n) {
> 	boolean[] primes = new boolean[n + 1];
> 	Arrays.fill(primes, true);
> 	primes = false;
> 	primes = false;
> 	for (int p = 2; p * p < n; ) {
> 	    for (int i = 2 * p; i < primes.length; i += p)
> 		primes[i] = false;
> 	    do
> 		++p;
> 	    while (!primes[p]);
> 	}
> 	return primes;
>    }

```

More information about the core-libs-dev mailing list