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

Unified 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: Fixup includes and comments for tries and ICU. Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: third_party/libaddressinput/chromium/trie.h
diff --git a/third_party/libaddressinput/chromium/trie.h b/third_party/libaddressinput/chromium/trie.h
new file mode 100644
index 0000000000000000000000000000000000000000..2a97316cb6ad37e5784a2e86b0e0ead15e0acdc6
--- /dev/null
+++ b/third_party/libaddressinput/chromium/trie.h
@@ -0,0 +1,55 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_TRIE_H_
+#define THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_TRIE_H_
+
+#include <stdint.h>
+#include <map>
+#include <set>
+
+namespace autofill {
+
+// A prefix search tree. Can return all objects whose keys start with a prefix
+// byte sequence.
+//
+// Maps keys to multiple objects. This property is useful when mapping region
+// names to region objects. For example, there's a "St. Petersburg" in Florida,
+// and there's a "St. Petersburg" in Russia. A lookup for "St. Petersburg" key
+// should return two distinct objects.
+template <typename T>
+class Trie {
+ public:
+ Trie();
+ ~Trie();
+
+ // Returns true if no data was added in AddDataForKey().
+ bool empty() const { return data_list_.empty() && sub_nodes_.empty(); }
+
+ // Adds a mapping from |key| to |data_item|. Can be called with the same |key|
+ // multiple times. Does not take ownership of |key|, which should not be NULL.
+ void AddDataForKey(const uint8_t* key, int32_t key_size, const T& data_item);
Evan Stade 2014/06/27 22:44:38 a) sizes are usually size_t b) this is a really co
please use gerrit instead 2014/06/28 22:05:21 Using std::vector<uint8_t> now.
+
+ // Adds all objects whose keys start with |key_prefix| to the |results|
+ // parameter. Does not take ownership of |key_prefix|, which should not be
+ // NULL. The |results| parameter should not be NULL.
+ void FindDataForKeyPrefix(const uint8_t* key_prefix,
+ int32_t key_prefix_size,
+ std::set<T>* results) const;
+
+ private:
+ // All objects for this node in the Trie. This field is a collection to enable
+ // mapping the same key to multiple objects.
+ std::set<T> data_list_;
+
+ // Trie sub nodes. The root Trie stores the objects for the empty key. The
+ // children of the root Trie store the objects for the one-byte keys. The
+ // grand-children of the root Trie store the objects for the two-byte keys,
+ // and so on.
+ std::map<uint8_t, Trie<T> > sub_nodes_;
+};
+
+} // namespace autofill
+
+#endif // THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_TRIE_H_

Powered by Google App Engine
This is Rietveld 408576698