mirror of
https://github.com/matrix-construct/construct
synced 2024-12-29 17:04:03 +01:00
ircd:Ⓜ️ Add event comparison operator suite.
This commit is contained in:
parent
f26410f5c3
commit
9863e2a1a3
2 changed files with 44 additions and 0 deletions
|
@ -33,6 +33,15 @@ namespace ircd::m
|
||||||
|
|
||||||
// [GET]
|
// [GET]
|
||||||
bool exists(const id::event &);
|
bool exists(const id::event &);
|
||||||
|
|
||||||
|
// Depth comparison; expect unstable sorting.
|
||||||
|
bool operator<(const event &, const event &);
|
||||||
|
bool operator>(const event &, const event &);
|
||||||
|
bool operator<=(const event &, const event &);
|
||||||
|
bool operator>=(const event &, const event &);
|
||||||
|
|
||||||
|
// Equality tests the event_id only! know this.
|
||||||
|
bool operator==(const event &a, const event &b);
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
|
|
|
@ -10,6 +10,41 @@
|
||||||
|
|
||||||
#include <ircd/m/m.h>
|
#include <ircd/m/m.h>
|
||||||
|
|
||||||
|
bool
|
||||||
|
ircd::m::operator==(const event &a, const event &b)
|
||||||
|
{
|
||||||
|
assert(json::get<"room_id"_>(a) == json::get<"room_id"_>(b));
|
||||||
|
return at<"event_id"_>(a) == at<"event_id"_>(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ircd::m::operator>=(const event &a, const event &b)
|
||||||
|
{
|
||||||
|
assert(json::get<"room_id"_>(a) == json::get<"room_id"_>(b));
|
||||||
|
return at<"depth"_>(a) >= at<"depth"_>(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ircd::m::operator<=(const event &a, const event &b)
|
||||||
|
{
|
||||||
|
assert(json::get<"room_id"_>(a) == json::get<"room_id"_>(b));
|
||||||
|
return at<"depth"_>(a) <= at<"depth"_>(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ircd::m::operator>(const event &a, const event &b)
|
||||||
|
{
|
||||||
|
assert(json::get<"room_id"_>(a) == json::get<"room_id"_>(b));
|
||||||
|
return at<"depth"_>(a) > at<"depth"_>(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ircd::m::operator<(const event &a, const event &b)
|
||||||
|
{
|
||||||
|
assert(json::get<"room_id"_>(a) == json::get<"room_id"_>(b));
|
||||||
|
return at<"depth"_>(a) < at<"depth"_>(b);
|
||||||
|
}
|
||||||
|
|
||||||
ircd::m::id::event
|
ircd::m::id::event
|
||||||
ircd::m::event_id(const event &event,
|
ircd::m::event_id(const event &event,
|
||||||
id::event::buf &buf)
|
id::event::buf &buf)
|
||||||
|
|
Loading…
Reference in a new issue