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
|
|
|
|
|
|
|
#include <aligned.hpp>
|
2018-07-11 13:20:14 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace dht
|
|
|
|
{
|
|
|
|
struct Key_t : public llarp::AlignedBuffer< 32 >
|
|
|
|
{
|
|
|
|
Key_t(const byte_t* val) : llarp::AlignedBuffer< 32 >(val)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Key_t() : llarp::AlignedBuffer< 32 >()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Key_t
|
|
|
|
operator^(const Key_t& other) const
|
|
|
|
{
|
|
|
|
Key_t dist;
|
2018-11-02 17:08:01 +00:00
|
|
|
for(size_t idx = 0; idx < (size() / sizeof(l[0])); ++idx)
|
2018-07-17 04:37:50 +00:00
|
|
|
dist.l[idx] = l[idx] ^ other.l[idx];
|
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
|
|
|
|
{
|
|
|
|
return memcmp(data(), other.data(), 32) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
operator!=(const Key_t& other) const
|
|
|
|
{
|
|
|
|
return memcmp(data(), other.data(), 32) != 0;
|
|
|
|
}
|
|
|
|
|
2018-07-11 13:20:14 +00:00
|
|
|
bool
|
|
|
|
operator<(const Key_t& other) const
|
|
|
|
{
|
2018-08-10 03:51:38 +00:00
|
|
|
return memcmp(data(), other.data(), 32) < 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
operator>(const Key_t& other) const
|
|
|
|
{
|
|
|
|
return memcmp(data(), other.data(), 32) > 0;
|
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
|