From 8824331c4b8dbc4a652bdf76e0450e8a1b7b53d1 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Mon, 20 Jun 2016 16:48:17 +1000 Subject: [PATCH] hash/crc: convert to object style accumulator --- hash/crc.cpp | 37 ++++++++++++++++++++++++++++--------- hash/crc.hpp | 16 ++++++++++++++-- 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/hash/crc.cpp b/hash/crc.cpp index 59c3c34b..436771d7 100644 --- a/hash/crc.cpp +++ b/hash/crc.cpp @@ -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 (); } diff --git a/hash/crc.hpp b/hash/crc.hpp index 6b7b175d..222f0119 100644 --- a/hash/crc.hpp +++ b/hash/crc.hpp @@ -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