hash: put checksum functions into util:#️⃣:

This commit is contained in:
Danny Robson 2016-06-17 15:56:14 +10:00
parent aeba9033e0
commit 51487cd34e
6 changed files with 39 additions and 23 deletions

View File

@ -21,18 +21,21 @@
static const unsigned MODULUS = 65521; static const unsigned MODULUS = 65521;
//-----------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////
uint32_t uint32_t
adler32 (const void* restrict _data, size_t _size) util::hash::adler32 (const void* restrict _data, size_t _size)
{ {
return adler32 (static_cast<const uint8_t*> (_data), return adler32 (
static_cast<const uint8_t*> (_data) + _size); static_cast<const uint8_t*> (_data),
static_cast<const uint8_t*> (_data) + _size
);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
uint32_t uint32_t
adler32 (const uint8_t *first, const uint8_t *last) util::hash::adler32 (const uint8_t *first, const uint8_t *last)
{ {
return fletcher<32, MODULUS, 1, 0> (first, last - first); return fletcher<32, MODULUS, 1, 0> (first, last - first);
} }

View File

@ -20,7 +20,9 @@
#include <cstdint> #include <cstdint>
#include <cstdlib> #include <cstdlib>
extern uint32_t adler32 (const void* restrict, size_t); namespace util { namespace hash {
extern uint32_t adler32 (const uint8_t *first, const uint8_t *last); uint32_t adler32 (const void* restrict, size_t);
uint32_t adler32 (const uint8_t *first, const uint8_t *last);
} }
#endif #endif

View File

@ -21,8 +21,10 @@
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
uint16_t uint16_t
bsdsum (const uint8_t *const restrict first, const uint8_t *const restrict last) util::hash::bsdsum (
{ const uint8_t *const restrict first,
const uint8_t *const restrict last
) {
CHECK_LE (first, last); CHECK_LE (first, last);
uint16_t accum = 0; uint16_t accum = 0;
@ -38,7 +40,7 @@ bsdsum (const uint8_t *const restrict first, const uint8_t *const restrict last)
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
uint16_t uint16_t
bsdsum (const void *restrict data, size_t size) util::hash::bsdsum (const void *restrict data, size_t size)
{ {
return bsdsum ( return bsdsum (
static_cast<const uint8_t*> (data), static_cast<const uint8_t*> (data),

View File

@ -14,13 +14,15 @@
* Copyright 2011 Danny Robson <danny@nerdcruft.net> * Copyright 2011 Danny Robson <danny@nerdcruft.net>
*/ */
#ifndef __UTIL_BSDSUM_HPP #ifndef __UTIL_HASH_BSDSUM_HPP
#define __UTIL_BSDSUM_HPP #define __UTIL_HASH_BSDSUM_HPP
#include <cstdint> #include <cstdint>
#include <cstdlib> #include <cstdlib>
uint16_t bsdsum (const void *restrict data, size_t bytes); namespace util { namespace hash {
uint16_t bsdsum (const uint8_t *restrict first, const uint8_t *restrict last); uint16_t bsdsum (const void *restrict data, size_t bytes);
uint16_t bsdsum (const uint8_t *restrict first, const uint8_t *restrict last);
} }
#endif #endif

View File

@ -20,15 +20,21 @@
#include "../debug.hpp" #include "../debug.hpp"
///////////////////////////////////////////////////////////////////////////////
uint32_t uint32_t
crc32 (const uint8_t *restrict first, const uint8_t *restrict last) noexcept util::hash::crc32 (
{ const uint8_t *restrict first,
not_implemented (); const uint8_t *restrict last
) noexcept {
CHECK_LE (first, last);
return crc32 (first, last - first);
} }
//-----------------------------------------------------------------------------
uint32_t uint32_t
crc32 (const void *restrict, size_t) { util::hash::crc32 (const void *restrict, size_t) {
not_implemented (); not_implemented ();
/* /*

View File

@ -14,14 +14,15 @@
* Copyright 2011 Danny Robson <danny@nerdcruft.net> * Copyright 2011 Danny Robson <danny@nerdcruft.net>
*/ */
#ifndef __UTIL_CRC_HPP #ifndef __UTIL_HASH_CRC_HPP
#define __UTIL_CRC_HPP #define __UTIL_HASH_CRC_HPP
#include <cstdint> #include <cstdint>
#include <cstdlib> #include <cstdlib>
uint32_t crc32 (const void *restrict data, size_t bytes); namespace util { namespace hash {
uint32_t crc32 (const uint8_t *restrict first, const uint8_t *restrict last) noexcept; uint32_t crc32 (const void *restrict data, size_t bytes);
uint32_t crc32 (const uint8_t *restrict first, const uint8_t *restrict last) noexcept;
} }
#endif #endif