libcruft-util/hash/xxhash.hpp

41 lines
1.0 KiB
C++
Raw Normal View History

2016-11-17 18:35:06 +11:00
/*
2018-08-04 15:14:06 +10:00
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
2016-11-17 18:35:06 +11:00
*
2018-01-19 11:30:09 +11:00
* Copyright 2016-2018 Danny Robson <danny@nerdcruft.net>
2016-11-17 18:35:06 +11:00
*/
#ifndef CRUFT_UTIL_HASH_XXHASH_HPP
#define CRUFT_UTIL_HASH_XXHASH_HPP
#include "../view.hpp"
2016-11-17 18:35:06 +11:00
#include <cstdint>
#include <type_traits>
namespace cruft::hash {
template <typename WordT>
2016-11-17 18:35:06 +11:00
class xxhash {
public:
static_assert (std::is_same<WordT,std::uint32_t>::value || std::is_same<WordT,std::uint64_t>::value);
using digest_t = WordT;
using word_t = WordT;
static constexpr int block_bytes = 4 * sizeof (word_t);
2016-11-17 18:35:06 +11:00
static constexpr word_t DEFAULT_SEED = 0;
2016-11-17 18:35:06 +11:00
xxhash (word_t seed = DEFAULT_SEED);
2016-11-17 18:35:06 +11:00
digest_t operator() (const cruft::view<const uint8_t*> data);
2016-11-17 18:35:06 +11:00
private:
word_t m_seed;
2016-11-17 18:35:06 +11:00
};
using xxhash32 = xxhash<uint32_t>;
using xxhash64 = xxhash<uint64_t>;
}
#endif