RZ

01: // LocalScanStream.cc # the actual synthesize algorithm
02:
03: #include <unistd.h>
04:
05: #include <cstring>
06:
07: #include "LocalScan.hh"
08: #include "LocalReadCheck.hh"
09:
10: // ######## non-mmapped version is brain warping ########
11:
12: void RZ::Scanner::scan_stream(int const givenfd)
13: {
14:     unsigned int const bufsize = block_size * 2;
15:     std::vector< char > givenbuf(bufsize + block_size - 1);
16:
17:     unsigned int chkc = 0;
18:     int nin = -block_size;
19:     read_check(this, chkc, nin, givenfd, &givenbuf[ 0 ], bufsize);
20:     if (nin) return;
21:     for (
22:         unsigned int backi = 0, bin = block_size, nexti = block_size; //nin = 0
23:
24:         nin || (nin = read(givenfd, &givenbuf[ nexti ], block_size));
25:
26:         bin || backi < bufsize || (backi -= bufsize),
27:         backi < nexti && (bin = block_size),
28:         nexti < bufsize || (nexti -= bufsize)
29:     ) for (; bin > 0 && nin > 0; ++backi, ++nexti, --bin, --nin) {
30:         Range range = fast_range(chkc);
31:         if (has_more(range)) {
32:             char *back = &givenbuf[ backi ];
33:             if (nexti < backi) {
34:                 if (backi < bufsize) {
35:                     std::memcpy(
36:                         back + bin, back + bin - bufsize, block_size - bin);
37:                     bin = block_size;
38:                 }
39:                 else {
40:                     std::memcpy(back - bufsize, back, bin);
41:                     backi -= bufsize;
42:                     back -= bufsize;
43:                     bin = block_size;
44:                 }
45:             }
46:             check_more(range, back);
47:         }
48:         chkc = c.rollingsum(chkc, givenbuf[ backi ], givenbuf[ nexti ]);
49:     }
50: }
51:
52: // LocalScanStream.cc # the actual synthesize algorithm