mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-10-29 11:05:43 +00:00
57 lines
1.1 KiB
C++
57 lines
1.1 KiB
C++
#ifndef LLARP_DHT_KEY_HPP
|
|
#define LLARP_DHT_KEY_HPP
|
|
|
|
#include <aligned.hpp>
|
|
|
|
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;
|
|
for(size_t idx = 0; idx < (size() / sizeof(l[0])); ++idx)
|
|
dist.l[idx] = l[idx] ^ other.l[idx];
|
|
return dist;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
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;
|
|
}
|
|
};
|
|
} // namespace dht
|
|
} // namespace llarp
|
|
|
|
#endif
|