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;
//-----------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////
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),
static_cast<const uint8_t*> (_data) + _size);
return adler32 (
static_cast<const uint8_t*> (_data),
static_cast<const uint8_t*> (_data) + _size
);
}
//-----------------------------------------------------------------------------
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);
}

View File

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

View File

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

View File

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

View File

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

View File

@ -14,14 +14,15 @@
* Copyright 2011 Danny Robson <danny@nerdcruft.net>
*/
#ifndef __UTIL_CRC_HPP
#define __UTIL_CRC_HPP
#ifndef __UTIL_HASH_CRC_HPP
#define __UTIL_HASH_CRC_HPP
#include <cstdint>
#include <cstdlib>
namespace util { namespace hash {
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