forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ascii_trie.h
40 lines (31 loc) · 981 Bytes
/
ascii_trie.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright 2013 The Flutter 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 FLUTTER_FML_ASCIITRIE_H_
#define FLUTTER_FML_ASCIITRIE_H_
#include <memory>
#include <string>
#include <vector>
namespace fml {
/// A trie for looking for ASCII prefixes.
class AsciiTrie {
public:
struct TrieNode;
typedef std::unique_ptr<TrieNode> TrieNodePtr;
/// The max Ascii value.
static const int kMaxAsciiValue = 128;
/// Clear and insert all the entries into the trie.
void Fill(const std::vector<std::string>& entries);
/// Returns true if \p argument is prefixed by the contents of the trie.
inline bool Query(const char* argument) {
return !node_ || Query(node_.get(), argument);
}
struct TrieNode {
TrieNodePtr children[kMaxAsciiValue];
};
private:
static bool Query(TrieNode* trie, const char* query);
TrieNodePtr node_;
};
} // namespace fml
#endif