mirror of
https://github.com/matrix-construct/construct
synced 2024-11-18 07:50:57 +01:00
ircd::db: Create template for integer comparators.
This commit is contained in:
parent
ad0f248b0f
commit
12957038f7
1 changed files with 42 additions and 12 deletions
|
@ -15,9 +15,15 @@ namespace ircd::db
|
||||||
{
|
{
|
||||||
struct comparator;
|
struct comparator;
|
||||||
|
|
||||||
|
template<class T> struct cmp_integer;
|
||||||
|
template<class T> struct reverse_cmp_integer;
|
||||||
|
|
||||||
struct cmp_int64_t;
|
struct cmp_int64_t;
|
||||||
struct reverse_cmp_int64_t;
|
struct reverse_cmp_int64_t;
|
||||||
|
|
||||||
|
struct cmp_uint64_t;
|
||||||
|
struct reverse_cmp_uint64_t;
|
||||||
|
|
||||||
struct cmp_string_view;
|
struct cmp_string_view;
|
||||||
struct reverse_cmp_string_view;
|
struct reverse_cmp_string_view;
|
||||||
}
|
}
|
||||||
|
@ -74,42 +80,66 @@ struct ircd::db::reverse_cmp_string_view
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ircd::db::cmp_int64_t
|
template<class T>
|
||||||
|
struct ircd::db::cmp_integer
|
||||||
:db::comparator
|
:db::comparator
|
||||||
{
|
{
|
||||||
static bool less(const string_view &sa, const string_view &sb)
|
static bool less(const string_view &sa, const string_view &sb)
|
||||||
{
|
{
|
||||||
assert(sa.size() == sizeof(int64_t) && sb.size() == sizeof(int64_t));
|
const byte_view<T> a{sa}, b{sb};
|
||||||
const byte_view<int64_t> a{sa}, b{sb};
|
|
||||||
return a < b;
|
return a < b;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool equal(const string_view &sa, const string_view &sb)
|
static bool equal(const string_view &sa, const string_view &sb)
|
||||||
{
|
{
|
||||||
assert(sa.size() == sizeof(int64_t) && sb.size() == sizeof(int64_t));
|
const byte_view<T> a{sa}, b{sb};
|
||||||
const byte_view<int64_t> a{sa}, b{sb};
|
|
||||||
return a == b;
|
return a == b;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmp_int64_t()
|
cmp_integer()
|
||||||
:db::comparator{"int64_t", &less, &equal}
|
:db::comparator{"integer", &less, &equal}
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ircd::db::reverse_cmp_int64_t
|
template<class T>
|
||||||
|
struct ircd::db::reverse_cmp_integer
|
||||||
:db::comparator
|
:db::comparator
|
||||||
{
|
{
|
||||||
static bool less(const string_view &a, const string_view &b)
|
static bool less(const string_view &a, const string_view &b)
|
||||||
{
|
{
|
||||||
return !cmp_int64_t::less(a, b);
|
return !cmp_integer<T>::less(a, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool equal(const string_view &a, const string_view &b)
|
static bool equal(const string_view &a, const string_view &b)
|
||||||
{
|
{
|
||||||
return cmp_int64_t::equal(a, b);
|
return cmp_integer<T>::equal(a, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
reverse_cmp_int64_t()
|
reverse_cmp_integer()
|
||||||
:db::comparator{"reverse_int64_t", &less, &equal}
|
:db::comparator{"reverse_integer", &less, &equal}
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ircd::db::cmp_int64_t
|
||||||
|
:cmp_integer<int64_t>
|
||||||
|
{
|
||||||
|
using cmp_integer<int64_t>::cmp_integer;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ircd::db::reverse_cmp_int64_t
|
||||||
|
:reverse_cmp_integer<int64_t>
|
||||||
|
{
|
||||||
|
using reverse_cmp_integer<int64_t>::reverse_cmp_integer;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ircd::db::cmp_uint64_t
|
||||||
|
:cmp_integer<uint64_t>
|
||||||
|
{
|
||||||
|
using cmp_integer<uint64_t>::cmp_integer;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ircd::db::reverse_cmp_uint64_t
|
||||||
|
:reverse_cmp_integer<uint64_t>
|
||||||
|
{
|
||||||
|
using reverse_cmp_integer<uint64_t>::reverse_cmp_integer;
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in a new issue