0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 10:12:39 +01:00

ircd::db: Add reverse string_view comparator.

This commit is contained in:
Jason Volk 2017-09-23 00:13:16 -07:00
parent d2469ba44d
commit 703121f867

View file

@ -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<bool (const string_view &, const string_view &)> 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}
{}
};