hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
CRC64.cpp
Go to the documentation of this file.
1 #include <CRC64.h>
2 bool CRC64::calculated = false;
3 u_int64_t CRC64::crc_table[256];
5 {
6  if(!calculated)
7  {
8  calculated = true;
9  calcCrcTable();
10  }
11 }
12 
13 
15 {
16 }
17 
18 
19 u_int64_t CRC64::calc(const char *data, unsigned int size)
20 {
21  u_int64_t crc = 0;
22  for (unsigned int i = 0; i < size; i++)
23  {
24  crc = crc_table[(crc ^ (data[i])) & 0xFF] ^ (crc >> 8);
25  }
26  crc = ~crc;
27  return crc;
28 }
29 
30 
31 void CRC64::calcCrcTable()
32 {
33  const u_int64_t CRCPOLY = 0x42F0E1EBA9EA3693ULL;
34  //0xd800000000000000ULL;
35  register u_int64_t t;
36  for (register unsigned int i = 0; i < 256; i++)
37  {
38  t = i;
39  for (register int j = 8; j > 0; j--)
40  {
41  if (t & 1)
42  t = (t >> 1) ^ CRCPOLY;
43  else
44  t >>= 1;
45  }
46  crc_table[i] = t;
47  }
48 }