From 9619081f8471ec9a9cb1e7cf57e3ace8e479e02f Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sun, 28 Apr 2024 18:50:33 +0200 Subject: [PATCH] Use fuzzy compare for RDB#apply --- src/rdb/rdb/rdb.cc | 62 +++++++++++++++++++++++++++++++++++++++++++--- src/rdb/rdb/rdb.h | 5 +--- 2 files changed, 60 insertions(+), 7 deletions(-) diff --git a/src/rdb/rdb/rdb.cc b/src/rdb/rdb/rdb.cc index 7771727b3..b3ea21a41 100644 --- a/src/rdb/rdb/rdb.cc +++ b/src/rdb/rdb/rdb.cc @@ -174,6 +174,62 @@ template <> RDB_PUBLIC std::string Value::to_display_string () const return to_string (); } +// compare implementations + +template <> RDB_PUBLIC bool Value::compare (const ValueBase *o) const +{ + const Value *other = static_cast *> (o); + return m_value < other->m_value - db::epsilon; +} + +template <> RDB_PUBLIC bool Value::compare (const ValueBase *o) const +{ + const Value *other = static_cast *> (o); + return m_value < other->m_value; +} + +template <> RDB_PUBLIC bool Value::compare (const ValueBase *o) const +{ + const Value *other = static_cast *> (o); + return m_value < other->m_value; +} + +template <> RDB_PUBLIC bool Value::compare (const ValueBase *o) const +{ + const Value *other = static_cast *> (o); + return m_value.less (other->m_value); +} + +template <> RDB_PUBLIC bool Value::compare (const ValueBase *o) const +{ + const Value *other = static_cast *> (o); + return m_value.less (other->m_value); +} + +template <> RDB_PUBLIC bool Value::compare (const ValueBase *o) const +{ + const Value *other = static_cast *> (o); + return m_value.less (other->m_value); +} + +template <> RDB_PUBLIC bool Value::compare (const ValueBase *o) const +{ + const Value *other = static_cast *> (o); + return m_value.less (other->m_value); +} + +template <> RDB_PUBLIC bool Value::compare (const ValueBase *o) const +{ + const Value *other = static_cast *> (o); + return m_value.less (other->m_value); +} + +template <> RDB_PUBLIC bool Value::compare (const ValueBase *o) const +{ + const Value *other = static_cast *> (o); + return m_value.less (other->m_value); +} + // is_shape implementations template <> RDB_PUBLIC bool Value::is_shape () const @@ -881,14 +937,14 @@ Tags::tag (const std::string &name, bool user_tag) const Tag & Tags::tag (id_type id) const { - tl_assert (id - 1 < m_tags.size () && id > 0); + tl_assert (id < m_tags.size () + 1 && id > 0); return m_tags [id - 1]; } Tag & Tags::tag (id_type id) { - tl_assert (id - 1 < m_tags.size () && id > 0); + tl_assert (id < m_tags.size () + 1 && id > 0); return m_tags [id - 1]; } @@ -1830,7 +1886,7 @@ Database::apply (const rdb::Database &other) } for (auto c = other.categories ().begin (); c != other.categories ().end (); ++c) { - const rdb::Category *this_cat = category_by_name (c->name ()); + const rdb::Category *this_cat = category_by_name (c->path ()); if (this_cat) { cat2cat.insert (std::make_pair (this_cat->id (), c->id ())); } diff --git a/src/rdb/rdb/rdb.h b/src/rdb/rdb/rdb.h index a2d0f0b5a..d8f6c3d18 100644 --- a/src/rdb/rdb/rdb.h +++ b/src/rdb/rdb/rdb.h @@ -506,10 +506,7 @@ public: return type_index_of (); } - bool compare (const ValueBase *other) const - { - return m_value < static_cast *> (other)->m_value; - } + bool compare (const ValueBase *other) const; bool is_shape () const;