RZ

01: // LocalScanMMap.cc # the actual synthesize algorithm
02:
03: #include <cstring>
04: #include <vector>
05:
06: #include "LocalScan.hh"
07: #include "MMap.hh"
08:
09: // ######## mmapped version is very simple ########
10:
11: void RZ::Scanner::scan_mmap(int const givenfd)
12: {
13:     unsigned int const givensize = given_size(givenfd);
14:     if (givensize < block_size) return;
15:     char const * const givenmmap = fd_memory_map(
16:         givenfd, givensize, false, "given file for scan");
17:
18:     std::vector< char > buffer(block_size);
19:     char * const bufferdata = &buffer[ 0 ];
20:
21:     unsigned int chkc = c.checksum32(givenmmap);
22:     char const *back = givenmmap;
23:     char const *next = givenmmap + block_size;
24:     char const * const nextend = givenmmap + givensize;
25:     for (;;) {
26:         Range range = fast_range(chkc);
27:         if (has_more(range)) {
28:             // mmap might change under me so buffer block, recheck and continue
29:             std::memcpy(bufferdata, back, block_size);
30:             if (c.checksum32(bufferdata) == range.first->sig_c) {
31:                 // add a non-overlapping-matches heuristic
32:                 // fast-forward over the unlikely
33:                 if (check_more(range, bufferdata)) {
34:                     back += block_size;
35:                     next += block_size;
36:                     if (next > nextend) break;
37:                     chkc = c.checksum32(back);
38:                     continue;
39:                 }
40:             }
41:         }
42:         if (next == nextend) break;
43:         chkc = c.rollingsum(chkc, *back, *next);
44:         ++back;
45:         ++next;
46:     }
47: }
48:
49: // LocalScanMMap.cc # the actual synthesize algorithm