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 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_SUBSTRING_SET_MATCHER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_SUBSTRING_SET_MATCHER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_SUBSTRING_SET_MATCHER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_SUBSTRING_SET_MATCHER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 void RegisterAndUnregisterPatterns( | 61 void RegisterAndUnregisterPatterns( |
62 const std::vector<const SubstringPattern*>& to_register, | 62 const std::vector<const SubstringPattern*>& to_register, |
63 const std::vector<const SubstringPattern*>& to_unregister); | 63 const std::vector<const SubstringPattern*>& to_unregister); |
64 | 64 |
65 // Matches |text| against all registered SubstringPatterns. Stores the IDs | 65 // Matches |text| against all registered SubstringPatterns. Stores the IDs |
66 // of matching patterns in |matches|. |matches| is not cleared before adding | 66 // of matching patterns in |matches|. |matches| is not cleared before adding |
67 // to it. | 67 // to it. |
68 bool Match(const std::string& text, | 68 bool Match(const std::string& text, |
69 std::set<SubstringPattern::ID>* matches) const; | 69 std::set<SubstringPattern::ID>* matches) const; |
70 | 70 |
71 // Returns true if this object retains no allocated data. Only for debugging. | |
72 bool IsCompletelyEmpty() const; | |
Matt Perry
2012/03/28 18:59:52
nit: IsEmpty should be fine... I wouldn't expect i
battre
2012/03/28 19:18:42
Done.
| |
73 | |
71 private: | 74 private: |
72 // A node of an Aho Corasick Tree. This is implemented according to | 75 // A node of an Aho Corasick Tree. This is implemented according to |
73 // http://www.cs.uku.fi/~kilpelai/BSA05/lectures/slides04.pdf | 76 // http://www.cs.uku.fi/~kilpelai/BSA05/lectures/slides04.pdf |
74 // | 77 // |
75 // The algorithm is based on the idea of building a trie of all registered | 78 // The algorithm is based on the idea of building a trie of all registered |
76 // patterns. Each node of the tree is annotated with a set of pattern | 79 // patterns. Each node of the tree is annotated with a set of pattern |
77 // IDs that are used to report matches. | 80 // IDs that are used to report matches. |
78 // | 81 // |
79 // The root of the trie represents an empty match. If we were looking whether | 82 // The root of the trie represents an empty match. If we were looking whether |
80 // any registered pattern matches a text at the beginning of the text (i.e. | 83 // any registered pattern matches a text at the beginning of the text (i.e. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 | 152 |
150 // The nodes of a Aho-Corasick tree. | 153 // The nodes of a Aho-Corasick tree. |
151 std::vector<AhoCorasickNode> tree_; | 154 std::vector<AhoCorasickNode> tree_; |
152 | 155 |
153 DISALLOW_COPY_AND_ASSIGN(SubstringSetMatcher); | 156 DISALLOW_COPY_AND_ASSIGN(SubstringSetMatcher); |
154 }; | 157 }; |
155 | 158 |
156 } // namespace extensions | 159 } // namespace extensions |
157 | 160 |
158 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_SUBSTRING_SET_MATCHER_H_ | 161 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_SUBSTRING_SET_MATCHER_H_ |
OLD | NEW |