hash/crc: convert to object style accumulator

This commit is contained in:
Danny Robson 2016-06-20 16:48:17 +10:00
parent 8333cad8cc
commit 8824331c4b
2 changed files with 42 additions and 11 deletions

View File

@ -16,25 +16,32 @@
#include "./crc.hpp"
#include "../endian.hpp"
#include "../debug.hpp"
using util::hash::crc32;
///////////////////////////////////////////////////////////////////////////////
uint32_t
util::hash::crc32 (
const uint8_t *restrict first,
const uint8_t *restrict last
) noexcept {
void
crc32::reset (void)
{ ; }
///////////////////////////////////////////////////////////////////////////////
void
crc32::update (const uint8_t *restrict first,
const uint8_t *restrict last) noexcept
{
CHECK_LE (first, last);
return crc32 (first, last - first);
return update (first, last - first);
}
//-----------------------------------------------------------------------------
uint32_t
util::hash::crc32 (const void *restrict, size_t) noexcept {
void
crc32::update (const void *restrict, size_t) noexcept
{
not_implemented ();
/*
@ -67,3 +74,15 @@ util::hash::crc32 (const void *restrict, size_t) noexcept {
}
*/
}
//-----------------------------------------------------------------------------
void
crc32::finish (void)
{ not_implemented (); }
//-----------------------------------------------------------------------------
typename crc32::digest_t
crc32::digest (void) const
{ not_implemented (); }

View File

@ -23,8 +23,20 @@
///////////////////////////////////////////////////////////////////////////////
namespace util { namespace hash {
uint32_t crc32 (const void *restrict data, size_t bytes) noexcept;
uint32_t crc32 (const uint8_t *restrict first, const uint8_t *restrict last) noexcept;
class crc32 {
public:
using digest_t = uint32_t;
void reset (void);
void update (const void *restrict data, size_t bytes) noexcept;
void update (const uint8_t *restrict first, const uint8_t *restrict last) noexcept;
void finish (void);
digest_t digest (void) const;
};
} }
#endif