Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:13:13

0001 #include "FWCore/Utilities/interface/Adler32Calculator.h"
0002 
0003 namespace cms {
0004 
0005   //-------------------------------------------------------
0006   // the following is adapted from
0007   // http://en.wikipedia.org/wiki/Adler-32
0008   //-------------------------------------------------------
0009 
0010   void Adler32(char const* data, size_t len, uint32_t& a, uint32_t& b) {
0011     /* data: Pointer to the data to be summed; len is in bytes */
0012 
0013 #define MOD_ADLER 65521
0014 
0015     unsigned char const* ptr = static_cast<unsigned char const*>(static_cast<void const*>(data));
0016     while (len > 0) {
0017       size_t tlen = (len > 5552 ? 5552 : len);
0018       len -= tlen;
0019       do {
0020         a += *ptr++;
0021         b += a;
0022       } while (--tlen);
0023 
0024       a %= MOD_ADLER;
0025       b %= MOD_ADLER;
0026     }
0027 
0028 #undef MOD_ADLER
0029   }
0030 
0031   uint32_t Adler32(char const* data, size_t len) {
0032     /* data: Pointer to the data to be summed; len is in bytes */
0033     uint32_t a = 1, b = 0;
0034     Adler32(data, len, a, b);
0035     return (b << 16) | a;
0036   }
0037 }  // namespace cms