~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/algorithm/crc32.h

  • Committer: Olaf van der Spek
  • Date: 2011-08-22 19:14:08 UTC
  • mto: This revision was merged to the branch mainline in revision 2421.
  • Revision ID: olafvdspek@gmail.com-20110822191408-wg2dowhggydj6cf9
Refactor

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
# include <sys/types.h>
38
38
#endif
39
39
 
40
 
namespace drizzled
41
 
{
42
 
namespace algorithm
43
 
{
 
40
namespace drizzled {
 
41
namespace algorithm {
44
42
 
45
 
static const uint32_t crc32tab[256] = {
 
43
static const uint32_t crc32tab[256] = 
 
44
{
46
45
  0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
47
46
  0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
48
47
  0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
112
111
template <class T>
113
112
uint32_t crc32(T key, size_t key_length)
114
113
{
115
 
  uint64_t x;
116
114
  uint32_t crc= UINT32_MAX;
117
115
 
118
 
  for (x= 0; x < key_length; x++)
 
116
  for (size_t x= 0; x < key_length; x++)
119
117
    crc= (crc >> 8) ^ crc32tab[(crc ^ static_cast<uint8_t>(key[x])) & 0xff];
120
118
 
121
119
  return ~crc;
123
121
 
124
122
} /* namespace algorithm */
125
123
} /* namespace drizzled */
126