mirror of
https://github.com/matrix-construct/construct
synced 2024-09-28 19:58:53 +02:00
ircd:Ⓜ️:room::state: Add prev() and next() reference traversal interface.
This commit is contained in:
parent
3444bed245
commit
f61059a400
3 changed files with 129 additions and 0 deletions
|
@ -98,6 +98,11 @@ struct ircd::m::room::state
|
||||||
state(const state &) = delete;
|
state(const state &) = delete;
|
||||||
state &operator=(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 prefetch(const state &, const string_view &, const event::idx_range &);
|
||||||
static size_t clear_history(const state &);
|
static size_t clear_history(const state &);
|
||||||
static size_t rebuild_history(const state &);
|
static size_t rebuild_history(const state &);
|
||||||
|
|
54
ircd/m.cc
54
ircd/m.cc
|
@ -3743,6 +3743,60 @@ ircd::m::room::state::prefetch(const state &state,
|
||||||
return call(state, type, range);
|
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::room
|
||||||
ircd::m::create(const id::room &room_id,
|
ircd::m::create(const id::room &room_id,
|
||||||
const id::user &creator,
|
const id::user &creator,
|
||||||
|
|
|
@ -826,6 +826,76 @@ ircd::m::room::state::prefetch(const state &state,
|
||||||
return ret;
|
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
|
extern "C" size_t
|
||||||
dagree_histogram(const m::room &room,
|
dagree_histogram(const m::room &room,
|
||||||
std::vector<size_t> &vec)
|
std::vector<size_t> &vec)
|
||||||
|
|
Loading…
Reference in a new issue