2020-10-27 08:10:48 +01:00
|
|
|
// The Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) The Construct Developers, Authors & Contributors
|
2023-02-22 04:47:25 +01:00
|
|
|
// Copyright (C) 2016-2023 Jason Volk <jason@zemos.net>
|
2020-10-27 08:10:48 +01:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
#pragma once
|
2023-02-22 04:47:25 +01:00
|
|
|
#define HAVE_IRCD_M_ROOM_ITERATE_H
|
2020-10-27 08:10:48 +01:00
|
|
|
|
2023-02-22 04:47:25 +01:00
|
|
|
/// Interfaced optimized for pipelined iterations of room events.
|
2020-10-27 08:10:48 +01:00
|
|
|
///
|
2023-02-22 04:47:25 +01:00
|
|
|
struct ircd::m::room::iterate
|
2020-10-27 08:10:48 +01:00
|
|
|
{
|
2022-08-06 03:38:32 +02:00
|
|
|
using entry = pair<uint64_t, m::event::idx>;
|
2023-02-17 05:53:30 +01:00
|
|
|
using closure = util::function_bool
|
2020-10-27 08:10:48 +01:00
|
|
|
<
|
2023-02-22 04:47:25 +01:00
|
|
|
const string_view, const uint64_t, const event::idx
|
2020-10-27 08:10:48 +01:00
|
|
|
>;
|
|
|
|
|
|
|
|
static conf::item<size_t> prefetch;
|
|
|
|
|
|
|
|
m::room room;
|
2023-02-22 04:47:25 +01:00
|
|
|
string_view column;
|
2020-10-27 08:10:48 +01:00
|
|
|
std::pair<uint64_t, int64_t> range; // highest (inclusive) to lowest (exclusive)
|
2022-08-06 03:38:32 +02:00
|
|
|
size_t queue_max;
|
|
|
|
std::unique_ptr<entry[]> buf;
|
2020-10-27 08:10:48 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
bool for_each(const closure &) const;
|
|
|
|
|
2023-02-22 04:47:25 +01:00
|
|
|
iterate(const m::room &,
|
|
|
|
const string_view &column = {},
|
|
|
|
const decltype(range) & = { -1UL, -1L });
|
2022-08-06 03:38:32 +02:00
|
|
|
|
2023-02-22 04:47:25 +01:00
|
|
|
iterate(const iterate &) = delete;
|
|
|
|
iterate(iterate &&) = delete;
|
2020-10-27 08:10:48 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
inline
|
2023-02-22 04:47:25 +01:00
|
|
|
ircd::m::room::iterate::iterate(const m::room &room,
|
|
|
|
const string_view &column,
|
2020-10-27 08:10:48 +01:00
|
|
|
const decltype(range) &range)
|
|
|
|
:room{room}
|
2023-02-22 04:47:25 +01:00
|
|
|
,column{column}
|
2020-10-27 08:10:48 +01:00
|
|
|
,range{range}
|
2022-08-06 03:38:32 +02:00
|
|
|
,queue_max{prefetch}
|
|
|
|
,buf
|
|
|
|
{
|
|
|
|
new entry[queue_max]
|
|
|
|
{
|
|
|
|
{ 0UL, 0UL }
|
|
|
|
}
|
|
|
|
}
|
2020-10-27 08:10:48 +01:00
|
|
|
{}
|