cvc5-cvc5-1.2.0.src.expr.node_trie.cpp Maven / Gradle / Ivy
The newest version!
/******************************************************************************
* Top contributors (to current version):
* Andrew Reynolds, Mathias Preiner, Mudathir Mohamed
*
* This file is part of the cvc5 project.
*
* Copyright (c) 2009-2024 by the authors listed in the file AUTHORS
* in the top-level source directory and their institutional affiliations.
* All rights reserved. See the file COPYING in the top-level source
* directory for licensing information.
* ****************************************************************************
*
* Implementation of a trie class for Nodes and TNodes.
*/
#include "expr/node_trie.h"
namespace cvc5::internal {
template
NodeTemplate NodeTemplateTrie::existsTerm(
const std::vector>& reps) const
{
const NodeTemplateTrie* tnt = this;
typename std::map,
NodeTemplateTrie>::const_iterator it;
for (const NodeTemplate& r : reps)
{
it = tnt->d_data.find(r);
if (it == tnt->d_data.end())
{
// didn't find this child, return null
return Node::null();
}
tnt = &it->second;
}
if (tnt->d_data.empty())
{
return Node::null();
}
return tnt->d_data.begin()->first;
}
template TNode NodeTemplateTrie::existsTerm(
const std::vector& reps) const;
template Node NodeTemplateTrie::existsTerm(
const std::vector& reps) const;
template
NodeTemplate NodeTemplateTrie::addOrGetTerm(
NodeTemplate n, const std::vector>& reps)
{
NodeTemplateTrie* tnt = this;
for (const NodeTemplate& r : reps)
{
tnt = &(tnt->d_data[r]);
}
if (tnt->d_data.empty())
{
// Store n in d_data. This should be interpreted as the "data" and not as a
// reference to a child.
tnt->d_data[n].clear();
return n;
}
return tnt->d_data.begin()->first;
}
template TNode NodeTemplateTrie::addOrGetTerm(
TNode n, const std::vector& reps);
template Node NodeTemplateTrie::addOrGetTerm(
Node n, const std::vector& reps);
template
void NodeTemplateTrie::debugPrint(const char* c,
unsigned depth) const
{
for (const std::pair,
NodeTemplateTrie>& p : d_data)
{
for (unsigned i = 0; i < depth; i++)
{
Trace(c) << " ";
}
Trace(c) << p.first << std::endl;
p.second.debugPrint(c, depth + 1);
}
}
template void NodeTemplateTrie::debugPrint(const char* c,
unsigned depth) const;
template void NodeTemplateTrie::debugPrint(const char* c,
unsigned depth) const;
template
std::vector NodeTemplateTrie::getLeaves(size_t depth) const
{
Assert(depth > 0);
std::vector vec;
std::vector*, size_t>> visit;
visit.emplace_back(this, depth);
do
{
std::pair*, size_t> curr = visit.back();
visit.pop_back();
size_t currDepth = curr.second;
for (const std::pair,
NodeTemplateTrie>& p : curr.first->d_data)
{
if (currDepth == 0)
{
// we are at a leaf
vec.push_back(p.first);
break;
}
visit.emplace_back(&p.second, currDepth - 1);
}
} while (!visit.empty());
return vec;
}
template std::vector NodeTemplateTrie::getLeaves(
size_t depth) const;
template std::vector NodeTemplateTrie::getLeaves(
size_t depth) const;
} // namespace cvc5::internal