2018-07-11 13:20:14 +00:00
|
|
|
#ifndef LLARP_DHT_KEY_HPP
|
|
|
|
#define LLARP_DHT_KEY_HPP
|
2018-12-12 02:52:51 +00:00
|
|
|
|
2019-01-10 19:41:51 +00:00
|
|
|
#include <util/aligned.hpp>
|
2018-07-11 13:20:14 +00:00
|
|
|
|
2018-12-20 14:18:03 +00:00
|
|
|
#include <array>
|
|
|
|
|
2018-07-11 13:20:14 +00:00
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace dht
|
|
|
|
{
|
2019-01-02 01:04:08 +00:00
|
|
|
struct Key_t : public AlignedBuffer< 32 >
|
2018-07-11 13:20:14 +00:00
|
|
|
{
|
2019-01-02 01:04:08 +00:00
|
|
|
explicit Key_t(const byte_t* buf) : AlignedBuffer< SIZE >(buf)
|
2018-12-20 14:18:03 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-01-02 01:04:08 +00:00
|
|
|
explicit Key_t(const Data& val) : AlignedBuffer< SIZE >(val)
|
2018-07-11 13:20:14 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-01-02 01:04:08 +00:00
|
|
|
explicit Key_t(const AlignedBuffer< SIZE >& val)
|
|
|
|
: AlignedBuffer< SIZE >(val)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Key_t() : AlignedBuffer< SIZE >()
|
2018-07-11 13:20:14 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Key_t
|
|
|
|
operator^(const Key_t& other) const
|
|
|
|
{
|
|
|
|
Key_t dist;
|
2019-01-02 01:04:08 +00:00
|
|
|
std::transform(begin(), end(), other.begin(), dist.begin(),
|
2018-12-20 14:18:03 +00:00
|
|
|
std::bit_xor< byte_t >());
|
2018-07-11 13:20:14 +00:00
|
|
|
return dist;
|
|
|
|
}
|
|
|
|
|
2018-11-01 12:47:14 +00:00
|
|
|
bool
|
|
|
|
operator==(const Key_t& other) const
|
|
|
|
{
|
2018-12-30 18:56:28 +00:00
|
|
|
return as_array() == other.as_array();
|
2018-11-01 12:47:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
operator!=(const Key_t& other) const
|
|
|
|
{
|
2018-12-30 18:56:28 +00:00
|
|
|
return as_array() != other.as_array();
|
2018-11-01 12:47:14 +00:00
|
|
|
}
|
|
|
|
|
2018-07-11 13:20:14 +00:00
|
|
|
bool
|
|
|
|
operator<(const Key_t& other) const
|
|
|
|
{
|
2018-12-30 18:56:28 +00:00
|
|
|
return as_array() < other.as_array();
|
2018-08-10 03:51:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
operator>(const Key_t& other) const
|
|
|
|
{
|
2018-12-30 18:56:28 +00:00
|
|
|
return as_array() > other.as_array();
|
2018-07-11 13:20:14 +00:00
|
|
|
}
|
|
|
|
};
|
2018-07-17 04:37:50 +00:00
|
|
|
} // namespace dht
|
|
|
|
} // namespace llarp
|
2018-07-11 13:20:14 +00:00
|
|
|
|
2018-12-12 02:52:51 +00:00
|
|
|
#endif
|