blob: bb70a18fea760f7ab5fd365c84a4ba8bc7c3024f (
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
|
/********************* */
/*! \file trigger_trie.cpp
** \verbatim
** Top contributors (to current version):
** Andrew Reynolds, Morgan Deters, Mathias Preiner
** This file is part of the CVC4 project.
** Copyright (c) 2009-2020 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.\endverbatim
**
** \brief Implementation of trigger trie class
**/
#include "theory/quantifiers/ematching/trigger_trie.h"
namespace CVC4 {
namespace theory {
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 theory
} // namespace CVC4
|