0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-15 14:31:11 +01:00

ircd:Ⓜ️:event: Add more ergonomic bulk id/idx extraction interface.

This commit is contained in:
Jason Volk 2020-12-16 17:06:10 -08:00
parent 7a11acbacd
commit 159bebbd26
3 changed files with 85 additions and 1 deletions

View file

@ -37,6 +37,8 @@ struct ircd::m::event::auth
5
};
template<size_t N> vector_view<event::id> ids(event::id (&)[N]) const;
template<size_t N> vector_view<event::idx> idxs(event::idx (&)[N]) const;
std::tuple<event::id, json::object> auth_events(const size_t &idx) const;
event::id auth_event(const size_t &idx) const;
bool auth_event_exists(const size_t &idx) const;
@ -48,3 +50,43 @@ struct ircd::m::event::auth
using super_type::tuple;
using super_type::operator=;
};
template<size_t N>
inline ircd::vector_view<ircd::m::event::idx>
ircd::m::event::auth::idxs(event::idx (&out)[N])
const
{
event::id buf[N];
const auto &ids
{
auth::ids(buf)
};
const auto &found
{
m::index(out, ids)
};
return vector_view<event::idx>
(
out, out + ids.size()
);
}
template<size_t N>
inline ircd::vector_view<ircd::m::event::id>
ircd::m::event::auth::ids(event::id (&out)[N])
const
{
size_t i(0);
m::for_each(*this, [&i, &out](const event::id &event_id)
{
out[i++] = event_id;
return i < N;
});
return vector_view<event::id>
(
out, i
);
}

View file

@ -156,11 +156,11 @@ struct ircd::m::event
event() = default;
};
#include "index.h"
#include "auth.h"
#include "prev.h"
#include "refs.h"
#include "horizon.h"
#include "index.h"
#include "event_id.h"
#include "fetch.h"
#include "cached.h"

View file

@ -44,6 +44,8 @@ struct ircd::m::event::prev
20
};
template<size_t N> vector_view<event::id> ids(event::id (&)[N]) const;
template<size_t N> vector_view<event::idx> idxs(event::idx (&)[N]) const;
std::tuple<event::id, json::object> prev_events(const size_t &idx) const;
event::id prev_event(const size_t &idx) const;
bool prev_event_exists(const size_t &idx) const;
@ -55,3 +57,43 @@ struct ircd::m::event::prev
using super_type::tuple;
using super_type::operator=;
};
template<size_t N>
inline ircd::vector_view<ircd::m::event::idx>
ircd::m::event::prev::idxs(event::idx (&out)[N])
const
{
event::id buf[N];
const auto &ids
{
prev::ids(buf)
};
const auto &found
{
m::index(out, ids)
};
return vector_view<event::idx>
(
out, out + ids.size()
);
}
template<size_t N>
inline ircd::vector_view<ircd::m::event::id>
ircd::m::event::prev::ids(event::id (&out)[N])
const
{
size_t i(0);
m::for_each(*this, [&i, &out](const event::id &event_id)
{
out[i++] = event_id;
return i < N;
});
return vector_view<event::id>
(
out, i
);
}