Geant4  10.03
engineIDulong.cc
Go to the documentation of this file.
1 // $Id:$
2 // -*- C++ -*-
3 //
4 // -----------------------------------------------------------------------
5 // HEP Random
6 // --- engineIDulong ---
7 // function implementation file
8 // -----------------------------------------------------------------------
9 //
10 // =======================================================================
11 // Mark Fischler - Created: Mar. 8, 2005
12 // =======================================================================
13 
14 #include <string>
15 #include <vector>
16 
17 namespace CLHEP {
18 
19 static std::vector<unsigned long> gen_crc_table() {
20  /* generate the table of CRC remainders for all possible bytes */
21  static const unsigned long POLYNOMIAL = 0x04c11db7UL;
22  std::vector<unsigned long> crc_table;
23  for ( unsigned long i = 0; i < 256; ++i ) {
24  unsigned long crc = i << 24;
25  for ( int j = 0; j < 8; j++ ) {
26  if ( crc & 0x80000000UL ) {
27  crc = ( ( crc << 1 ) ^ POLYNOMIAL ) & 0xffffffffUL;
28  } else {
29  crc = ( crc << 1 ) & 0xffffffffUL;
30  }
31  }
32  crc_table.push_back(crc);
33  }
34  return crc_table;
35 }
36 
37 unsigned long crc32ul(const std::string & s) {
38  static const std::vector<unsigned long> crc_table = gen_crc_table();
39  unsigned long crc = 0;
40  int end = s.length();
41  for (int j = 0; j != end; ++j) {
42  int i = ( (int) ( crc >> 24) ^ s[j] ) & 0xff;
43  crc = ( ( crc << 8 ) ^ crc_table[i] ) & 0xffffffffUL;
44  }
45  return crc;
46 }
47 
48 } // namespace CLHEP
49 
static std::vector< unsigned long > gen_crc_table()
static constexpr double s
Definition: G4SIunits.hh:169
unsigned long crc32ul(const std::string &s)