Code Examples
A repository of 155 code examples for BeepBeep
|
Use the SlicerMap to perform a computation on multiple subsets of an input stream. More...
Static Public Member Functions | |
static void | main (String[] args) |
Use the SlicerMap to perform a computation on multiple subsets of an input stream.
The principle of the SlicerMap
processor is to "slice" an input stream into multiple sub-streams. For this, a function, called the slicing function, is evaluated on each input event. The value of that function decides what sub-stream that event belongs to. A different instance of a processor is created for each possible value of the slicing function, and the input event is pushed to the corresponding processor.
The slicer keeps an associative map; keys correspond to values of the slicing function, and values are the last event produced by the corresponding processor. Every time an event is received, it returns as its output the updated map.
In this program, the slicing function is the identity, and the processor given to the slicer is a simple counter that increments every time an event is received. Since there is one such counter for each different input event, the slicer effectively maintains the count of how many times each value has been seen in its input stream. Graphically, this can be represented as:
The expected output of this program is:
{1=1.0} {1=1.0, 6=1.0} {1=1.0, 4=1.0, 6=1.0} {1=1.0, 3=1.0, 4=1.0, 6=1.0} {1=1.0, 2=1.0, 3=1.0, 4=1.0, 6=1.0} {1=2.0, 2=1.0, 3=1.0, 4=1.0, 6=1.0} {1=2.0, 2=1.0, 3=1.0, 4=1.0, 6=1.0, 9=1.0} …
Definition at line 75 of file SlicerSimple.java.
|
static |
We first setup a stream of numbers to be used as a source
Definition at line 77 of file SlicerSimple.java.