CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/FWCore/Utilities/src/Adler32Calculator.cc

Go to the documentation of this file.
00001 #include "FWCore/Utilities/interface/Adler32Calculator.h"
00002 
00003 namespace cms {
00004 
00005   //-------------------------------------------------------
00006   // the following is adapted from 
00007   // https://en.wikipedia.org/wiki/Adler-32
00008   //-------------------------------------------------------
00009   
00010   void
00011   Adler32(char const* data, size_t len, uint32_t& a, uint32_t& b) {
00012    /* data: Pointer to the data to be summed; len is in bytes */
00013   
00014     #define MOD_ADLER 65521
00015    
00016     unsigned char const* ptr = static_cast<unsigned char const*>(static_cast<void const*>(data));
00017     while (len > 0) {
00018       size_t tlen = (len > 5552 ? 5552 : len);
00019       len -= tlen;
00020       do {
00021         a += *ptr++;
00022         b += a;
00023       } while (--tlen);
00024       
00025       a %= MOD_ADLER;
00026       b %= MOD_ADLER;
00027     }
00028   
00029     #undef MOD_ADLER
00030   }
00031   
00032   uint32_t
00033   Adler32(char const* data, size_t len) {
00034    /* data: Pointer to the data to be summed; len is in bytes */
00035     uint32_t a = 1, b = 0;
00036     Adler32(data, len, a, b);
00037     return (b << 16) | a;
00038   }
00039 }