Flutter Engine
ascii_trie.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FLUTTER_FML_ASCIITRIE_H_
6 #define FLUTTER_FML_ASCIITRIE_H_
7 
8 #include <memory>
9 #include <string>
10 #include <vector>
11 
12 namespace fml {
13 
14 /// A trie for looking for ASCII prefixes.
15 class AsciiTrie {
16  public:
17  struct TrieNode;
18  typedef std::unique_ptr<TrieNode> TrieNodePtr;
19  /// The max Ascii value.
20  static const int kMaxAsciiValue = 128;
21 
22  /// Clear and insert all the entries into the trie.
23  void Fill(const std::vector<std::string>& entries);
24 
25  /// Returns true if \p argument is prefixed by the contents of the trie.
26  inline bool Query(const char* argument) {
27  return !node_ || Query(node_.get(), argument);
28  }
29 
30  struct TrieNode {
31  TrieNodePtr children[kMaxAsciiValue];
32  };
33 
34  private:
35  static bool Query(TrieNode* trie, const char* query);
36  TrieNodePtr node_;
37 };
38 } // namespace fml
39 
40 #endif
TrieNodePtr children[kMaxAsciiValue]
Definition: ascii_trie.h:31
Definition: ascii_trie.cc:9
static const int kMaxAsciiValue
The max Ascii value.
Definition: ascii_trie.h:20
bool Query(const char *argument)
Returns true if argument is prefixed by the contents of the trie.
Definition: ascii_trie.h:26
void Fill(const std::vector< std::string > &entries)
Clear and insert all the entries into the trie.
Definition: ascii_trie.cc:34
A trie for looking for ASCII prefixes.
Definition: ascii_trie.h:15
std::unique_ptr< TrieNode > TrieNodePtr
Definition: ascii_trie.h:17