Add functions to allow pending_key objects to be in containers. (#4489)
This commit is contained in:
parent
7dbf64f11c
commit
7523172634
3 changed files with 32 additions and 0 deletions
|
|
@ -3,6 +3,7 @@
|
||||||
#include <nano/lib/thread_pool.hpp>
|
#include <nano/lib/thread_pool.hpp>
|
||||||
#include <nano/lib/timer.hpp>
|
#include <nano/lib/timer.hpp>
|
||||||
#include <nano/lib/utility.hpp>
|
#include <nano/lib/utility.hpp>
|
||||||
|
#include <nano/secure/pending_info.hpp>
|
||||||
#include <nano/secure/utility.hpp>
|
#include <nano/secure/utility.hpp>
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
@ -346,3 +347,16 @@ TEST (relaxed_atomic_integral, many_threads)
|
||||||
// Check values
|
// Check values
|
||||||
ASSERT_EQ (0, atomic);
|
ASSERT_EQ (0, atomic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST (pending_key, sorting)
|
||||||
|
{
|
||||||
|
nano::pending_key one{ 1, 2 };
|
||||||
|
nano::pending_key two{ 1, 3 };
|
||||||
|
nano::pending_key three{ 2, 1 };
|
||||||
|
ASSERT_LT (one, two);
|
||||||
|
ASSERT_LT (one, three);
|
||||||
|
ASSERT_LT (two, three);
|
||||||
|
nano::pending_key one_same{ 1, 2 };
|
||||||
|
ASSERT_EQ (std::hash<nano::pending_key>{}(one), std::hash<nano::pending_key>{}(one_same));
|
||||||
|
ASSERT_NE (std::hash<nano::pending_key>{}(one), std::hash<nano::pending_key>{}(two));
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -65,3 +65,8 @@ nano::account const & nano::pending_key::key () const
|
||||||
{
|
{
|
||||||
return account;
|
return account;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool nano::pending_key::operator< (nano::pending_key const & other_a) const
|
||||||
|
{
|
||||||
|
return account == other_a.account ? hash < other_a.hash : account < other_a.account;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,21 @@ public:
|
||||||
pending_key (nano::account const &, nano::block_hash const &);
|
pending_key (nano::account const &, nano::block_hash const &);
|
||||||
bool deserialize (nano::stream &);
|
bool deserialize (nano::stream &);
|
||||||
bool operator== (nano::pending_key const &) const;
|
bool operator== (nano::pending_key const &) const;
|
||||||
|
bool operator< (nano::pending_key const &) const;
|
||||||
nano::account const & key () const;
|
nano::account const & key () const;
|
||||||
nano::account account{};
|
nano::account account{};
|
||||||
nano::block_hash hash{ 0 };
|
nano::block_hash hash{ 0 };
|
||||||
};
|
};
|
||||||
} // namespace nano
|
} // namespace nano
|
||||||
|
|
||||||
|
namespace std
|
||||||
|
{
|
||||||
|
template <>
|
||||||
|
struct hash<::nano::pending_key>
|
||||||
|
{
|
||||||
|
size_t operator() (::nano::pending_key const & data_a) const
|
||||||
|
{
|
||||||
|
return hash<::nano::uint512_union>{}({ ::nano::uint256_union{ data_a.account.number () }, data_a.hash });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue