RZ

01: // ExtractLocalLookup.cc # the actual synthesize algorithm
02:
03: #include <cstdio>
04:
05: #include "RZError.hh"
06: #include "RZMagic.hh"
07: #include "RZNetOrder.hh"
08: #include "ExtractLocalLookup.hh"
09:
10: /****** extract checksum initializers and block size in bytes ******/
11:
12: RZ::LocalSums::LocalSums(struct RZWrapper const &rzwrapper)
13: :
14:     Sums(rzwrapper)
15: {
16:     AssertionError::what_not("No blocks to scan for!", rzwrapper.n_blks == 0);
17:     block_size = rzwrapper.block_size;
18: }
19:
20: RZ::LocalSums::LocalSums(struct IntermediateWrapper const &interwrap)
21: :
22:     Sums(net4in< RZModuli >(interwrap.rz_header + 16))
23: {
24:     AssertionError::what_not("No blocks to scan for!", interwrap.n_blks == 0);
25:     block_size = net_in(interwrap.rz_header + 28) >> 3;
26: }
27:
28: /****** extract lookup table from rz wrapper ******/
29:
30: void RZ::LookupTable::extract_lookup_table(
31:     RZSignatureTable::Signature const & sigtab)
32: {
33:     RZSignatureTable::Signature::const_iterator signatures = sigtab.begin();
34:
35:     for (unsigned int i = 0, nblks = sigtab.size(); i < nblks; ++i) {
36:         struct LookupEntry e;
37:         e.sig_a = signatures[i].sig_a;
38:         e.sig_b = signatures[i].sig_b;
39:         e.sig_c = signatures[i].sig_c;
40:         e.bk_i = i;
41:         lookup_table.push_back(e);
42:     }
43: }
44:
45: void RZ::LookupTable::extract_lookup_table(
46:     unsigned int const nblks, std::FILE * const RZWRAPPER)
47: {
48:     // read all the (nblks * 16) bytes of the signature table
49:     for (unsigned int i = 0; i < nblks; ++i) {
50:         char buffer[ 16 ];
51:         {
52:             int n = std::fread(buffer, 1, 16, RZWRAPPER);
53:             ScanError::what_if("Can't read rz signature table!", n != 16);
54:         }
55:         {
56:             struct LookupEntry e;
57:             e.sig_a = net_in(buffer + 0); // only use the 12 bytes
58:             e.sig_b = net_in(buffer + 4); // of signature from
59:             e.sig_c = net_in(buffer + 8); // the rz sig tab
60:             e.bk_i = i;   // need a ref to original block after sort
61:             lookup_table.push_back(e);
62:         }
63:     }
64: }
65:
66: // ExtractLookupTable.cc # the actual synthesize algorithm