go
method. Consider an example, the LastOfN
star:
LastOfN
star discards the first N-1 particles from the input
porthole and routes the last one to the output
porthole . The value N is read from the control
input. Since the control data varies, the number of particles to read from the input
porthole is variable, as expected for a DDF star. We can specify that the input
porthole is dynamic by setting the num
field of the input
declaration to be 0 using the preprocessor format:
waitFor
method of the DDFStar
class (actually, it is defined in the base class, DynDFStar
). The waitFor
method takes a porthole as an argument, and an optional integer as a second argument. It indicates that the star should fire when amount of data specified by the integer (default is 1) is available on the specified port. In the above example, the setup
method specifies that the star should first wait for a control
input. When a control
input arrives, the go
method reads the control value, and uses waitFor
to specify that the star should fire next when the specified number of inputs have arrived at input
. The private member readyToGo
is used to keep track of which input we are waiting for. The line
num
) to be consumed.The next example is a DDF star with a dynamic output porthole: a
DownCounter
star.
DownCounter
star has a dynamic output
porthole that will generate the down-counter sequence of integer data starting from the value read through the input
porthole. The code in the go
method is self-explanatory.It is possible, if a bit strange, for a star to alternate between SDF-like behavior and DDF-like behavior. To assert that its next firing should be under SDF rules, the star calls. The following example shows a star that uses the same input for control and data. An integer input specifies the number of particles that will be consumed on the next firing. After these particles have been consumed, the star reverts to SDF behavior to collect the next control input. In the following,
readyToGo
and num
are private integers.
clearWaitPort()
in the setup method, the star begins as an SDF star. It consumes one data, stores its value in num
, and issues a waitFor
command. This changes its behavior to DDF and specifies the number of input tokens that are required. On the next firing, it will read num
input tokens and copy them to the output, and then it will revert to SDF behavior.