{
visit.push_back(cur.getOperator());
}
- for (const TNode& cn : cur)
- {
- visit.push_back(cn);
- }
+ visit.insert(visit.end(), cur.begin(), cur.end());
}
else if (!itv->second)
{
}
else
{
- for (const TNode& cn : cur)
- {
- visit.push_back(cn);
- }
+ visit.insert(visit.end(), cur.begin(), cur.end());
}
visited.insert(cur);
}
{
visit.push_back(cur.getOperator());
}
- for (TNode cn : cur)
+ visit.insert(visit.end(), cur.begin(), cur.end());
+ }
+ } while (!visit.empty());
+}
+
+void getKindSubterms(TNode n,
+ Kind k,
+ bool topLevel,
+ std::unordered_set<Node, NodeHashFunction>& ts)
+{
+ std::unordered_set<TNode, TNodeHashFunction> visited;
+ std::vector<TNode> visit;
+ TNode cur;
+ visit.push_back(n);
+ do
+ {
+ cur = visit.back();
+ visit.pop_back();
+ if (visited.find(cur) == visited.end())
+ {
+ visited.insert(cur);
+ if (cur.getKind() == k)
+ {
+ ts.insert(cur);
+ if (topLevel)
+ {
+ // only considering top-level applications
+ continue;
+ }
+ }
+ if (cur.hasOperator())
{
- visit.push_back(cn);
+ visit.push_back(cur.getOperator());
}
+ visit.insert(visit.end(), cur.begin(), cur.end());
}
} while (!visit.empty());
}
ops[tn].insert(o);
}
// add children to visit in the future
- for (TNode cn : cur)
- {
- visit.push_back(cn);
- }
+ visit.insert(visit.end(), cur.begin(), cur.end());
}
} while (!visit.empty());
}
std::unordered_set<Node, NodeHashFunction>& syms,
std::unordered_set<TNode, TNodeHashFunction>& visited);
+/**
+ * For term n, this function collects the subterms of n whose kind is k.
+ * @param n The node under investigation
+ * @param k The kind we are considering
+ * @param topLevel If true, we collect only the top-level subterms with kind k.
+ * @param ts The set which the symbols of n are added to
+ */
+void getKindSubterms(TNode n,
+ Kind k,
+ bool topLevel,
+ std::unordered_set<Node, NodeHashFunction>& ts);
+
/**
* For term n, this function collects the operators that occur in n.
* @param n The node under investigation