Skip to content

Commit

Permalink
Adding equality operators for store iterator subtypes.
Browse files Browse the repository at this point in the history
  • Loading branch information
clemahieu committed Jan 13, 2023
1 parent dd7298d commit 7b6334e
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion nano/node/lmdb/lmdb_iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ class mdb_iterator : public store_iterator_impl<T, U>
return &current;
}

bool operator== (nano::mdb_iterator<T, U> const & base_a) const
{
auto const other_a (boost::polymorphic_downcast<nano::mdb_iterator<T, U> const *> (&base_a));
auto result (current.first.data () == other_a->current.first.data ());
debug_assert (!result || (current.first.size () == other_a->current.first.size ()));
debug_assert (!result || (current.second.data () == other_a->current.second.data ()));
debug_assert (!result || (current.second.size () == other_a->current.second.size ()));
return result;
}

bool operator== (nano::store_iterator_impl<T, U> const & base_a) const override
{
auto const other_a (boost::polymorphic_downcast<nano::mdb_iterator<T, U> const *> (&base_a));
Expand Down Expand Up @@ -210,11 +220,21 @@ class mdb_merge_iterator : public store_iterator_impl<T, U>
return least_iterator ().operator-> ();
}

bool operator== (nano::mdb_merge_iterator<T, U> const & other) const
{
return *impl1 == *other.impl1 && *impl2 == *other.impl2;
}

bool operator!= (nano::mdb_merge_iterator<T, U> const & base_a) const
{
return !(*this == base_a);
}

bool operator== (nano::store_iterator_impl<T, U> const & base_a) const override
{
debug_assert ((dynamic_cast<nano::mdb_merge_iterator<T, U> const *> (&base_a) != nullptr) && "Incompatible iterator comparison");
auto & other (static_cast<nano::mdb_merge_iterator<T, U> const &> (base_a));
return *impl1 == *other.impl1 && *impl2 == *other.impl2;
return *this == other;
}

bool is_end_sentinal () const override
Expand Down

0 comments on commit 7b6334e

Please sign in to comment.