summaryrefslogtreecommitdiff
path: root/src/theory/quantifiers/ematching/trigger_trie.cpp
blob: 964338f621c033f68990a4d8a9e19c02fed37fe8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/******************************************************************************
 * Top contributors (to current version):
 *   Andrew Reynolds, Morgan Deters, Tim King
 *
 * This file is part of the cvc5 project.
 *
 * Copyright (c) 2009-2021 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 trigger trie class.
 */

#include "theory/quantifiers/ematching/trigger_trie.h"

namespace cvc5 {
namespace theory {
namespace quantifiers {
namespace inst {

TriggerTrie::TriggerTrie() {}

TriggerTrie::~TriggerTrie()
{
  for (size_t i = 0, ntriggers = d_tr.size(); i < ntriggers; i++)
  {
    delete d_tr[i];
  }
}

inst::Trigger* TriggerTrie::getTrigger(std::vector<Node>& nodes)
{
  std::vector<Node> temp;
  temp.insert(temp.begin(), nodes.begin(), nodes.end());
  std::sort(temp.begin(), temp.end());
  TriggerTrie* tt = this;
  for (const Node& n : temp)
  {
    std::map<TNode, TriggerTrie>::iterator itt = tt->d_children.find(n);
    if (itt == tt->d_children.end())
    {
      return nullptr;
    }
    else
    {
      tt = &(itt->second);
    }
  }
  return tt->d_tr.empty() ? nullptr : tt->d_tr[0];
}

void TriggerTrie::addTrigger(std::vector<Node>& nodes, inst::Trigger* t)
{
  std::vector<Node> temp(nodes.begin(), nodes.end());
  std::sort(temp.begin(), temp.end());
  TriggerTrie* tt = this;
  for (const Node& n : temp)
  {
    std::map<TNode, TriggerTrie>::iterator itt = tt->d_children.find(n);
    if (itt == tt->d_children.end())
    {
      TriggerTrie* ttn = &tt->d_children[n];
      tt = ttn;
    }
    else
    {
      tt = &(itt->second);
    }
  }
  tt->d_tr.push_back(t);
}

}  // namespace inst
}  // namespace quantifiers
}  // namespace theory
}  // namespace cvc5
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback