Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Side by Side Diff: third_party/libaddressinput/chromium/trie.h

Issue 298863012: Use upstream libaddressinput in Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Whitelist strings used on all platforms. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (C) 2014 Google Inc. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // 2 // Use of this source code is governed by a BSD-style license that can be
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // found in the LICENSE file.
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 4
15 #ifndef I18N_ADDRESSINPUT_UTIL_TRIE_H_ 5 #ifndef THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_TRIE_H_
16 #define I18N_ADDRESSINPUT_UTIL_TRIE_H_ 6 #define THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_TRIE_H_
17
18 #include <libaddressinput/util/basictypes.h>
19 7
20 #include <list> 8 #include <list>
21 #include <map> 9 #include <map>
22 #include <set> 10 #include <set>
23 #include <string> 11 #include <string>
24 12
25 namespace i18n { 13 #include "base/basictypes.h"
26 namespace addressinput { 14
15 namespace autofill {
27 16
28 // A prefix search tree. Can return all objects whose keys start with a prefix 17 // A prefix search tree. Can return all objects whose keys start with a prefix
29 // string. 18 // string.
30 // 19 //
31 // Maps keys to multiple objects. This property is useful when mapping region 20 // Maps keys to multiple objects. This property is useful when mapping region
32 // names to region objects. For example, there's a "St. Petersburg" in Florida, 21 // names to region objects. For example, there's a "St. Petersburg" in Florida,
33 // and there's a "St. Petersburg" in Russia. A lookup for "St. Petersburg" key 22 // and there's a "St. Petersburg" in Russia. A lookup for "St. Petersburg" key
34 // should return two distinct objects. 23 // should return two distinct objects.
35 template <typename T> 24 template <typename T>
36 class Trie { 25 class Trie {
37 public: 26 public:
38 Trie(); 27 Trie();
28 ~Trie();
39 29
40 ~Trie(); 30 // Returns true if no data was added in AddDataForKey().
31 bool empty() const { return data_list_.empty() && sub_nodes_.empty(); }
41 32
42 // Adds a mapping from |key| to |data_item|. Can be called with the same |key| 33 // Adds a mapping from |key| to |data_item|. Can be called with the same |key|
43 // multiple times. 34 // multiple times.
44 void AddDataForKey(const std::string& key, const T& data_item); 35 void AddDataForKey(const std::string& key, const T& data_item);
Evan Stade 2014/06/27 22:44:37 this was a netter api
please use gerrit instead 2014/06/28 22:05:21 Changed to "const std::vector<uint8_t>& key" and n
Evan Stade 2014/06/30 18:49:38 in case you were wondering, s/netter/nicer
please use gerrit instead 2014/07/01 04:53:50 Thanks :-) (I too typo tometimes)
45 36
46 // Adds all objects whose keys start with |key_prefix| to the |results| 37 // Adds all objects whose keys start with |key_prefix| to the |results|
47 // parameter. The |results| parameter should not be NULL. 38 // parameter. The |results| parameter should not be NULL.
48 void FindDataForKeyPrefix(const std::string& key_prefix, 39 void FindDataForKeyPrefix(const std::string& key_prefix,
49 std::set<T>* results) const; 40 std::set<T>* results) const;
50 41
51 private: 42 private:
52 // All objects for this node in the trie. This field is a collection to enable 43 // All objects for this node in the trie. This field is a collection to enable
53 // mapping the same key to multiple objects. 44 // mapping the same key to multiple objects.
54 std::list<T> data_list_; 45 std::list<T> data_list_;
55 46
56 // Trie sub nodes. The root trie stores the objects for the empty string key. 47 // Trie sub nodes. The root trie stores the objects for the empty string key.
57 // The children of the root trie store the objects for the one-letter keys. 48 // The children of the root trie store the objects for the one-letter keys.
58 // The grand-children of the root trie store the objects for the two-letter 49 // The grand-children of the root trie store the objects for the two-letter
59 // keys, and so on. 50 // keys, and so on.
60 std::map<char, Trie<T>*> sub_nodes_; 51 std::map<char, Trie<T>*> sub_nodes_;
61 52
62 DISALLOW_COPY_AND_ASSIGN(Trie); 53 DISALLOW_COPY_AND_ASSIGN(Trie);
63 }; 54 };
64 55
65 } // namespace addressinput 56 } // namespace autofill
66 } // namespace i18n
67 57
68 #endif // I18N_ADDRESSINPUT_UTIL_TRIE_H_ 58 #endif // THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_TRIE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698