0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-25 05:18:23 +02:00

ircd:Ⓜ️:room::state: Add prev() and next() reference traversal interface.

This commit is contained in:
Jason Volk 2019-03-11 15:01:14 -07:00
parent 3444bed245
commit f61059a400
3 changed files with 129 additions and 0 deletions

View file

@ -98,6 +98,11 @@ struct ircd::m::room::state
state(const state &) = delete;
state &operator=(const state &) = delete;
static bool prev(const event::idx &, const event::closure_idx_bool &);
static bool next(const event::idx &, const event::closure_idx_bool &);
static event::idx prev(const event::idx &);
static event::idx next(const event::idx &);
static size_t prefetch(const state &, const string_view &, const event::idx_range &);
static size_t clear_history(const state &);
static size_t rebuild_history(const state &);

View file

@ -3743,6 +3743,60 @@ ircd::m::room::state::prefetch(const state &state,
return call(state, type, range);
}
ircd::m::event::idx
ircd::m::room::state::next(const event::idx &event_idx)
{
using prototype = event::idx (const event::idx &);
static mods::import<prototype> call
{
"m_room", "ircd::m::room::state::next"
};
return call(event_idx);
}
ircd::m::event::idx
ircd::m::room::state::prev(const event::idx &event_idx)
{
using prototype = event::idx (const event::idx &);
static mods::import<prototype> call
{
"m_room", "ircd::m::room::state::prev"
};
return call(event_idx);
}
bool
ircd::m::room::state::next(const event::idx &event_idx,
const event::closure_idx_bool &closure)
{
using prototype = bool (const event::idx &, const event::closure_idx_bool &);
static mods::import<prototype> call
{
"m_room", "ircd::m::room::state::next"
};
return call(event_idx, closure);
}
bool
ircd::m::room::state::prev(const event::idx &event_idx,
const event::closure_idx_bool &closure)
{
using prototype = bool (const event::idx &, const event::closure_idx_bool &);
static mods::import<prototype> call
{
"m_room", "ircd::m::room::state::prev"
};
return call(event_idx, closure);
}
ircd::m::room
ircd::m::create(const id::room &room_id,
const id::user &creator,

View file

@ -826,6 +826,76 @@ ircd::m::room::state::prefetch(const state &state,
return ret;
}
ircd::m::event::idx
IRCD_MODULE_EXPORT
ircd::m::room::state::prev(const event::idx &event_idx)
{
event::idx ret{0};
prev(event_idx, [&ret]
(const event::idx &event_idx)
{
if(event_idx > ret)
ret = event_idx;
return true;
});
return ret;
}
ircd::m::event::idx
IRCD_MODULE_EXPORT
ircd::m::room::state::next(const event::idx &event_idx)
{
event::idx ret{0};
next(event_idx, [&ret]
(const event::idx &event_idx)
{
if(event_idx > ret)
ret = event_idx;
return true;
});
return ret;
}
bool
IRCD_MODULE_EXPORT
ircd::m::room::state::next(const event::idx &event_idx,
const event::closure_idx_bool &closure)
{
const m::event::refs refs
{
event_idx
};
return refs.for_each(dbs::ref::STATE, [&closure]
(const event::idx &event_idx, const dbs::ref &ref)
{
assert(ref == dbs::ref::STATE);
return closure(event_idx);
});
}
bool
IRCD_MODULE_EXPORT
ircd::m::room::state::prev(const event::idx &event_idx,
const event::closure_idx_bool &closure)
{
const m::event::refs refs
{
event_idx
};
return refs.for_each(dbs::ref::PREV_STATE, [&closure]
(const event::idx &event_idx, const dbs::ref &ref)
{
assert(ref == dbs::ref::PREV_STATE);
return closure(event_idx);
});
}
extern "C" size_t
dagree_histogram(const m::room &room,
std::vector<size_t> &vec)