0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-10 05:58:56 +02:00

ircd:Ⓜ️:event: Add refs interface.

This commit is contained in:
Jason Volk 2019-02-06 16:27:48 -08:00
parent 2586476a57
commit ec8f0c1e1c
4 changed files with 105 additions and 0 deletions

View file

@ -33,6 +33,7 @@ namespace ircd::m
#include "event/event.h"
#include "event/prev.h"
#include "event/refs.h"
#include "event/index.h"
#include "event/fetch.h"
#include "event/get.h"

View file

@ -78,6 +78,7 @@ struct ircd::m::event
>
{
struct prev;
struct refs;
struct fetch;
struct conforms;

View file

@ -0,0 +1,34 @@
// Matrix Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2018 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.
#pragma once
#define HAVE_IRCD_M_EVENT_REFS_H
struct ircd::m::event::refs
{
using closure_bool = event::closure_idx_bool;
event::idx idx;
public:
bool for_each(const closure_bool &) const;
bool has(const event::idx &) const noexcept;
size_t count() const noexcept;
refs(const event::idx &idx) noexcept;
};
inline
ircd::m::event::refs::refs(const event::idx &idx)
noexcept
:idx{idx}
{
assert(idx);
}

View file

@ -1034,6 +1034,75 @@ ircd::m::index(const event::id &event_id,
});
}
///////////////////////////////////////////////////////////////////////////////
//
// event/refs.h
//
size_t
ircd::m::event::refs::count()
const noexcept
{
assert(idx);
size_t ret(0);
for_each([&ret](const auto &)
{
++ret;
return true;
});
return ret;
}
bool
ircd::m::event::refs::has(const event::idx &idx)
const noexcept
{
return !for_each([&idx](const event::idx &ref)
{
return ref != idx; // true to continue, false to break
});
}
bool
ircd::m::event::refs::for_each(const closure_bool &closure)
const
{
auto &column
{
dbs::event_refs
};
const byte_view<string_view> &key
{
idx
};
auto it
{
column.begin(key)
};
for(; it; ++it)
{
const auto parts
{
dbs::event_refs_key(it->first)
};
const auto &ref
{
std::get<0>(parts)
};
assert(idx != ref);
if(!closure(ref))
return false;
}
return true;
}
///////////////////////////////////////////////////////////////////////////////
//
// event/prev.h