GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/expr/node_trie.cpp Lines: 20 27 74.1 %
Date: 2021-05-24 Branches: 36 94 38.3 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Andrew Reynolds, Mathias Preiner
4
 *
5
 * This file is part of the cvc5 project.
6
 *
7
 * Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
8
 * in the top-level source directory and their institutional affiliations.
9
 * All rights reserved.  See the file COPYING in the top-level source
10
 * directory for licensing information.
11
 * ****************************************************************************
12
 *
13
 * Implementation of a trie class for Nodes and TNodes.
14
 */
15
16
#include "expr/node_trie.h"
17
18
namespace cvc5 {
19
namespace theory {
20
21
template <bool ref_count>
22
1679249
NodeTemplate<ref_count> NodeTemplateTrie<ref_count>::existsTerm(
23
    const std::vector<NodeTemplate<ref_count>>& reps) const
24
{
25
1679249
  const NodeTemplateTrie<ref_count>* tnt = this;
26
  typename std::map<NodeTemplate<ref_count>,
27
1679249
                    NodeTemplateTrie<ref_count>>::const_iterator it;
28
4497984
  for (const NodeTemplate<ref_count>& r : reps)
29
  {
30
3412197
    it = tnt->d_data.find(r);
31
3412197
    if (it == tnt->d_data.end())
32
    {
33
      // didn't find this child, return null
34
593462
      return Node::null();
35
    }
36
2818735
    tnt = &it->second;
37
  }
38
1085787
  if (tnt->d_data.empty())
39
  {
40
709
    return Node::null();
41
  }
42
1085078
  return tnt->d_data.begin()->first;
43
}
44
45
template TNode NodeTemplateTrie<false>::existsTerm(
46
    const std::vector<TNode>& reps) const;
47
template Node NodeTemplateTrie<true>::existsTerm(
48
    const std::vector<Node>& reps) const;
49
50
template <bool ref_count>
51
1377423
NodeTemplate<ref_count> NodeTemplateTrie<ref_count>::addOrGetTerm(
52
    NodeTemplate<ref_count> n, const std::vector<NodeTemplate<ref_count>>& reps)
53
{
54
1377423
  NodeTemplateTrie<ref_count>* tnt = this;
55
3894050
  for (const NodeTemplate<ref_count>& r : reps)
56
  {
57
2516627
    tnt = &(tnt->d_data[r]);
58
  }
59
1377423
  if (tnt->d_data.empty())
60
  {
61
    // Store n in d_data. This should be interpretted as the "data" and not as a
62
    // reference to a child.
63
1032832
    tnt->d_data[n].clear();
64
1032832
    return n;
65
  }
66
344591
  return tnt->d_data.begin()->first;
67
}
68
69
template TNode NodeTemplateTrie<false>::addOrGetTerm(
70
    TNode n, const std::vector<TNode>& reps);
71
template Node NodeTemplateTrie<true>::addOrGetTerm(
72
    Node n, const std::vector<Node>& reps);
73
74
template <bool ref_count>
75
void NodeTemplateTrie<ref_count>::debugPrint(const char* c,
76
                                             unsigned depth) const
77
{
78
  for (const std::pair<const NodeTemplate<ref_count>,
79
                       NodeTemplateTrie<ref_count>>& p : d_data)
80
  {
81
    for (unsigned i = 0; i < depth; i++)
82
    {
83
      Trace(c) << "  ";
84
    }
85
    Trace(c) << p.first << std::endl;
86
    p.second.debugPrint(c, depth + 1);
87
  }
88
}
89
90
template void NodeTemplateTrie<false>::debugPrint(const char* c,
91
                                                  unsigned depth) const;
92
template void NodeTemplateTrie<true>::debugPrint(const char* c,
93
                                                 unsigned depth) const;
94
95
}  // namespace theory
96
28191
}  // namespace cvc5