MCPcopy Create free account
hub / github.com/Apache553/SubtitleFontHelper / QueryTrie

Class QueryTrie

SubtitleFontAutoLoaderDaemon/QueryService.cpp:13–205  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11{
12 template <typename T, bool AllowDuplicate = true>
13 class QueryTrie
14 {
15 private:
16 struct TrieNode
17 {
18 std::vector<std::pair<std::wstring, std::unique_ptr<TrieNode>>> m_branch;
19 std::vector<T*> m_data;
20
21 void CollectData(std::vector<T*>& ret)
22 {
23 ret.insert(ret.end(), m_data.begin(), m_data.end());
24 for (auto& branch : m_branch)
25 {
26 branch.second->CollectData(ret);
27 }
28 }
29
30 void SortList()
31 {
32 std::sort(m_branch.begin(), m_branch.end());
33 }
34
35 std::pair<std::wstring, std::unique_ptr<TrieNode>>* SearchPrefix(wchar_t leading)
36 {
37 auto left = m_branch.begin();
38 auto right = m_branch.end();
39 auto mid = left + (right - left) / 2;
40 auto result = right;
41 while (left != right)
42 {
43 assert(!mid->first.empty());
44 if (mid->first[0] == leading)
45 {
46 result = mid;
47 break;
48 }
49 else if (mid->first[0] > leading)
50 {
51 right = mid;
52 }
53 else
54 {
55 left = mid + 1;
56 }
57 mid = left + (right - left) / 2;
58 }
59 if (result == m_branch.end())
60 return nullptr;
61 return &(*result);
62 }
63 };
64
65 TrieNode m_rootNode;
66 public:
67 void AddEntry(const wchar_t* key, T* value)
68 {
69 const wchar_t* keyPointer = key;
70 TrieNode* node = &m_rootNode;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected