Use empty uint8_t peer data (#2944)

* Use empty peer data
* Using std::nullptr_t to indicate no value is stored.
* put_key function

Co-authored-by: clemahieu <clemahieu@gmail.com>
This commit is contained in:
Sergey Kroshnin 2020-09-21 18:32:59 +03:00 committed by GitHub
commit bd014357b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View file

@ -50,6 +50,11 @@ public:
{
}
db_val (std::nullptr_t) :
db_val (0, this)
{
}
db_val (nano::uint128_union const & val_a) :
db_val (sizeof (val_a), const_cast<nano::uint128_union *> (&val_a))
{

View file

@ -555,8 +555,7 @@ public:
void peer_put (nano::write_transaction const & transaction_a, nano::endpoint_key const & endpoint_a) override
{
nano::db_val<Val> zero (static_cast<uint64_t> (0));
auto status = put (transaction_a, tables::peers, endpoint_a, zero);
auto status = put_key (transaction_a, tables::peers, endpoint_a);
release_assert (success (status));
}
@ -790,6 +789,12 @@ protected:
return static_cast<Derived_Store &> (*this).put (transaction_a, table_a, key_a, value_a);
}
// Put only key without value
int put_key (nano::write_transaction const & transaction_a, tables table_a, nano::db_val<Val> const & key_a)
{
return put (transaction_a, table_a, key_a, nano::db_val<Val>{ std::nullptr_t{} });
}
int del (nano::write_transaction const & transaction_a, tables table_a, nano::db_val<Val> const & key_a)
{
return static_cast<Derived_Store &> (*this).del (transaction_a, table_a, key_a);