修订版 | 924a35e5b4bb827cf6150bfef8ef48906e1f7f6f (tree) |
---|---|
时间 | 2023-01-14 06:56:08 |
作者 | Albert Mietus < albert AT mietus DOT nl > |
Commiter | Albert Mietus < albert AT mietus DOT nl > |
asis DRAFT
@@ -1,4 +1,4 @@ | ||
1 | -.. include:: /std/localtoc.irst | |
1 | +.. .. include:: /std/localtoc.irst | |
2 | 2 | |
3 | 3 | .. _Castle-TheSieve: |
4 | 4 |
@@ -12,10 +12,10 @@ | ||
12 | 12 | |
13 | 13 | |
14 | 14 | To show some features of CCastle, I use *‘the sieve’*, short for the `Sieve of Eratosthenes |
15 | - <https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes>`__. An old, well known, algorithm to find prime numbers. with | |
15 | + <https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes>`__. An old, well known, algorithm to find prime numbers; with | |
16 | 16 | impliciet concurrency. |
17 | 17 | |
18 | - With an almost trivial implementation, many “CC concepts” are shown. In only a handful of lines. | |
18 | + With an almost trivial implementation, many “CC concepts” can be shown. In only a handful of lines.... | |
19 | 19 | |
20 | 20 | The design |
21 | 21 | ********** |
@@ -29,9 +29,10 @@ | ||
29 | 29 | ========================= |
30 | 30 | |
31 | 31 | CCastle use “components” [#not-package]_ as main decomposition. Each kind of component can be instantiated multiple |
32 | -times; which often are also called *component*. One can also use the term *element*, to denote it is one (of possible) | |
33 | -many instantiated component-types. This is very ,like *“classes” vs “objects”* [#active-class]_. | |
32 | +times; sometimes called a *element*, or also just *component*. This is very like *“classes” and “objects”* in OO | |
33 | +[#active-class]_. | |
34 | 34 | |
35 | +Let’s introduce the those components | |
35 | 36 | |
36 | 37 | Generator |
37 | 38 | --------- |
@@ -39,21 +40,22 @@ | ||
39 | 40 | This component generates just numbers, which will be tested for prime (see below). As primes are always integer bigger |
40 | 41 | then one; it output is the stream stream of numbers: 2,3,4, … |
41 | 42 | |
42 | -Sieve (parameterised) | |
43 | ---------------------- | |
43 | +Sieve (on prime) | |
44 | +---------------- | |
44 | 45 | |
45 | -We use a (growing) chain of sieve-elements. Each behavior is the same; except for the constant that it gets when | |
46 | -creating. That number is a prime; as will see below. | |
46 | +We use a (growing) chain of sieve-elements. Each one is the same; except for the sieving-constant --a already found | |
47 | +prime. That number is set when instantiating the element. | |
47 | 48 | |
48 | -Each Sieve tries to divide each incoming number to its own, already known prime-number. When the modulo isn’t zero, we | |
49 | -call it a *coprime* (relative to the already tested primes) and send downstream. When it can be divided, the number is | |
50 | -clearly not prime and ignored | |
49 | + | |
50 | +Each Sieve tries to divide each incoming number to its own, sieve-constant. When the modulo isn’t zero, we call it | |
51 | +a *coprime* (relative to the already tested primes) and send downstream. When it can be divided, the number is clearly | |
52 | +not prime and ignored | |
51 | 53 | |
52 | 54 | Finder |
53 | 55 | ------ |
54 | 56 | |
55 | 57 | Each number that comes out of the chain of sieves is a prime (that is the algorithm; see Wikipedia for details). It is |
56 | -collected by the finder. And for each found prime, an extra sieve (element) is created and added to the chain. This kind | |
58 | +collected by the finder. For each found prime, an extra sieve (element) is created and added to the chain. This kind | |
57 | 59 | of shifts the finder to the right (aka downstream) |
58 | 60 | |
59 | 61 | In some implementations that is the responsibility of the finder (therefore sometimes calls “head”). In a variant, the |
@@ -61,17 +63,31 @@ | ||
61 | 63 | |
62 | 64 | Communication |
63 | 65 | ============= |
66 | +.. include:: ./sieve-protocols-sidebar.irst | |
67 | + | |
68 | +CCastle uses “protocols” to communicate between components. There are several kind of protocols; we use the ‘event’ kind | |
69 | +here. Two ports can be connected when both use the same protocol. | |
70 | + | |
71 | +Notice, that a *protocol* is not the same as an API in most language’s. A fundamenta concept of :ref:`CC`/CCastle is the | |
72 | +strict seperation between outside and inside | |
73 | + | |
74 | + | |
75 | + | |
76 | + | |
64 | 77 | |
65 | 78 | SimpleSieve |
66 | 79 | ----------- |
67 | 80 | |
68 | -In the basic variant,we use an event-based protocol, that just hold one event (read: a message), that carries the | |
81 | +In the basic variant, we use an event-based protocol, that just hold one event (read: a message), that carries the | |
69 | 82 | integer to be tried. |
70 | 83 | |
71 | 84 | StartSieve |
72 | 85 | ---------- |
73 | 86 | |
74 | -XXXX | |
87 | +The StartSieve protocol signals to start sieving (so generating numbers), and when to stop. This “max” number is the | |
88 | +maximal number to be tried, and does not need to be a prime. | |
89 | + | |
90 | +Currently, the is no way to specify the number of primes to be found. | |
75 | 91 | |
76 | 92 | Main |
77 | 93 | **** |
@@ -5,7 +5,7 @@ | ||
5 | 5 | |
6 | 6 | ditaa |
7 | 7 | |
8 | - | | |
8 | + Max | | |
9 | 9 | V |
10 | 10 | +-------*---\ /-----------\ /-----------\ /-----------\ /-----------\ /-----------+ |
11 | 11 | | Generator | | Sieve(2) | | Sieve(3) | | Sieve(5) | : | | Finder | |
@@ -13,6 +13,6 @@ | ||
13 | 13 | | cBLU | | cGRE | | cGRE | | cGRE | | cGRE | | cPNK | |
14 | 14 | +-----------/ \-----------/ \-----------/ \-----------/ \-----------/ \---------*-+ |
15 | 15 | | |
16 | - 0 The shown (horizontal) connections all use the SimpleSieve protocol V | |
16 | + 0 The shown (horizontal) connections all use the SimpleSieve protocol V Primes | |
17 | 17 | 0 The Generator has a (in) port for the StartSieve protocol |
18 | 18 | 0 The Finder has an optional (out) port for SimpleSieve protocol |
@@ -0,0 +1,16 @@ | ||
1 | +.. -*-rst-*- | |
2 | + included in `b.TheSieve.rst` | |
3 | + | |
4 | +.. sidebar:: Sieve Protocols | |
5 | + | |
6 | + .. code-block:: ReasonML | |
7 | + | |
8 | + protocol SimpleSieve : Protocol { | |
9 | + kind: event; | |
10 | + input(int:try); | |
11 | + } | |
12 | + | |
13 | + protocol StartSieve : Protocol { | |
14 | + kind: event; | |
15 | + runTo(int:max); | |
16 | + } |