From 2f3c4616648a6f1ce3204052c16e88ad1c59af0b Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 24 Sep 2018 22:00:21 -0700 Subject: [PATCH] ircd::db: Place linkage for db comparators so they have one address. --- include/ircd/db/comparator.h | 51 +++++------------- ircd/db.cc | 100 +++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+), 37 deletions(-) diff --git a/include/ircd/db/comparator.h b/include/ircd/db/comparator.h index 4feadb9d0..08ef4c059 100644 --- a/include/ircd/db/comparator.h +++ b/include/ircd/db/comparator.h @@ -40,46 +40,19 @@ struct ircd::db::comparator struct ircd::db::cmp_string_view :db::comparator { - static bool less(const string_view &a, const string_view &b) - { - return a < b; - } + static bool less(const string_view &a, const string_view &b); + static bool equal(const string_view &a, const string_view &b); - static bool equal(const string_view &a, const string_view &b) - { - return a == b; - } - - cmp_string_view() - :db::comparator{"string_view", &less, &equal} - {} + cmp_string_view(); }; struct ircd::db::reverse_cmp_string_view :db::comparator { - static bool less(const string_view &a, const string_view &b) - { - /// RocksDB sez things will not work correctly unless a shorter string - /// result returns less than a longer string even if one intends some - /// reverse ordering - if(a.size() < b.size()) - return true; + static bool less(const string_view &a, const string_view &b); + static bool equal(const string_view &a, const string_view &b); - /// Furthermore, b.size() < a.size() returning false from this function - /// appears to not be correct. The reversal also has to also come in - /// the form of a bytewise forward iteration. - return std::memcmp(a.data(), b.data(), std::min(a.size(), b.size())) > 0; - } - - static bool equal(const string_view &a, const string_view &b) - { - return a == b; - } - - reverse_cmp_string_view() - :db::comparator{"reverse_string_view", &less, &equal} - {} + reverse_cmp_string_view(); }; template @@ -126,23 +99,27 @@ struct ircd::db::reverse_cmp_integer struct ircd::db::cmp_int64_t :cmp_integer { - using cmp_integer::cmp_integer; + cmp_int64_t(); + ~cmp_int64_t() noexcept; }; struct ircd::db::reverse_cmp_int64_t :reverse_cmp_integer { - using reverse_cmp_integer::reverse_cmp_integer; + reverse_cmp_int64_t(); + ~reverse_cmp_int64_t() noexcept; }; struct ircd::db::cmp_uint64_t :cmp_integer { - using cmp_integer::cmp_integer; + cmp_uint64_t(); + ~cmp_uint64_t() noexcept; }; struct ircd::db::reverse_cmp_uint64_t :reverse_cmp_integer { - using reverse_cmp_integer::reverse_cmp_integer; + reverse_cmp_uint64_t(); + ~reverse_cmp_uint64_t() noexcept; }; diff --git a/ircd/db.cc b/ircd/db.cc index a4f10bf55..62ba8fd8f 100644 --- a/ircd/db.cc +++ b/ircd/db.cc @@ -8225,6 +8225,106 @@ ircd::db::seek(column::const_iterator_base &it, template bool ircd::db::seek(column::const_iterator_base &, const pos &); template bool ircd::db::seek(column::const_iterator_base &, const string_view &); +/////////////////////////////////////////////////////////////////////////////// +// +// comparator.h +// + +// +// linkage placements for integer comparators so they all have the same addr +// + +ircd::db::cmp_int64_t::cmp_int64_t() +{ +} + +ircd::db::cmp_int64_t::~cmp_int64_t() +noexcept +{ +} + +ircd::db::cmp_uint64_t::cmp_uint64_t() +{ +} + +ircd::db::cmp_uint64_t::~cmp_uint64_t() +noexcept +{ +} + +ircd::db::reverse_cmp_int64_t::reverse_cmp_int64_t() +{ +} + +ircd::db::reverse_cmp_int64_t::~reverse_cmp_int64_t() +noexcept +{ +} + +ircd::db::reverse_cmp_uint64_t::reverse_cmp_uint64_t() +{ +} + +ircd::db::reverse_cmp_uint64_t::~reverse_cmp_uint64_t() +noexcept +{ +} + +// +// cmp_string_view +// + +ircd::db::cmp_string_view::cmp_string_view() +:db::comparator{"string_view", &less, &equal} +{ +} + +bool +ircd::db::cmp_string_view::less(const string_view &a, + const string_view &b) +{ + return a < b; +} + +bool +ircd::db::cmp_string_view::equal(const string_view &a, + const string_view &b) +{ + return a == b; +} + +// +// reverse_cmp_string_view +// + +ircd::db::reverse_cmp_string_view::reverse_cmp_string_view() +:db::comparator{"reverse_string_view", &less, &equal} +{ +} + +bool +ircd::db::reverse_cmp_string_view::less(const string_view &a, + const string_view &b) +{ + /// RocksDB sez things will not work correctly unless a shorter string + /// result returns less than a longer string even if one intends some + /// reverse ordering + if(a.size() < b.size()) + return true; + + /// Furthermore, b.size() < a.size() returning false from this function + /// appears to not be correct. The reversal also has to also come in + /// the form of a bytewise forward iteration. + return std::memcmp(a.data(), b.data(), std::min(a.size(), b.size())) > 0; +} + +bool +ircd::db::reverse_cmp_string_view::equal(const string_view &a, + const string_view &b) +{ + return a == b; +} + /////////////////////////////////////////////////////////////////////////////// // // merge.h