From: Aina Niemetz Date: Tue, 13 Feb 2018 23:02:28 +0000 (-0800) Subject: Moved (unrecursified) bv::utils::collectVars. (#1602) X-Git-Tag: cvc5-1.0.0~5288 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=903570f7620aa989f6c717e8103c238069fc8d39;p=cvc5.git Moved (unrecursified) bv::utils::collectVars. (#1602) --- diff --git a/src/theory/bv/bv_subtheory_algebraic.cpp b/src/theory/bv/bv_subtheory_algebraic.cpp index ef5844e1f..888c95692 100644 --- a/src/theory/bv/bv_subtheory_algebraic.cpp +++ b/src/theory/bv/bv_subtheory_algebraic.cpp @@ -23,6 +23,7 @@ #include "theory/bv/theory_bv_utils.h" #include "theory/theory_model.h" +#include using namespace CVC4::context; using namespace CVC4::prop; @@ -33,6 +34,38 @@ namespace CVC4 { namespace theory { namespace bv { +/* ------------------------------------------------------------------------- */ + +namespace { + +/* Collect all variables under a given a node. */ +void collectVariables(TNode node, utils::NodeSet& vars) +{ + std::vector stack; + std::unordered_set visited; + + stack.push_back(node); + while (!stack.empty()) + { + Node n = stack.back(); + stack.pop_back(); + + if (vars.find(n) != vars.end()) continue; + if (visited.find(n) != visited.end()) continue; + visited.insert(n); + + if (Theory::isLeafOf(n, THEORY_BV) && n.getKind() != kind::CONST_BITVECTOR) + { + vars.insert(n); + continue; + } + stack.insert(stack.end(), n.begin(), n.end()); + } +} + +}; + +/* ------------------------------------------------------------------------- */ bool hasExpensiveBVOperators(TNode fact); Node mergeExplanations(const std::vector& expls); @@ -677,6 +710,7 @@ void AlgebraicSolver::assertFact(TNode fact) { EqualityStatus AlgebraicSolver::getEqualityStatus(TNode a, TNode b) { return EQUALITY_UNKNOWN; } + bool AlgebraicSolver::collectModelInfo(TheoryModel* model, bool fullModel) { Debug("bitvector-model") << "AlgebraicSolver::collectModelInfo\n"; @@ -705,7 +739,7 @@ bool AlgebraicSolver::collectModelInfo(TheoryModel* model, bool fullModel) TNode subst = Rewriter::rewrite(d_modelMap->apply(current)); Debug("bitvector-model") << " " << current << " => " << subst << "\n"; values[i] = subst; - utils::collectVariables(subst, leaf_vars); + collectVariables(subst, leaf_vars); } Debug("bitvector-model") << "Model:\n"; diff --git a/src/theory/bv/theory_bv_utils.cpp b/src/theory/bv/theory_bv_utils.cpp index eaa9f463b..ef56a30cc 100644 --- a/src/theory/bv/theory_bv_utils.cpp +++ b/src/theory/bv/theory_bv_utils.cpp @@ -496,24 +496,6 @@ void intersect(const std::vector& v1, /* ------------------------------------------------------------------------- */ -void collectVariables(TNode node, NodeSet& vars) -{ - if (vars.find(node) != vars.end()) return; - - if (Theory::isLeafOf(node, THEORY_BV) - && node.getKind() != kind::CONST_BITVECTOR) - { - vars.insert(node); - return; - } - for (unsigned i = 0; i < node.getNumChildren(); ++i) - { - collectVariables(node[i], vars); - } -} - -/* ------------------------------------------------------------------------- */ - }/* CVC4::theory::bv::utils namespace */ }/* CVC4::theory::bv namespace */ }/* CVC4::theory namespace */ diff --git a/src/theory/bv/theory_bv_utils.h b/src/theory/bv/theory_bv_utils.h index 1e27d75c0..e1a37cf76 100644 --- a/src/theory/bv/theory_bv_utils.h +++ b/src/theory/bv/theory_bv_utils.h @@ -2,7 +2,7 @@ /*! \file theory_bv_utils.h ** \verbatim ** Top contributors (to current version): - ** Aina Niemetz, Dejan Jovanovic, Morgan Deters + ** Aina Niemetz, Dejan Jovanovic, Tim King ** This file is part of the CVC4 project. ** Copyright (c) 2009-2018 by the authors listed in the file AUTHORS ** in the top-level source directory) and their institutional affiliations. @@ -194,9 +194,6 @@ void intersect(const std::vector& v1, const std::vector& v2, std::vector& intersection); -/* Collect all variables under a given a node. */ -void collectVariables(TNode node, NodeSet& vars); - } } }