54 lines
1.1 KiB
C++
54 lines
1.1 KiB
C++
//
|
|
// Created by Kirill Zhukov on 20.04.2025.
|
|
//
|
|
|
|
#ifndef HASHSTRUCTURE_H
|
|
#define HASHSTRUCTURE_H
|
|
|
|
#include <cstdint>
|
|
#include <cstdlib>
|
|
#include <string>
|
|
|
|
#include "utils/hash/xxhash/xxhash.h"
|
|
|
|
|
|
namespace usub::utils
|
|
{
|
|
struct alignas(16) Hash128
|
|
{
|
|
uint64_t low;
|
|
uint64_t high;
|
|
|
|
Hash128() : low(0), high(0)
|
|
{
|
|
}
|
|
|
|
bool operator<(const Hash128& other) const
|
|
{
|
|
return (this->high == other.high) ? (this->low < other.low) : (this->high < other.high);
|
|
}
|
|
|
|
bool operator==(const Hash128& other) const
|
|
{
|
|
return this->low == other.low && this->high == other.high;
|
|
}
|
|
};
|
|
|
|
inline Hash128 compute_hash128(const void* data, size_t length)
|
|
{
|
|
Hash128 h;
|
|
XXH128_hash_t hash = XXH3_128bits(data, length);
|
|
h.low = hash.low64;
|
|
h.high = hash.high64;
|
|
return h;
|
|
}
|
|
|
|
inline Hash128 compute_hash128(const std::string& s)
|
|
{
|
|
return compute_hash128(s.data(), s.size());
|
|
}
|
|
} // namespace usub::utils
|
|
|
|
|
|
#endif //HASHSTRUCTURE_H
|