0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 18:22:50 +01:00

ircd:Ⓜ️:state: Move DFS recursor out of closure.

This commit is contained in:
Jason Volk 2018-02-05 11:00:19 -08:00
parent 69427d7e43
commit efeaf3475a

View file

@ -79,6 +79,11 @@ ircd::m::state::get(db::column &column,
}); });
} }
namespace ircd::m::state
{
bool _dfs_recurse(db::column &, const search_closure &, const node &, int &);
}
bool bool
ircd::m::state::dfs(const string_view &node_id, ircd::m::state::dfs(const string_view &node_id,
const search_closure &closure) const search_closure &closure)
@ -96,10 +101,23 @@ ircd::m::state::dfs(db::column &column,
const string_view &node_id, const string_view &node_id,
const search_closure &closure) const search_closure &closure)
{ {
int depth(-1); bool ret{false};
const std::function<bool (const node &)> recurse{[&depth, &closure, &column, &recurse] get_node(column, node_id, [&column, &closure, &ret]
(const node &node) (const auto &node)
{ {
int depth(-1);
ret = _dfs_recurse(column, closure, node, depth);
});
return ret;
}
bool
ircd::m::state::_dfs_recurse(db::column &column,
const search_closure &closure,
const node &node,
int &depth)
{
++depth; ++depth;
const unwind down{[&depth] const unwind down{[&depth]
{ {
@ -109,14 +127,18 @@ ircd::m::state::dfs(db::column &column,
const node::rep rep{node}; const node::rep rep{node};
for(uint pos(0); pos < rep.kn || pos < rep.cn; ++pos) for(uint pos(0); pos < rep.kn || pos < rep.cn; ++pos)
{ {
const auto child{unquote(rep.chld[pos])}; const auto child
{
unquote(rep.chld[pos])
};
if(!empty(child)) if(!empty(child))
{ {
bool ret{false}; bool ret{false};
get_node(column, child, [&ret, &recurse] get_node(column, child, [&column, &closure, &depth, &ret]
(const auto &node) (const auto &node)
{ {
ret = recurse(node); ret = _dfs_recurse(column, closure, node, depth);
}); });
if(ret) if(ret)
@ -133,16 +155,6 @@ ircd::m::state::dfs(db::column &column,
} }
return false; return false;
}};
bool ret{false};
get_node(column, node_id, [&ret, &recurse]
(const auto &node)
{
ret = recurse(node);
});
return ret;
} }
// Internal insertion operations // Internal insertion operations