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:
parent
d2469ba44d
commit
703121f867
1 changed files with 21 additions and 2 deletions
|
@ -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}
|
||||
{}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue