RZ

01: /****** AlgoBitwiseGF.hh / GF(2**32) Finite Field Arithmetic ******/
02:
03: #ifndef _AlgoBitwiseGF_HH
04: #define _AlgoBitwiseGF_HH 1
05:
06: #include "AlgoGF.hh"
07:
08: /****** ******* ******* ******* ******* ******* ******* ******* ******* ******/ 
09:
10: namespace Bitwise {
11:     struct Checksum32: GF::GFbinary32 {
12:         unsigned int const buflen;
13:
14:         Checksum32(int m, unsigned int nbits)
15:         : GF::GFbinary32(m), buflen(nbits >> 3) {}
16:
17:         unsigned int checksum32(char const buffer[])
18:         const {
19:             return GF::checkKBin(mod32, (unsigned char const *)buffer, buflen);
20:         }
21:
22:         unsigned int checksum32(
23:             char const buffer0[], unsigned int buflen0, char const buffer1[])
24:         const {
25:             if (buflen <= buflen0) return checksum32(buffer0);
26:             return GF::checkKBin(
27:                 mod32, (unsigned char const *)buffer1, buflen - buflen0,
28:                 GF::checkKBin(mod32, (unsigned char const *)buffer0, buflen0)
29:             );
30:         }
31:
32:         void accumulate(
33:             char const buffer[], unsigned int buflen, unsigned int &acc)
34:         {
35:             acc = GF::checkKBin(
36:                 mod32, (unsigned char const*)buffer, buflen, acc);
37:         }
38:     };
39:
40:     struct Rollingsum: Checksum32 {
41:         int const advance;
42:
43:         Rollingsum(int m, unsigned int nbits)
44:         : Checksum32(m, nbits), advance(exponentiate(2, nbits)) {}
45:
46:         unsigned int rollingsum(unsigned int chk, char out, char in)
47:         const {
48:         return GF::check8out(
49:             mod32, advance, chk, (signed char)out) ^ (unsigned char)in);
50:         }
51:     };
52:
53:     // Checksum32 const a(555777555, 65536);
54:     // Checksum32 const b(777222777, 65536);
55:     // Rollingsum const c(999555999, 65536);
56:     
57:     // Bitwise::a.checksum32(buf);
58:     // Bitwise::b.checksum32(buf);
59:     // Bitwise::c.checksum32(buf);
60:     // Bitwise::c.rollingsum(chk, out, in);
61: }
62:
63: #endif /****** AlgoBitwiseGF.hh / GF(2**32) Finite Field Arithmetic ******/