From 51487cd34ec748446f87f8f1af00066056a6371f Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Fri, 17 Jun 2016 15:56:14 +1000 Subject: [PATCH] hash: put checksum functions into util::hash:: --- hash/adler.cpp | 13 ++++++++----- hash/adler.hpp | 6 ++++-- hash/bsdsum.cpp | 8 +++++--- hash/bsdsum.hpp | 10 ++++++---- hash/crc.cpp | 14 ++++++++++---- hash/crc.hpp | 11 ++++++----- 6 files changed, 39 insertions(+), 23 deletions(-) diff --git a/hash/adler.cpp b/hash/adler.cpp index 37206e59..eff919a8 100644 --- a/hash/adler.cpp +++ b/hash/adler.cpp @@ -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 (_data), - static_cast (_data) + _size); + return adler32 ( + static_cast (_data), + static_cast (_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); } diff --git a/hash/adler.hpp b/hash/adler.hpp index 9d8243f5..dc7279d0 100644 --- a/hash/adler.hpp +++ b/hash/adler.hpp @@ -20,7 +20,9 @@ #include #include -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 diff --git a/hash/bsdsum.cpp b/hash/bsdsum.cpp index b367a168..802af0d0 100644 --- a/hash/bsdsum.cpp +++ b/hash/bsdsum.cpp @@ -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 (data), diff --git a/hash/bsdsum.hpp b/hash/bsdsum.hpp index 0add7602..6c05bed1 100644 --- a/hash/bsdsum.hpp +++ b/hash/bsdsum.hpp @@ -14,13 +14,15 @@ * Copyright 2011 Danny Robson */ -#ifndef __UTIL_BSDSUM_HPP -#define __UTIL_BSDSUM_HPP +#ifndef __UTIL_HASH_BSDSUM_HPP +#define __UTIL_HASH_BSDSUM_HPP #include #include -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 diff --git a/hash/crc.cpp b/hash/crc.cpp index d0a7e5d6..20e2a9bb 100644 --- a/hash/crc.cpp +++ b/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 (); /* diff --git a/hash/crc.hpp b/hash/crc.hpp index 4a511bf3..604bdafb 100644 --- a/hash/crc.hpp +++ b/hash/crc.hpp @@ -14,14 +14,15 @@ * Copyright 2011 Danny Robson */ -#ifndef __UTIL_CRC_HPP -#define __UTIL_CRC_HPP +#ifndef __UTIL_HASH_CRC_HPP +#define __UTIL_HASH_CRC_HPP #include #include -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