mirror of
https://github.com/matrix-construct/construct
synced 2024-11-26 08:42:34 +01:00
ircd:Ⓜ️:state: Move DFS recursor out of closure.
This commit is contained in:
parent
69427d7e43
commit
efeaf3475a
1 changed files with 53 additions and 41 deletions
|
@ -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
|
||||
ircd::m::state::dfs(const string_view &node_id,
|
||||
const search_closure &closure)
|
||||
|
@ -95,10 +100,23 @@ bool
|
|||
ircd::m::state::dfs(db::column &column,
|
||||
const string_view &node_id,
|
||||
const search_closure &closure)
|
||||
{
|
||||
bool ret{false};
|
||||
get_node(column, node_id, [&column, &closure, &ret]
|
||||
(const auto &node)
|
||||
{
|
||||
int depth(-1);
|
||||
const std::function<bool (const node &)> recurse{[&depth, &closure, &column, &recurse]
|
||||
(const node &node)
|
||||
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;
|
||||
const unwind down{[&depth]
|
||||
|
@ -109,14 +127,18 @@ ircd::m::state::dfs(db::column &column,
|
|||
const node::rep rep{node};
|
||||
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))
|
||||
{
|
||||
bool ret{false};
|
||||
get_node(column, child, [&ret, &recurse]
|
||||
get_node(column, child, [&column, &closure, &depth, &ret]
|
||||
(const auto &node)
|
||||
{
|
||||
ret = recurse(node);
|
||||
ret = _dfs_recurse(column, closure, node, depth);
|
||||
});
|
||||
|
||||
if(ret)
|
||||
|
@ -133,16 +155,6 @@ ircd::m::state::dfs(db::column &column,
|
|||
}
|
||||
|
||||
return false;
|
||||
}};
|
||||
|
||||
bool ret{false};
|
||||
get_node(column, node_id, [&ret, &recurse]
|
||||
(const auto &node)
|
||||
{
|
||||
ret = recurse(node);
|
||||
});
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Internal insertion operations
|
||||
|
|
Loading…
Reference in a new issue