hash: put checksum functions into util:#️⃣:
This commit is contained in:
parent
aeba9033e0
commit
51487cd34e
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
@ -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),
|
||||||
|
@ -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
|
||||||
|
14
hash/crc.cpp
14
hash/crc.cpp
@ -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 ();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
11
hash/crc.hpp
11
hash/crc.hpp
@ -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
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user