mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-10-29 11:05:43 +00:00
68 lines
1.3 KiB
C++
68 lines
1.3 KiB
C++
#ifndef LLARP_DHT_KEY_HPP
|
|
#define LLARP_DHT_KEY_HPP
|
|
|
|
#include <util/aligned.hpp>
|
|
|
|
#include <array>
|
|
|
|
namespace llarp
|
|
{
|
|
namespace dht
|
|
{
|
|
struct Key_t : public AlignedBuffer< 32 >
|
|
{
|
|
explicit Key_t(const byte_t* buf) : AlignedBuffer< SIZE >(buf)
|
|
{
|
|
}
|
|
|
|
explicit Key_t(const Data& val) : AlignedBuffer< SIZE >(val)
|
|
{
|
|
}
|
|
|
|
explicit Key_t(const AlignedBuffer< SIZE >& val)
|
|
: AlignedBuffer< SIZE >(val)
|
|
{
|
|
}
|
|
|
|
Key_t() : AlignedBuffer< SIZE >()
|
|
{
|
|
}
|
|
|
|
Key_t
|
|
operator^(const Key_t& other) const
|
|
{
|
|
Key_t dist;
|
|
std::transform(begin(), end(), other.begin(), dist.begin(),
|
|
std::bit_xor< byte_t >());
|
|
return dist;
|
|
}
|
|
|
|
bool
|
|
operator==(const Key_t& other) const
|
|
{
|
|
return as_array() == other.as_array();
|
|
}
|
|
|
|
bool
|
|
operator!=(const Key_t& other) const
|
|
{
|
|
return as_array() != other.as_array();
|
|
}
|
|
|
|
bool
|
|
operator<(const Key_t& other) const
|
|
{
|
|
return as_array() < other.as_array();
|
|
}
|
|
|
|
bool
|
|
operator>(const Key_t& other) const
|
|
{
|
|
return as_array() > other.as_array();
|
|
}
|
|
};
|
|
} // namespace dht
|
|
} // namespace llarp
|
|
|
|
#endif
|