1 // Copyright (c) 2011-2015 Ryan Prichard
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to
5 // deal in the Software without restriction, including without limitation the
6 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 // sell copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30 #include "SimplePool.h"
31 #include "../shared/WinptyAssert.h"
40 std::string toString() const;
48 memset(&children, 0, sizeof(children));
55 Node() : childCount(0) {
56 Key zeroKey = { 0, 0, 0 };
62 enum { kTinyCount = 8 };
66 unsigned char values[kTinyCount];
67 Node *children[kTinyCount];
72 return key.virtualKey != 0 || key.unicodeChar != 0;
77 SimplePool<Node, 256> m_nodePool;
78 SimplePool<Branch, 8> m_branchPool;
82 void set(const char *encoding, int encodingLen, const Key &key);
83 int lookupKey(const char *input, int inputSize,
84 Key &keyOut, bool &incompleteOut) const;
85 void dumpInputMap() const;
88 Node *getChild(Node &node, unsigned char ch) {
89 return const_cast<Node*>(getChild(static_cast<const Node&>(node), ch));
92 const Node *getChild(const Node &node, unsigned char ch) const {
93 if (node.childCount <= Node::kTinyCount) {
94 for (int i = 0; i < node.childCount; ++i) {
95 if (node.u.tiny.values[i] == ch) {
96 return node.u.tiny.children[i];
101 return node.u.branch->children[ch];
105 void setHelper(Node &node, const char *encoding, int encodingLen, const Key &key);
106 Node &getOrCreateChild(Node &node, unsigned char ch);
107 void dumpInputMapHelper(const Node &node, std::string &encoding) const;
110 const InputMap::Key kKeyZero = { 0, 0, 0 };
112 void dumpInputMap(InputMap &inputMap);
114 #endif // INPUT_MAP_H