hash: put checksum functions into util:#️⃣:
This commit is contained in:
parent
aeba9033e0
commit
51487cd34e
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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),
|
||||
|
@ -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>
|
||||
|
||||
uint16_t bsdsum (const void *restrict data, size_t bytes);
|
||||
uint16_t bsdsum (const uint8_t *restrict first, const uint8_t *restrict last);
|
||||
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
|
||||
|
14
hash/crc.cpp
14
hash/crc.cpp
@ -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 ();
|
||||
|
||||
/*
|
||||
|
11
hash/crc.hpp
11
hash/crc.hpp
@ -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>
|
||||
|
||||
uint32_t crc32 (const void *restrict data, size_t bytes);
|
||||
uint32_t crc32 (const uint8_t *restrict first, const uint8_t *restrict last) noexcept;
|
||||
|
||||
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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user