RZ

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