0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 10:12:39 +01:00

ircd:Ⓜ️:state: Might as well typedef this id.

This commit is contained in:
Jason Volk 2018-02-10 17:11:23 -08:00
parent 6c6069fc2c
commit e368101e54
2 changed files with 36 additions and 35 deletions

View file

@ -36,8 +36,9 @@ namespace ircd::m::state
constexpr size_t NODE_MAX_DEG { NODE_MAX_KEY + 1 }; // tmp for now
constexpr int8_t MAX_HEIGHT { 16 }; // good for few mil at any degree :)
using id = string_view;
using id_buffer = fixed_buffer<mutable_buffer, ID_MAX_SZ>;
using id_closure = std::function<void (const string_view &)>;
using id_closure = std::function<void (const id &)>;
using val_closure = std::function<void (const string_view &)>;
using node_closure = std::function<void (const json::object &)>;
using search_closure = std::function<bool (const json::array &, const string_view &, const uint &, const uint &)>;
@ -49,30 +50,30 @@ namespace ircd::m::state
json::array make_key(const mutable_buffer &out, const string_view &type, const string_view &state_key);
json::array make_key(const mutable_buffer &out, const string_view &type);
string_view set_node(db::txn &txn, const mutable_buffer &id, const json::object &node);
id set_node(db::txn &txn, const mutable_buffer &id, const json::object &node);
void get_node(const string_view &id, const node_closure &);
string_view insert(db::txn &, const mutable_buffer &rootout, const string_view &rootin, const json::array &key, const id::event &);
string_view insert(db::txn &, const mutable_buffer &rootout, const string_view &rootin, const string_view &type, const string_view &state_key, const id::event &);
string_view insert(db::txn &, const mutable_buffer &rootout, const string_view &rootin, const event &);
id insert(db::txn &, const mutable_buffer &rootout, const id &rootin, const json::array &key, const m::id::event &);
id insert(db::txn &, const mutable_buffer &rootout, const id &rootin, const string_view &type, const string_view &state_key, const m::id::event &);
id insert(db::txn &, const mutable_buffer &rootout, const id &rootin, const event &);
bool dfs(const string_view &root, const json::array &key, const search_closure &);
bool dfs(const string_view &root, const search_closure &);
bool dfs(const id &root, const json::array &key, const search_closure &);
bool dfs(const id &root, const search_closure &);
bool test(const string_view &root, const iter_bool_closure &);
bool test(const string_view &root, const string_view &type, const iter_bool_closure &);
bool test(const id &root, const iter_bool_closure &);
bool test(const id &root, const string_view &type, const iter_bool_closure &);
void for_each(const string_view &root, const iter_closure &);
void for_each(const string_view &root, const string_view &type, const iter_closure &);
void for_each(const id &root, const iter_closure &);
void for_each(const id &root, const string_view &type, const iter_closure &);
size_t count(const string_view &root, const iter_bool_closure &);
size_t count(const string_view &root);
size_t count(const id &root, const iter_bool_closure &);
size_t count(const id &root);
bool get(std::nothrow_t, const string_view &root, const json::array &key, const val_closure &);
void get(const string_view &root, const json::array &key, const val_closure &);
bool get(std::nothrow_t, const id &root, const json::array &key, const val_closure &);
void get(const id &root, const json::array &key, const val_closure &);
bool get(std::nothrow_t, const string_view &root, const string_view &type, const string_view &state_key, const val_closure &);
void get(const string_view &root, const string_view &type, const string_view &state_key, const val_closure &);
bool get(std::nothrow_t, const id &root, const string_view &type, const string_view &state_key, const val_closure &);
void get(const id &root, const string_view &type, const string_view &state_key, const val_closure &);
}
/// JSON property name strings specifically for use in m::state
@ -139,11 +140,11 @@ struct ircd::m::state::node
json::array key(const size_t &) const;
string_view val(const size_t &) const;
string_view child(const size_t &) const;
state::id child(const size_t &) const;
size_t keys(json::array *const &out, const size_t &max) const;
size_t vals(string_view *const &out, const size_t &max) const;
size_t childs(string_view *const &out, const size_t &max) const;
size_t childs(state::id *const &out, const size_t &max) const;
size_t find(const json::array &key) const;
bool has_key(const json::array &key) const;
@ -165,7 +166,7 @@ struct ircd::m::state::node::rep
{
std::array<json::array, NODE_MAX_KEY + 1> keys;
std::array<string_view, NODE_MAX_VAL + 1> vals;
std::array<string_view, NODE_MAX_DEG + 1> chld;
std::array<state::id, NODE_MAX_DEG + 1> chld;
size_t kn {0};
size_t vn {0};
size_t cn {0};
@ -179,7 +180,7 @@ struct ircd::m::state::node::rep
void shr(const size_t &pos);
json::object write(const mutable_buffer &out);
string_view write(db::txn &, const mutable_buffer &id);
state::id write(db::txn &, const mutable_buffer &id);
rep(const node &node);
rep() = default;

View file

@ -247,7 +247,7 @@ namespace ircd::m::state
/// State update from an event. Leaves the root node ID in the root buffer;
/// returns view.
///
ircd::string_view
ircd::m::state::id
ircd::m::state::insert(db::txn &txn,
const mutable_buffer &rootout,
const string_view &rootin,
@ -267,7 +267,7 @@ ircd::m::state::insert(db::txn &txn,
return insert(txn, rootout, rootin, type, state_key, event_id);
}
ircd::string_view
ircd::m::state::id
ircd::m::state::_create(db::txn &txn,
const mutable_buffer &root,
const string_view &type,
@ -297,13 +297,13 @@ ircd::m::state::_create(db::txn &txn,
/// State update for room_id inserting (type,state_key) = event_id into the
/// tree. Leaves the root node ID in the root buffer; returns view.
ircd::string_view
ircd::m::state::id
ircd::m::state::insert(db::txn &txn,
const mutable_buffer &rootout,
const string_view &rootin,
const string_view &type,
const string_view &state_key,
const id::event &event_id)
const m::id::event &event_id)
{
// The insertion process reads from the DB and will yield this ircd::ctx
// so the key buffer must stay on this stack.
@ -311,12 +311,12 @@ ircd::m::state::insert(db::txn &txn,
return insert(txn, rootout, rootin, make_key(key, type, state_key), event_id);
}
ircd::string_view
ircd::m::state::id
ircd::m::state::insert(db::txn &txn,
const mutable_buffer &rootout,
const string_view &rootin,
const json::array &key,
const id::event &event_id)
const m::id::event &event_id)
{
node::rep push;
int8_t height{0};
@ -332,7 +332,7 @@ ircd::m::state::insert(db::txn &txn,
return root;
}
ircd::string_view
ircd::m::state::id
ircd::m::state::_insert(int8_t &height,
db::txn &txn,
const json::array &key,
@ -496,7 +496,7 @@ ircd::m::state::_insert_leaf_full(const int8_t &height,
return ret;
}
ircd::string_view
ircd::m::state::id
ircd::m::state::_insert_branch_nonfull(db::txn &txn,
const mutable_buffer &idbuf,
node::rep &rep,
@ -518,7 +518,7 @@ ircd::m::state::_insert_branch_nonfull(db::txn &txn,
return rep.write(txn, idbuf);
}
ircd::string_view
ircd::m::state::id
ircd::m::state::_insert_leaf_nonfull(db::txn &txn,
const json::array &key,
const string_view &val,
@ -540,7 +540,7 @@ ircd::m::state::_insert_leaf_nonfull(db::txn &txn,
return rep.write(txn, idbuf);
}
ircd::string_view
ircd::m::state::id
ircd::m::state::_insert_overwrite(db::txn &txn,
const json::array &key,
const string_view &val,
@ -582,7 +582,7 @@ ircd::m::state::get_node(const string_view &node_id,
/// Writes a node to the db::txn and returns the id of this node (a hash) into
/// the buffer.
ircd::string_view
ircd::m::state::id
ircd::m::state::set_node(db::txn &iov,
const mutable_buffer &hashbuf,
const json::object &node)
@ -708,7 +708,7 @@ ircd::m::state::node::rep::rep(const node &node)
{
}
ircd::string_view
ircd::m::state::id
ircd::m::state::node::rep::write(db::txn &txn,
const mutable_buffer &idbuf)
{
@ -873,7 +873,7 @@ const
}
size_t
ircd::m::state::node::childs(string_view *const &out,
ircd::m::state::node::childs(state::id *const &out,
const size_t &max)
const
{
@ -911,7 +911,7 @@ const
return i;
}
ircd::string_view
ircd::m::state::id
ircd::m::state::node::child(const size_t &pos)
const
{