0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 15:33:54 +01:00

ircd:Ⓜ️:event: Augment event::horizon interface allowing full column iteration.

This commit is contained in:
Jason Volk 2019-05-17 02:14:29 -07:00
parent 2a47c82534
commit c119c84c2f
3 changed files with 35 additions and 11 deletions

View file

@ -27,13 +27,14 @@ class ircd::m::event::horizon
event::id event_id;
public:
using closure_bool = event::closure_idx_bool;
using closure_bool = std::function<bool (const event::id &, const event::idx &)>;
bool for_each(const closure_bool &) const;
bool has(const event::idx &) const;
size_t count() const;
horizon(const event::id &);
horizon() = default;
static bool has(const event::id &);
static size_t rebuild();

View file

@ -2588,7 +2588,8 @@ ircd::m::event::horizon::count()
const
{
size_t ret(0);
for_each([&ret](const auto &)
for_each([&ret]
(const auto &, const auto &)
{
++ret;
return true;
@ -2602,7 +2603,7 @@ ircd::m::event::horizon::has(const event::idx &event_idx)
const
{
return !for_each([&event_idx]
(const auto &_event_idx)
(const auto &, const auto &_event_idx)
{
// false to break; true to continue.
return _event_idx == event_idx? false : true;
@ -2613,25 +2614,47 @@ bool
ircd::m::event::horizon::for_each(const closure_bool &closure)
const
{
if(!this->event_id)
{
db::column &column{dbs::event_horizon};
for(auto it(column.begin()); it; ++it)
{
const auto &parts
{
split(it->first, "\0"_sv)
};
const auto &event_id
{
parts.first
};
const auto &event_idx
{
byte_view<event::idx>(parts.second)
};
if(!closure(event_id, event_idx))
return false;
}
return true;
}
char buf[m::dbs::EVENT_HORIZON_KEY_MAX_SIZE];
const string_view &key
{
m::dbs::event_horizon_key(buf, event_id, 0UL)
};
auto it
{
m::dbs::event_horizon.begin(key)
};
for(; it; ++it)
for(auto it(m::dbs::event_horizon.begin(key)); it; ++it)
{
const auto &event_idx
{
std::get<0>(m::dbs::event_horizon_key(it->first))
};
if(!closure(event_idx))
if(!closure(event_id, event_idx))
return false;
}

View file

@ -6460,7 +6460,7 @@ console_cmd__event__horizon(opt &out, const string_view &line)
};
horizon.for_each([&out, &event_id]
(const auto &event_idx)
(const auto &, const auto &event_idx)
{
const auto _event_id
{