CMSDK
2.0.1
|
compute CRC32 hash, based on Intel's Slicing-by-8 algorithm More...
#include <crc32.h>
Public Types | |
enum | { HashBytes = 4 } |
hash is 4 bytes long | |
Public Member Functions | |
CRC32 () | |
same as reset() | |
std::string | operator() (const void *data, size_t numBytes) |
compute CRC32 of a memory block | |
std::string | operator() (const std::string &text) |
compute CRC32 of a string, excluding final zero | |
void | add (const void *data, size_t numBytes) |
add arbitrary number of bytes | |
std::string | getHash () |
return latest hash as 8 hex characters | |
void | getHash (unsigned char buffer[HashBytes]) |
return latest hash as bytes | |
void | reset () |
restart | |
compute CRC32 hash, based on Intel's Slicing-by-8 algorithm
Usage: CRC32 crc32; std::string myHash = crc32("Hello World"); // std::string std::string myHash2 = crc32("How are you", 11); // arbitrary data, 11 bytes
or in a streaming fashion:
CRC32 crc32; while (more data available) crc32.add(pointer to fresh data, number of new bytes); std::string myHash3 = crc32.getHash(); Note: You can find code for the faster Slicing-by-16 algorithm on my website, too: http://create.stephan-brumme.com/crc32/ Its unrolled version is about twice as fast but its look-up table doubled in size as well.