diff --git a/include/ircd/m/state.h b/include/ircd/m/state.h index 9db0d11c2..b853cb85b 100644 --- a/include/ircd/m/state.h +++ b/include/ircd/m/state.h @@ -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; - using id_closure = std::function; + using id_closure = std::function; using val_closure = std::function; using node_closure = std::function; using search_closure = std::function; @@ -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 keys; std::array vals; - std::array chld; + std::array 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; diff --git a/ircd/m/state.cc b/ircd/m/state.cc index 79f0da5b6..2a54f3b49 100644 --- a/ircd/m/state.cc +++ b/ircd/m/state.cc @@ -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 {