1 #include <ail/crc32.hpp>
2 #include <ail/array.hpp>
8 ulong crc32_table
[256];
10 struct initialise_crc32_table
12 initialise_crc32_table()
14 char const polynomial_terms
[] =
17 10, 11, 12, 16, 22, 23, 26
20 ulong polynomial_pattern
= 0;
21 for(std::size_t i
= 0; i
< sizeof(polynomial_terms
); ++i
)
23 ulong shifts
= 31 - polynomial_terms
[i
];
24 polynomial_pattern
|= 1 << shifts
;
27 for(std::size_t i
= 0; i
< ail::countof(crc32_table
); ++i
)
29 ulong new_table_entry
= static_cast<ulong
>(i
);
30 for(int j
= 0; j
< 8; ++j
)
32 bool first_bit_was_set
= (new_table_entry
& 1);
33 new_table_entry
>>= 1;
34 if(first_bit_was_set
== true)
35 new_table_entry
^= polynomial_pattern
;
36 crc32_table
[i
] = new_table_entry
;
49 crc32::crc32(char const * data
, std::size_t size
):
55 ulong
crc32::hash(char const * data
, std::size_t size
)
60 ulong index
= (*data
^ sum
) & 0xff;
61 ulong shifted_sum
= sum
>> 8;
62 sum
= crc32_table
[index
] ^ shifted_sum
;
70 ulong
crc32::checksum() const