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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
diff --git a/re2/prefilter_tree.cc b/re2/prefilter_tree.cc
--- a/re2/prefilter_tree.cc
+++ b/re2/prefilter_tree.cc
@@ -107,21 +107,23 @@ void PrefilterTree::Compile(vector<string>* atom_vec) {
// not miss out on any regexps triggering by getting rid of a
// prefilter node.
for (int i = 0; i < entries_.size(); i++) {
- IntMap* parents = entries_[i].parents;
+ StdIntMap* parents = entries_[i].parents;
if (parents->size() > 8) {
// This one triggers too many things. If all the parents are AND
// nodes and have other things guarding them, then get rid of
// this trigger. TODO(vsri): Adjust the threshold appropriately,
// make it a function of total number of nodes?
bool have_other_guard = true;
- for (IntMap::iterator it = parents->begin(); it != parents->end(); ++it)
+ for (StdIntMap::iterator it = parents->begin();
+ it != parents->end(); ++it) {
have_other_guard = have_other_guard &&
- (entries_[it->index()].propagate_up_at_count > 1);
+ (entries_[it->first].propagate_up_at_count > 1);
+ }
if (have_other_guard) {
- for (IntMap::iterator it = parents->begin();
+ for (StdIntMap::iterator it = parents->begin();
it != parents->end(); ++it)
- entries_[it->index()].propagate_up_at_count -= 1;
+ entries_[it->first].propagate_up_at_count -= 1;
parents->clear(); // Forget the parents
}
@@ -213,7 +215,7 @@ void PrefilterTree::AssignUniqueIds(vector<string>* atom_vec) {
}
entries_.resize(node_map_.size());
- // Create parent IntMap for the entries.
+ // Create parent StdIntMap for the entries.
for (int i = v.size() - 1; i >= 0; i--) {
Prefilter* prefilter = v[i];
if (prefilter == NULL)
@@ -223,7 +225,7 @@ void PrefilterTree::AssignUniqueIds(vector<string>* atom_vec) {
continue;
Entry* entry = &entries_[prefilter->unique_id()];
- entry->parents = new IntMap(node_map_.size());
+ entry->parents = new StdIntMap();
}
// Fill the entries.
@@ -249,7 +251,7 @@ void PrefilterTree::AssignUniqueIds(vector<string>* atom_vec) {
case Prefilter::OR:
case Prefilter::AND: {
- IntMap uniq_child(node_map_.size());
+ std::set<int> uniq_child;
for (int j = 0; j < prefilter->subs()->size() ; j++) {
Prefilter* child = (*prefilter->subs())[j];
Prefilter* canonical = CanonicalNode(child);
@@ -258,12 +260,12 @@ void PrefilterTree::AssignUniqueIds(vector<string>* atom_vec) {
return;
}
int child_id = canonical->unique_id();
- if (!uniq_child.has_index(child_id))
- uniq_child.set_new(child_id, 1);
+ uniq_child.insert(child_id);
// To the child, we want to add to parent indices.
Entry* child_entry = &entries_[child_id];
- if (!child_entry->parents->has_index(prefilter->unique_id()))
- child_entry->parents->set_new(prefilter->unique_id(), 1);
+ if (child_entry->parents->find(prefilter->unique_id()) ==
+ child_entry->parents->end())
+ (*child_entry->parents)[prefilter->unique_id()] = 1;
}
entry->propagate_up_at_count =
prefilter->op() == Prefilter::AND ? uniq_child.size() : 1;
@@ -329,10 +331,10 @@ void PrefilterTree::PropagateMatch(const vector<int>& atom_ids,
}
int c;
// Pass trigger up to parents.
- for (IntMap::iterator it = entry.parents->begin();
+ for (StdIntMap::iterator it = entry.parents->begin();
it != entry.parents->end();
++it) {
- int j = it->index();
+ int j = it->first;
const Entry& parent = entries_[j];
VLOG(10) << " parent= " << j << " trig= " << parent.propagate_up_at_count;
// Delay until all the children have succeeded.
@@ -364,12 +366,12 @@ void PrefilterTree::PrintDebugInfo() {
VLOG(10) << "#Unique Nodes: " << entries_.size();
for (int i = 0; i < entries_.size(); ++i) {
- IntMap* parents = entries_[i].parents;
+ StdIntMap* parents = entries_[i].parents;
const vector<int>& regexps = entries_[i].regexps;
VLOG(10) << "EntryId: " << i
<< " N: " << parents->size() << " R: " << regexps.size();
- for (IntMap::iterator it = parents->begin(); it != parents->end(); ++it)
- VLOG(10) << it->index();
+ for (StdIntMap::iterator it = parents->begin(); it != parents->end(); ++it)
+ VLOG(10) << it->first;
}
VLOG(10) << "Map:";
for (map<string, Prefilter*>::const_iterator iter = node_map_.begin();
diff --git a/re2/prefilter_tree.h b/re2/prefilter_tree.h
--- a/re2/prefilter_tree.h
+++ b/re2/prefilter_tree.h
@@ -16,12 +16,15 @@
#ifndef RE2_PREFILTER_TREE_H_
#define RE2_PREFILTER_TREE_H_
+#include <map>
+
#include "util/util.h"
#include "util/sparse_array.h"
namespace re2 {
typedef SparseArray<int> IntMap;
+typedef std::map<int, int> StdIntMap;
class Prefilter;
@@ -71,7 +74,7 @@ class PrefilterTree {
// are two different nodes, but they share the atom 'def'. So when
// 'def' matches, it triggers two parents, corresponding to the two
// different OR nodes.
- IntMap* parents;
+ StdIntMap* parents;
// When this node is ready to trigger the parent, what are the
// regexps that are triggered.
|