Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Last active January 29, 2017 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deque-blog/65f8fc19540671737928bc1fd305cc55 to your computer and use it in GitHub Desktop.
Save deque-blog/65f8fc19540671737928bc1fd305cc55 to your computer and use it in GitHub Desktop.
template<typename Tag>
std::set<id> join_sets(op<Tag, std::set<id>> const& op)
{
std::set<id> out;
for (auto r: op.rands())
out.insert(r.begin(), r.end());
return out;
}
std::set<id> dependencies_alg(expression_r<std::set<id>> const& e)
{
if (auto* o = get_as_add(e)) return join_sets(*o);
if (auto* o = get_as_mul(e)) return join_sets(*o);
if (auto* v = get_as_var(e)) return {*v};
return {};
}
std::set<id> dependencies(expression const& e)
{
return cata<std::set<id>>(dependencies_alg, e);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment