scaleex-scale.html
doubleCode_samples.html
mergeex-merge.html
sumex-sum.html
dxex-dx.html
wiring functionsex-msfl.html
histoex-histo.html
RLE
convolex-conv.html
higher order
actorex-fmap.html
 

type $t rl<s> = RL of $t * unsigned<s>;


actor rle (n: int)

  in (i:$t)

  out (o:$t rl<n>)

var st : {Init,Run} = Init

var c : $t            -- current symbol

var k : unsigned<n>   -- length of current run

rules

| (st:Init, i:v)         -> (st:Init, c:v, k:1)

| (st:Run, i:v) when v=c -> (st:Run, k:k+1)

| (st:Run, i:v)          -> (st:Run, o:RL(c,k), c:v, k:1)

;

This actor computes the run-length encoding (RLE) of a sequence of values.

For example, if the stream on input i is : 

    1 1 1 6 6 6 6 6 8 8 8 8 ...

then the stream on output o will be :

    RL(1,3) RL(6,5) RL(8,4) ...

Run-lengths are encoded using the user-defined algebraic rl.

t RL<n> is the type of run-lengths where t is the type of the sequence elements and n the number of bits used for coding the length.


Once the first value has been read on input i (after first rule has been activated and the state variable st set to Run), the behavior of the actor is described by rules 2 and 3, which can be read as follows :

  1. if the next value (v) read on input i is equal to the value of the current run (stored in local variable c), then increment the run length counter k (rule #2)

  2. otherwise, output the run descriptor on output o (value c and length k), set c to the new value read on input i and counter k to 1 (rule #3)