0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-05-29 00:03:45 +02:00

ircd:Ⓜ️:node: Start preliminary mitsein interface.

This commit is contained in:
Jason Volk 2020-04-23 00:10:55 -07:00
parent 406a893f80
commit 1882f7b507
2 changed files with 74 additions and 0 deletions

View file

@ -38,6 +38,7 @@ struct ircd::m::node
{
struct room;
struct keys;
struct mitsein;
string_view node_id;
@ -77,6 +78,29 @@ struct ircd::m::node::keys
{}
};
/// Interface to the other nodes visible to a node from common rooms.
struct ircd::m::node::mitsein
{
using closure = std::function<bool (const string_view &, const m::room &)>;
m::node node;
public:
// All common rooms with node
bool for_each(const m::node &, const string_view &membership, const closure &) const;
bool for_each(const m::node &, const closure &) const;
// Counting convenience
size_t count(const m::node &, const string_view &membership = {}) const;
// Existential convenience (does `node` and `other` share any common room).
bool has(const m::node &other, const string_view &membership = {}) const;
mitsein(const m::node &node)
:node{node}
{}
};
inline
ircd::m::node::node(const string_view &node_id)
:node_id

View file

@ -146,3 +146,53 @@ const
closure(key);
});
}
//
// node::mitsein
//
bool
ircd::m::node::mitsein::has(const m::node &other,
const string_view &membership)
const
{
return !for_each(other, membership, []
(const auto &, const auto &)
{
return false;
});
}
size_t
ircd::m::node::mitsein::count(const m::node &other,
const string_view &membership)
const
{
size_t ret(0);
for_each(other, membership, [&ret]
(const auto &, const auto &)
{
++ret;
return true;
});
return ret;
}
bool
ircd::m::node::mitsein::for_each(const m::node &other,
const closure &closure)
const
{
return for_each(other, string_view{}, closure);
}
bool
ircd::m::node::mitsein::for_each(const m::node &other,
const string_view &membership,
const closure &closure)
const
{
always_assert(0);
return true;
}