0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-26 18:38:52 +02:00

ircd:Ⓜ️ Add event comparison operator suite.

This commit is contained in:
Jason Volk 2018-04-06 03:13:27 -07:00
parent f26410f5c3
commit 9863e2a1a3
2 changed files with 44 additions and 0 deletions

View file

@ -33,6 +33,15 @@ namespace ircd::m
// [GET]
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

View file

@ -10,6 +10,41 @@
#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::event_id(const event &event,
id::event::buf &buf)