mirror of https://github.com/dnomd343/klotski.git
Dnomd343
2 months ago
10 changed files with 96 additions and 54 deletions
@ -0,0 +1,44 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
/// Provides XXH3 and MD5 hash calculation support. The former is far ahead in
|
||||
|
/// speed, but the latter is more of a commemorative significance.
|
||||
|
|
||||
|
/// They do not guarantee the security of the hash algorithm, as this scenario
|
||||
|
/// is only used to verify the correctness of the data.
|
||||
|
|
||||
|
#include <vector> |
||||
|
#include <cstdint> |
||||
|
|
||||
|
namespace helper { |
||||
|
|
||||
|
// ----------------------------------------------------------------------------------------- //
|
||||
|
|
||||
|
/// Calculate XXH3 hash value as u64.
|
||||
|
uint64_t xxh3(const std::string_view &data); |
||||
|
|
||||
|
/// Calculate XXH3 hash value as u64.
|
||||
|
uint64_t xxh3(const void *data, uint64_t size); |
||||
|
|
||||
|
/// Calculate MD5 hash value as string.
|
||||
|
std::string md5(const std::string_view &data); |
||||
|
|
||||
|
/// Calculate MD5 hash value as string.
|
||||
|
std::string md5(const void *data, uint64_t size); |
||||
|
|
||||
|
// ----------------------------------------------------------------------------------------- //
|
||||
|
|
||||
|
/// Calculate XXH3 hash value of continuous array.
|
||||
|
template <typename T> |
||||
|
requires std::is_trivial_v<T> |
||||
|
uint64_t xxh3(const std::vector<T> &data); |
||||
|
|
||||
|
/// Calculate MD5 hash value of continuous array.
|
||||
|
template <typename T> |
||||
|
requires std::is_trivial_v<T> |
||||
|
std::string md5(const std::vector<T> &data); |
||||
|
|
||||
|
// ----------------------------------------------------------------------------------------- //
|
||||
|
|
||||
|
} // namespace helper
|
||||
|
|
||||
|
#include "internal/hash.inl" |
@ -0,0 +1,12 @@ |
|||||
|
#include "helper/hash.h" |
||||
|
|
||||
|
#include <md5.h> |
||||
|
#include <xxh3.h> |
||||
|
|
||||
|
std::string helper::md5(const void *data, const uint64_t size) { |
||||
|
return md5::MD5::Hash(data, size); |
||||
|
} |
||||
|
|
||||
|
uint64_t helper::xxh3(const void *data, const uint64_t size) { |
||||
|
return XXH_INLINE_XXH3_64bits(data, size); |
||||
|
} |
@ -0,0 +1,25 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
namespace helper { |
||||
|
|
||||
|
inline uint64_t xxh3(const std::string_view &data) { |
||||
|
return xxh3(data.data(), data.size()); |
||||
|
} |
||||
|
|
||||
|
inline std::string md5(const std::string_view &data) { |
||||
|
return md5(data.data(), data.size()); |
||||
|
} |
||||
|
|
||||
|
template <typename T> |
||||
|
requires std::is_trivial_v<T> |
||||
|
uint64_t xxh3(const std::vector<T> &data) { |
||||
|
return xxh3(data.data(), data.size() * sizeof(T)); |
||||
|
} |
||||
|
|
||||
|
template <typename T> |
||||
|
requires std::is_trivial_v<T> |
||||
|
std::string md5(const std::vector<T> &data) { |
||||
|
return md5(data.data(), data.size() * sizeof(T)); |
||||
|
} |
||||
|
|
||||
|
} // namespace helper |
@ -1,40 +0,0 @@ |
|||||
#pragma once |
|
||||
|
|
||||
/// Provides XXH3 and MD5 hash calculation support. The former is far ahead in
|
|
||||
/// speed, but the latter is more of a commemorative significance.
|
|
||||
|
|
||||
#include "md5.h" |
|
||||
#include "xxh3.h" |
|
||||
|
|
||||
#include <vector> |
|
||||
#include <cstdint> |
|
||||
|
|
||||
namespace hash { |
|
||||
|
|
||||
inline std::string md5(const void *data, const uint64_t size) { |
|
||||
return md5::MD5::Hash(data, size); |
|
||||
} |
|
||||
|
|
||||
inline uint64_t xxh3(const void *data, const uint64_t size) { |
|
||||
return XXH_INLINE_XXH3_64bits(data, size); |
|
||||
} |
|
||||
|
|
||||
inline std::string md5(const std::string_view &data) { |
|
||||
return md5(data.data(), data.size()); |
|
||||
} |
|
||||
|
|
||||
inline uint64_t xxh3(const std::string_view &data) { |
|
||||
return xxh3(data.data(), data.size()); |
|
||||
} |
|
||||
|
|
||||
template <typename T> |
|
||||
std::string md5(const std::vector<T> &data) { |
|
||||
return md5(data.data(), data.size() * sizeof(T)); |
|
||||
} |
|
||||
|
|
||||
template <typename T> |
|
||||
uint64_t xxh3(const std::vector<T> &data) { |
|
||||
return xxh3(data.data(), data.size() * sizeof(T)); |
|
||||
} |
|
||||
|
|
||||
} // namespace hash
|
|
Loading…
Reference in new issue