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

ircd:Ⓜ️ Add parallel index() overload for event::prev.

This commit is contained in:
Jason Volk 2020-11-22 02:31:50 -08:00
parent 00bd72e3ff
commit 5fdc492470
2 changed files with 26 additions and 0 deletions

View file

@ -16,6 +16,9 @@ namespace ircd::m
// Parallel query; returns number of successful results (positions are fixed)
size_t index(const vector_view<event::idx> &out, const vector_view<const event::id> &in);
// Parallel query; returns number of successful results (positions are fixed)
size_t index(const vector_view<event::idx> &out, const m::event::prev &);
// Responds with idx in closure; returns false if no action.
bool index(std::nothrow_t, const event::id &, const event::closure_idx &);

View file

@ -98,6 +98,29 @@ ircd::m::index(std::nothrow_t,
});
}
size_t
ircd::m::index(const vector_view<event::idx> &out,
const event::prev &prev)
{
const auto num
{
std::min(prev.prev_events_count(), event::prev::MAX)
};
size_t i(0);
event::id event_id[num];
m::for_each(prev, [&num, &i, &event_id]
(const auto &prev_id)
{
assert(i < num);
event_id[i++] = prev_id;
return i < num;
});
assert(i == num);
return index(out, vector_view<const event::id>(event_id, i));
}
size_t
ircd::m::index(const vector_view<event::idx> &out_,
const vector_view<const event::id> &in_)