engineIDulong.cc

Go to the documentation of this file.
00001 // $Id:$
00002 // -*- C++ -*-
00003 //
00004 // -----------------------------------------------------------------------
00005 //                             HEP Random
00006 //                      --- engineIDulong ---
00007 //                      function implementation file
00008 // -----------------------------------------------------------------------
00009 //
00010 // =======================================================================
00011 // Mark Fischler  - Created: Mar. 8, 2005
00012 // =======================================================================
00013 
00014 #include <string>
00015 #include <vector>
00016 
00017 namespace CLHEP {
00018 
00019 static std::vector<unsigned long> gen_crc_table() {
00020   /* generate the table of CRC remainders for all possible bytes */
00021   static const unsigned long POLYNOMIAL = 0x04c11db7UL;
00022   std::vector<unsigned long> crc_table;
00023   for ( unsigned long i = 0;  i < 256;  ++i ) {
00024     unsigned long crc = i << 24;
00025     for ( int j = 0;  j < 8;  j++ ) {
00026       if ( crc & 0x80000000UL ) {
00027         crc = ( ( crc << 1 ) ^ POLYNOMIAL ) & 0xffffffffUL;
00028       } else {
00029         crc = ( crc << 1 ) & 0xffffffffUL; 
00030       }
00031     }
00032     crc_table.push_back(crc);
00033   }
00034   return crc_table;
00035 }
00036 
00037 unsigned long crc32ul(const std::string & s) {
00038   static std::vector<unsigned long> crc_table =  gen_crc_table();
00039   unsigned long crc = 0;
00040   int end = s.length();
00041   for (int j = 0; j != end; ++j) {
00042     int i = ( (int) ( crc >> 24) ^ s[j] ) & 0xff;
00043     crc = ( ( crc << 8 ) ^ crc_table[i] ) & 0xffffffffUL;
00044   }
00045   return crc;
00046 }
00047 
00048 }  // namespace CLHEP
00049 

Generated on Mon May 27 17:47:34 2013 for Geant4 by  doxygen 1.4.7