Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GoikLectures
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Goik Martin
GoikLectures
Commits
abe2e1f2
Commit
abe2e1f2
authored
9 years ago
by
Goik Martin
Browse files
Options
Downloads
Patches
Plain Diff
cosmetics
parent
07540628
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Doc/Sd1/appendix.xml
+23
-9
23 additions, 9 deletions
Doc/Sd1/appendix.xml
with
23 additions
and
9 deletions
Doc/Sd1/appendix.xml
+
23
−
9
View file @
abe2e1f2
...
...
@@ -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"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment