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 "./crc.hpp"
#include "../endian.hpp"
#include "../debug.hpp" #include "../debug.hpp"
using util::hash::crc32;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
uint32_t void
util::hash::crc32 ( crc32::reset (void)
const uint8_t *restrict first, { ; }
const uint8_t *restrict last
) noexcept {
///////////////////////////////////////////////////////////////////////////////
void
crc32::update (const uint8_t *restrict first,
const uint8_t *restrict last) noexcept
{
CHECK_LE (first, last); CHECK_LE (first, last);
return crc32 (first, last - first); return update (first, last - first);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
uint32_t void
util::hash::crc32 (const void *restrict, size_t) noexcept { crc32::update (const void *restrict, size_t) noexcept
{
not_implemented (); 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 { namespace util { namespace hash {
uint32_t crc32 (const void *restrict data, size_t bytes) noexcept; class crc32 {
uint32_t crc32 (const uint8_t *restrict first, const uint8_t *restrict last) noexcept; 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 #endif