Skip to content
Snippets Groups Projects
Commit abe2e1f2 authored by Goik Martin's avatar Goik Martin
Browse files

cosmetics

parent 07540628
No related branches found
No related tags found
No related merge requests found
......@@ -219,7 +219,7 @@
<para>We start with the first task by implementing the <link
xlink:href="https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes#Euler.27s_Sieve">Euler
sieve algorithm</link>. We may use a boolean array representing the
sieve algorithm</link>. We may use a boolean array representing e.g. the
first 100 primes:</para>
<programlisting language="java">boolean[] nonPrimes = new boolean[100];</programlisting>
......@@ -237,9 +237,9 @@ value | t| t| f| f| t| f| t| f| t| t| t| f| t| f| t ...</programlisting>
<para>Since we intend to deal with a large number <code
xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html#MAX_VALUE">Integer.MAX_VALUE</code>
of values we only consider odd values since even numbers are never prime
except for the value 2. Thus 0 will represent 1, 1 will represent 2 and
n will represent 2 * n + 1:</para>
of values (rather than just 100 ) we only consider odd values since even
numbers are never prime except for the value 2. Thus 0 will represent 1,
1 will represent 2 and n will represent 2 * n + 1:</para>
<programlisting language="non">Index | 0| 1| 2| 3| 4| 5| 6| 7| ...
-----------+--+--+--+--+--+---+---+---+ ...
......@@ -283,8 +283,11 @@ value | f| f| f| f| t| f| f| t| ...</programlisting>
<tip>
<para>Decompose the <link
xlink:href="https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes#Euler.27s_Sieve">Euler
sieve algorithm</link> into smaller tasks and write appropriate
tests.</para>
sieve algorithm</link> into smaller tasks and write appropriate tests.
Start with small <code>limit</code> values (like 20) and extend to
<code
xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html#MAX_VALUE">Integer.MAX_VALUE</code>
step by step.</para>
</tip>
<para>Once you've finished implementing the sieve continue by
......@@ -358,7 +361,7 @@ public class PrimeFrequencySet {
private final static int initialCapacity = 16;
private PrimeFrequency[] store = new PrimeFrequency[initialCapacity];
private PrimeFrequency[] store = new PrimeFrequency[initialCapacity]; // May grow due to new factors.
/**
* Searching for the existence of a {@link PrimeFrequency} with a matching
......@@ -423,7 +426,16 @@ public class PrimeFrequencySet {
<para>This allows for decomposing arbitrary <code>int</code> values into
their prime factors. We show a unit test example:</para>
<programlisting language="java"> PrimeFrequencySet pfs = sieve.getPrimeFactors(12); <co
<programlisting language="java">/**
* Prime factor decomposition.
*/
public class FactorTest {
final Sieve sieve = new Sieve(100000);
@Test
public void test2 () {
PrimeFrequencySet pfs = sieve.getPrimeFactors(12); <co
linkends="sd1ListingTestPrimeFactorDecompose-1"
xml:id="sd1ListingTestPrimeFactorDecompose-1-co"/>
Assert.assertEquals(2, pfs.getLength()); <co
......@@ -434,7 +446,9 @@ public class PrimeFrequencySet {
xml:id="sd1ListingTestPrimeFactorDecompose-3-co"/>
Assert.assertEquals(new PrimeFrequency(3, 1), pfs.get(1)); <co
linkends="sd1ListingTestPrimeFactorDecompose-4"
xml:id="sd1ListingTestPrimeFactorDecompose-4-co"/></programlisting>
xml:id="sd1ListingTestPrimeFactorDecompose-4-co"/>
}
}</programlisting>
<calloutlist>
<callout arearefs="sd1ListingTestPrimeFactorDecompose-1-co"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment