From 703121f8671d8d131cf6a6b72e23d63688590c26 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sat, 23 Sep 2017 00:13:16 -0700 Subject: [PATCH] ircd::db: Add reverse string_view comparator. --- include/ircd/db/comparator.h | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/include/ircd/db/comparator.h b/include/ircd/db/comparator.h index f72194eec..9db3efb95 100644 --- a/include/ircd/db/comparator.h +++ b/include/ircd/db/comparator.h @@ -29,6 +29,7 @@ namespace ircd::db struct cmp_int64_t; struct cmp_string_view; + struct reverse_cmp_string_view; } struct ircd::db::comparator @@ -38,6 +39,24 @@ struct ircd::db::comparator std::function equal; }; +struct ircd::db::reverse_cmp_string_view +:db::comparator +{ + static bool less(const string_view &a, const string_view &b) + { + 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} + {} +}; + struct ircd::db::cmp_string_view :db::comparator { @@ -52,7 +71,7 @@ struct ircd::db::cmp_string_view } cmp_string_view() - :db::comparator{"string_view", less, equal} + :db::comparator{"string_view", &less, &equal} {} }; @@ -78,6 +97,6 @@ struct ircd::db::cmp_int64_t } cmp_int64_t() - :db::comparator{"int64_t", less, equal} + :db::comparator{"int64_t", &less, &equal} {} };