OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/api/declarative/substring_set_matcher.h" | 5 #include "chrome/browser/extensions/api/declarative/substring_set_matcher.h" |
6 | 6 |
7 #include <queue> | 7 #include <queue> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 matches->insert(tree_[current_node].matches().begin(), | 85 matches->insert(tree_[current_node].matches().begin(), |
86 tree_[current_node].matches().end()); | 86 tree_[current_node].matches().end()); |
87 } else { | 87 } else { |
88 DCHECK_EQ(0, current_node); | 88 DCHECK_EQ(0, current_node); |
89 } | 89 } |
90 } | 90 } |
91 | 91 |
92 return old_number_of_matches != matches->size(); | 92 return old_number_of_matches != matches->size(); |
93 } | 93 } |
94 | 94 |
| 95 bool SubstringSetMatcher::IsEmpty() const { |
| 96 // An empty tree consists of only the root node. |
| 97 return patterns_.empty() && tree_.size() == 1u; |
| 98 } |
| 99 |
95 void SubstringSetMatcher::RebuildAhoCorasickTree() { | 100 void SubstringSetMatcher::RebuildAhoCorasickTree() { |
96 tree_.clear(); | 101 tree_.clear(); |
97 | 102 |
98 // Initialize root note of tree. | 103 // Initialize root note of tree. |
99 AhoCorasickNode root; | 104 AhoCorasickNode root; |
100 root.set_failure(0); | 105 root.set_failure(0); |
101 tree_.push_back(root); | 106 tree_.push_back(root); |
102 | 107 |
103 // Insert all patterns. | 108 // Insert all patterns. |
104 for (SubstringPatternSet::const_iterator i = patterns_.begin(); | 109 for (SubstringPatternSet::const_iterator i = patterns_.begin(); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 void SubstringSetMatcher::AhoCorasickNode::AddMatch(SubstringPattern::ID id) { | 215 void SubstringSetMatcher::AhoCorasickNode::AddMatch(SubstringPattern::ID id) { |
211 matches_.insert(id); | 216 matches_.insert(id); |
212 } | 217 } |
213 | 218 |
214 void SubstringSetMatcher::AhoCorasickNode::AddMatches( | 219 void SubstringSetMatcher::AhoCorasickNode::AddMatches( |
215 const SubstringSetMatcher::AhoCorasickNode::Matches& matches) { | 220 const SubstringSetMatcher::AhoCorasickNode::Matches& matches) { |
216 matches_.insert(matches.begin(), matches.end()); | 221 matches_.insert(matches.begin(), matches.end()); |
217 } | 222 } |
218 | 223 |
219 } // namespace extensions | 224 } // namespace extensions |
OLD | NEW |