accumulator

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

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

Examples

1 scope(failure) {writefln("Unittest failure :%s(%s)", __FILE__, __LINE__); stdout.flush();}
2 scope(success) {writefln("Unittest success :%s(%s)", __FILE__, __LINE__); stdout.flush();}
3 
4 auto arr1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].repeatStream;
5 auto acc = accumulator!4(arr1, new int[14]);
6 static assert(isBufferedInputStream!(typeof(acc)));
7 
8 int[] buf = new int[3];
9 assert(!acc.empty || !acc.fetch());
10 assert(acc.read(buf) == [0+1+2+3, 4+5+6+7, 8+9+0+1]);
11 assert(!acc.empty || !acc.fetch());
12 assert(acc.read(buf) == [2+3+4+5, 6+7+8+9, 0+1+2+3]);

Meta