2023-02-17 05:41:09 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2023 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
|
|
|
size_t
|
2023-02-18 00:24:23 +01:00
|
|
|
ircd::m::room::missing::count()
|
2023-02-17 05:41:09 +01:00
|
|
|
const
|
|
|
|
{
|
|
|
|
size_t ret{0};
|
|
|
|
for_each([&ret]
|
|
|
|
(const auto &event_id, const auto &depth, const auto &event_idx) noexcept
|
|
|
|
{
|
|
|
|
++ret;
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2023-02-18 00:24:23 +01:00
|
|
|
ircd::m::room::missing::for_each(const closure &closure)
|
2023-02-17 05:41:09 +01:00
|
|
|
const
|
|
|
|
{
|
|
|
|
return for_each({0L, 0L}, closure);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2023-02-18 00:24:23 +01:00
|
|
|
ircd::m::room::missing::for_each(const pair<int64_t> &depth,
|
|
|
|
const closure &closure)
|
2023-02-17 05:41:09 +01:00
|
|
|
const
|
|
|
|
{
|
|
|
|
room::events it
|
|
|
|
{
|
|
|
|
room, uint64_t(depth.first)
|
|
|
|
};
|
|
|
|
|
|
|
|
for(; it; ++it)
|
|
|
|
{
|
|
|
|
if(depth.second && int64_t(it.depth()) > depth.second)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if(!_each(it, closure))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2023-02-18 00:24:23 +01:00
|
|
|
ircd::m::room::missing::rfor_each(const pair<int64_t> &depth,
|
|
|
|
const closure &closure)
|
2023-02-17 05:41:09 +01:00
|
|
|
const
|
|
|
|
{
|
|
|
|
room::events it
|
|
|
|
{
|
|
|
|
room, depth.second?: -1UL
|
|
|
|
};
|
|
|
|
|
|
|
|
for(; it; --it)
|
|
|
|
{
|
|
|
|
if(depth.second && int64_t(it.depth()) > depth.second)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(int64_t(it.depth()) < depth.first)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if(!_each(it, closure))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2023-02-18 00:24:23 +01:00
|
|
|
ircd::m::room::missing::_each(m::room::events &it,
|
|
|
|
const closure &closure)
|
2023-02-17 05:41:09 +01:00
|
|
|
const
|
|
|
|
{
|
2023-02-18 04:49:23 +01:00
|
|
|
const auto &[depth, event_idx]
|
2023-02-17 05:41:09 +01:00
|
|
|
{
|
|
|
|
*it
|
|
|
|
};
|
|
|
|
|
2023-02-18 04:49:23 +01:00
|
|
|
const m::event::fetch event
|
|
|
|
{
|
|
|
|
std::nothrow, event_idx
|
|
|
|
};
|
|
|
|
|
2023-02-17 05:41:09 +01:00
|
|
|
const event::prev prev
|
|
|
|
{
|
|
|
|
event
|
|
|
|
};
|
|
|
|
|
|
|
|
event::idx idx_buf[event::prev::MAX];
|
2023-02-18 04:49:23 +01:00
|
|
|
const auto prev_idx
|
2023-02-17 05:41:09 +01:00
|
|
|
{
|
|
|
|
prev.idxs(idx_buf)
|
|
|
|
};
|
|
|
|
|
2023-02-18 04:49:23 +01:00
|
|
|
for(size_t i(0); i < prev_idx.size(); ++i)
|
2023-02-17 05:41:09 +01:00
|
|
|
{
|
2023-02-18 04:49:23 +01:00
|
|
|
if(prev_idx[i])
|
2023-02-17 05:41:09 +01:00
|
|
|
continue;
|
|
|
|
|
2023-02-18 04:49:23 +01:00
|
|
|
if(!closure(prev.prev_event(i), depth, event_idx))
|
2023-02-17 05:41:09 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|