accumulator

積分器です。 たとえば、連続する少数の個数のサンプルの和を取るような用途に適しています。

  1. auto accumulator(size_t integN)
  2. auto accumulator(Sg sg, size_t bufSize)
    accumulator
    (
    size_t N
    Sg
    )
    (
    Sg sg
    ,
    size_t bufSize = 1024 * 1024
    )
  3. auto accumulator(Sg sg, E[] buffer)

Examples

scope(failure) {writefln("Unittest failure :%s(%s)", __FILE__, __LINE__); stdout.flush();}
scope(success) {writefln("Unittest success :%s(%s)", __FILE__, __LINE__); stdout.flush();}

auto arr1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].repeatStream;
auto acc = accumulator!4(arr1, new int[14]);
static assert(isBufferedInputStream!(typeof(acc)));

int[] buf = new int[3];
assert(!acc.empty || !acc.fetch());
assert(acc.read(buf) == [0+1+2+3, 4+5+6+7, 8+9+0+1]);
assert(!acc.empty || !acc.fetch());
assert(acc.read(buf) == [2+3+4+5, 6+7+8+9, 0+1+2+3]);

Meta