Debian Codegraph @

lib/dat/trie.cpp

raw symbols SCIP
1 /*
2 Copyright (C) 2011-2015 Brazil
3 Copyright (C) 2022 Sutou Kouhei <[email protected]>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #include "trie.hpp"cxx . . $ `<file>/lib/dat/trie.hpp`/
21
22 #include <algorithm>
23 #include <cstring>
24
25 #include "vector.hpp"cxx . . $ `<file>/lib/dat/vector.hpp`/
26
27 namespace grncxx . . $ grn/ {
28 namespace datcxx . . $ grn/dat/ {
29 namespacecxx . . $ grn/dat/`$anonymous_namespace_lib/dat/trie.cpp`/ {
30
31 class StatusFlagManagercxx . . $ grn/dat/`$anonymous_namespace_lib/dat/trie.cpp`/StatusFlagManager# {
32 public:
33 StatusFlagManagercxx . . $ grn/dat/`$anonymous_namespace_lib/dat/trie.cpp`/StatusFlagManager#StatusFlagManager(a9ec5a5b9fdbc3df).(Headercxx . . $ grn/dat/Header# *header, UInt32cxx . . $ grn/dat/UInt32# status_flag)
34 : header_cxx . . $ grn/dat/`$anonymous_namespace_lib/dat/trie.cpp`/StatusFlagManager#header_.(header), status_flag_cxx . . $ grn/dat/`$anonymous_namespace_lib/dat/trie.cpp`/StatusFlagManager#status_flag_.(status_flag) {
35 header_cxx . . $ grn/dat/`$anonymous_namespace_lib/dat/trie.cpp`/StatusFlagManager#header_.->set_status_flagscxx . . $ grn/dat/Header#set_status_flags(cb2f890c2fdad230).(header_cxx . . $ grn/dat/`$anonymous_namespace_lib/dat/trie.cpp`/StatusFlagManager#header_.->status_flagscxx . . $ grn/dat/Header#status_flags(ddd8539a2fcdd4ce).() | status_flag_cxx . . $ grn/dat/`$anonymous_namespace_lib/dat/trie.cpp`/StatusFlagManager#status_flag_.);
36 }
37 ~cxx . . $ grn/dat/`$anonymous_namespace_lib/dat/trie.cpp`/StatusFlagManager#`~StatusFlagManager`(ced63f7c635d850d).StatusFlagManagercxx . . $ grn/dat/`$anonymous_namespace_lib/dat/trie.cpp`/StatusFlagManager#() {
38 header_cxx . . $ grn/dat/`$anonymous_namespace_lib/dat/trie.cpp`/StatusFlagManager#header_.->set_status_flagscxx . . $ grn/dat/Header#set_status_flags(cb2f890c2fdad230).(header_cxx . . $ grn/dat/`$anonymous_namespace_lib/dat/trie.cpp`/StatusFlagManager#header_.->status_flagscxx . . $ grn/dat/Header#status_flags(ddd8539a2fcdd4ce).() & ~status_flag_cxx . . $ grn/dat/`$anonymous_namespace_lib/dat/trie.cpp`/StatusFlagManager#status_flag_.);
39 }
40
41 private:
42 Headercxx . . $ grn/dat/Header# *header_cxx . . $ grn/dat/`$anonymous_namespace_lib/dat/trie.cpp`/StatusFlagManager#header_.;
43 UInt32cxx . . $ grn/dat/UInt32# status_flag_cxx . . $ grn/dat/`$anonymous_namespace_lib/dat/trie.cpp`/StatusFlagManager#status_flag_.;
44
45 // Disallows copy and assignment.
46 StatusFlagManagercxx . . $ grn/dat/`$anonymous_namespace_lib/dat/trie.cpp`/StatusFlagManager#StatusFlagManager(17bcec8516e7885d).(const StatusFlagManagercxx . . $ grn/dat/`$anonymous_namespace_lib/dat/trie.cpp`/StatusFlagManager# &);
47 StatusFlagManagercxx . . $ grn/dat/`$anonymous_namespace_lib/dat/trie.cpp`/StatusFlagManager# &operatorcxx . . $ grn/dat/`$anonymous_namespace_lib/dat/trie.cpp`/StatusFlagManager#`operator=`(91623bf3c21d00a5).=(const StatusFlagManagercxx . . $ grn/dat/`$anonymous_namespace_lib/dat/trie.cpp`/StatusFlagManager# &);
48 };
49
50 } // namespace
51
52 Triecxx . . $ grn/dat/Trie#::Triecxx . . $ grn/dat/Trie#Trie(49f6e7a06ebc5aa8).()
53 : file_cxx . . $ grn/dat/Trie#file_.(),
54 header_cxx . . $ grn/dat/Trie#header_.(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:416:9`!),
55 nodes_cxx . . $ grn/dat/Trie#nodes_.(),
56 blocks_cxx . . $ grn/dat/Trie#blocks_.(),
57 entries_cxx . . $ grn/dat/Trie#entries_.(),
58 key_buf_cxx . . $ grn/dat/Trie#key_buf_.() {}
59
60 Triecxx . . $ grn/dat/Trie#::~cxx . . $ grn/dat/Trie#`~Trie`(ced63f7c635d850d).Triecxx . . $ grn/dat/Trie#() {}
61
62 void Triecxx . . $ grn/dat/Trie#::createcxx . . $ grn/dat/Trie#create(effadf6d9e160e1f).(const char *file_name,
63 UInt64cxx . . $ grn/dat/UInt64# file_size,
64 UInt32cxx . . $ grn/dat/UInt32# max_num_keys,
65 double num_nodes_per_key,
66 double average_key_length) {
67 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(PARAM_ERROR, (file_size != 0) && (max_num_keys != 0));
68
69 if (num_nodes_per_key < 1.0) {
70 num_nodes_per_key = DEFAULT_NUM_NODES_PER_KEYcxx . . $ grn/dat/DEFAULT_NUM_NODES_PER_KEY.;
71 }
72 if (num_nodes_per_key > MAX_NUM_NODES_PER_KEYcxx . . $ grn/dat/MAX_NUM_NODES_PER_KEY.) {
73 num_nodes_per_key = MAX_NUM_NODES_PER_KEYcxx . . $ grn/dat/MAX_NUM_NODES_PER_KEY.;
74 }
75 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(PARAM_ERROR, num_nodes_per_key < 1.0);
76 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(PARAM_ERROR, num_nodes_per_key > MAX_NUM_NODES_PER_KEY);
77
78 if (average_key_length < 1.0) {
79 average_key_length = DEFAULT_AVERAGE_KEY_LENGTHcxx . . $ grn/dat/DEFAULT_AVERAGE_KEY_LENGTH.;
80 }
81 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(PARAM_ERROR, average_key_length < 1.0);
82 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(PARAM_ERROR, average_key_length > MAX_KEY_LENGTH);
83
84 if (max_num_keys == 0) {
85 if (file_size == 0) {
86 file_size = DEFAULT_FILE_SIZEcxx . . $ grn/dat/DEFAULT_FILE_SIZE.;
87 } else {
88 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(PARAM_ERROR, file_size < MIN_FILE_SIZE);
89 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(PARAM_ERROR, file_size > MAX_FILE_SIZE);
90 }
91 } else {
92 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(PARAM_ERROR, max_num_keys > MAX_NUM_KEYS);
93 }
94
95 Triecxx . . $ grn/dat/Trie# new_triecxx . . $ grn/dat/Trie#Trie(49f6e7a06ebc5aa8).;
96 new_trie.create_filecxx . . $ grn/dat/Trie#create_file(effadf6d9e160e1f).(file_name, file_size, max_num_keys,
97 num_nodes_per_key, average_key_length);
98 new_trie.swapcxx . . $ grn/dat/Trie#swap(e01dee0d6759772e).(this);
99 }
100
101 void Triecxx . . $ grn/dat/Trie#::createcxx . . $ grn/dat/Trie#create(f9e26080e2580924).(const Triecxx . . $ grn/dat/Trie# &trie,
102 const char *file_name,
103 UInt64cxx . . $ grn/dat/UInt64# file_size,
104 UInt32cxx . . $ grn/dat/UInt32# max_num_keys,
105 double num_nodes_per_key,
106 double average_key_length) {
107 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(PARAM_ERROR, (file_size != 0) && (max_num_keys != 0));
108
109 if (num_nodes_per_key < 1.0) {
110 if (trie.num_keyscxx . . $ grn/dat/Trie#num_keys(ddd8539a2fcdd4ce).() == 0) {
111 num_nodes_per_key = DEFAULT_NUM_NODES_PER_KEYcxx . . $ grn/dat/DEFAULT_NUM_NODES_PER_KEY.;
112 } else {
113 num_nodes_per_key = 1.0 * trie.num_nodescxx . . $ grn/dat/Trie#num_nodes(ddd8539a2fcdd4ce).() / trie.num_keyscxx . . $ grn/dat/Trie#num_keys(ddd8539a2fcdd4ce).();
114 if (num_nodes_per_key > MAX_NUM_NODES_PER_KEYcxx . . $ grn/dat/MAX_NUM_NODES_PER_KEY.) {
115 num_nodes_per_key = MAX_NUM_NODES_PER_KEYcxx . . $ grn/dat/MAX_NUM_NODES_PER_KEY.;
116 }
117 }
118 }
119 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(PARAM_ERROR, num_nodes_per_key < 1.0);
120 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(PARAM_ERROR, num_nodes_per_key > MAX_NUM_NODES_PER_KEY);
121
122 if (average_key_length < 1.0) {
123 if (trie.num_keyscxx . . $ grn/dat/Trie#num_keys(ddd8539a2fcdd4ce).() == 0) {
124 average_key_length = DEFAULT_AVERAGE_KEY_LENGTHcxx . . $ grn/dat/DEFAULT_AVERAGE_KEY_LENGTH.;
125 } else {
126 average_key_length = 1.0 * trie.total_key_lengthcxx . . $ grn/dat/Trie#total_key_length(ddd8539a2fcdd4ce).() / trie.num_keyscxx . . $ grn/dat/Trie#num_keys(ddd8539a2fcdd4ce).();
127 }
128 }
129 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(PARAM_ERROR, average_key_length < 1.0);
130 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(PARAM_ERROR, average_key_length > MAX_KEY_LENGTH);
131
132 if (max_num_keys == 0) {
133 if (file_size == 0) {
134 file_size = trie.file_sizecxx . . $ grn/dat/Trie#file_size(fe4d2d262d4164a8).();
135 }
136 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(PARAM_ERROR, file_size < MIN_FILE_SIZE);
137 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(PARAM_ERROR, file_size > MAX_FILE_SIZE);
138 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(PARAM_ERROR, file_size < trie.virtual_size());
139 } else {
140 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(PARAM_ERROR, max_num_keys < trie.num_keys());
141 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(PARAM_ERROR, max_num_keys < trie.max_key_id());
142 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(PARAM_ERROR, max_num_keys > MAX_NUM_KEYS);
143 }
144
145 Triecxx . . $ grn/dat/Trie# new_triecxx . . $ grn/dat/Trie#Trie(49f6e7a06ebc5aa8).;
146 new_trie.create_filecxx . . $ grn/dat/Trie#create_file(effadf6d9e160e1f).(file_name, file_size, max_num_keys,
147 num_nodes_per_key, average_key_length);
148 new_trie.build_from_triecxx . . $ grn/dat/Trie#build_from_trie(47c3eab575beacb0).(trie);
149 new_trie.swapcxx . . $ grn/dat/Trie#swap(e01dee0d6759772e).(this);
150 }
151
152 void Triecxx . . $ grn/dat/Trie#::repaircxx . . $ grn/dat/Trie#repair(747e891cfe89c583).(const Triecxx . . $ grn/dat/Trie# &trie, const char *file_name) {
153 Triecxx . . $ grn/dat/Trie# new_triecxx . . $ grn/dat/Trie#Trie(49f6e7a06ebc5aa8).;
154 new_trie.create_filecxx . . $ grn/dat/Trie#create_file(9790cea5b3a5c247).(file_name, trie.file_sizecxx . . $ grn/dat/Trie#file_size(fe4d2d262d4164a8).(), trie.max_num_keyscxx . . $ grn/dat/Trie#max_num_keys(ddd8539a2fcdd4ce).(),
155 trie.max_num_blockscxx . . $ grn/dat/Trie#max_num_blocks(ddd8539a2fcdd4ce).(), trie.key_buf_sizecxx . . $ grn/dat/Trie#key_buf_size(ddd8539a2fcdd4ce).());
156 new_trie.repair_triecxx . . $ grn/dat/Trie#repair_trie(47c3eab575beacb0).(trie);
157 new_trie.swapcxx . . $ grn/dat/Trie#swap(e01dee0d6759772e).(this);
158 }
159
160 void Triecxx . . $ grn/dat/Trie#::opencxx . . $ grn/dat/Trie#open(85c52e162fed56f9).(const char *file_name) {
161 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(PARAM_ERROR, file_name == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:416:9`!);
162
163 Triecxx . . $ grn/dat/Trie# new_triecxx . . $ grn/dat/Trie#Trie(49f6e7a06ebc5aa8).;
164 new_trie.open_filecxx . . $ grn/dat/Trie#open_file(85c52e162fed56f9).(file_name);
165 new_trie.swapcxx . . $ grn/dat/Trie#swap(e01dee0d6759772e).(this);
166 }
167
168 void Triecxx . . $ grn/dat/Trie#::closecxx . . $ grn/dat/Trie#close(49f6e7a06ebc5aa8).() {
169 Triecxx . . $ grn/dat/Trie#Trie(49f6e7a06ebc5aa8).().swapcxx . . $ grn/dat/Trie#swap(e01dee0d6759772e).(this);
170 }
171
172 void Triecxx . . $ grn/dat/Trie#::swapcxx . . $ grn/dat/Trie#swap(e01dee0d6759772e).(Triecxx . . $ grn/dat/Trie# *trie) {
173 file_cxx . . $ grn/dat/Trie#file_..swapcxx . . $ grn/dat/File#swap(13ac73f2af8264d0).(&trie->file_cxx . . $ grn/dat/Trie#file_.);
174 std::swapcxx . . $ std/swap(c75b8fd57d7c2e06).(header_cxx . . $ grn/dat/Trie#header_., trie->header_cxx . . $ grn/dat/Trie#header_.);
175 nodes_cxx . . $ grn/dat/Trie#nodes_..swapcxx . . $ grn/dat/Array#swap(9e3561b02af8a061).(&trie->nodes_cxx . . $ grn/dat/Trie#nodes_.);
176 blocks_cxx . . $ grn/dat/Trie#blocks_..swapcxx . . $ grn/dat/Array#swap(9e3561b02af8a061).(&trie->blocks_cxx . . $ grn/dat/Trie#blocks_.);
177 entries_cxx . . $ grn/dat/Trie#entries_..swapcxx . . $ grn/dat/Array#swap(9e3561b02af8a061).(&trie->entries_cxx . . $ grn/dat/Trie#entries_.);
178 key_buf_cxx . . $ grn/dat/Trie#key_buf_..swapcxx . . $ grn/dat/Array#swap(9e3561b02af8a061).(&trie->key_buf_cxx . . $ grn/dat/Trie#key_buf_.);
179 }
180
181 void Triecxx . . $ grn/dat/Trie#::flushcxx . . $ grn/dat/Trie#flush(49f6e7a06ebc5aa8).() {
182 file_cxx . . $ grn/dat/Trie#file_..flushcxx . . $ grn/dat/File#flush(49f6e7a06ebc5aa8).();
183 }
184
185 void Triecxx . . $ grn/dat/Trie#::create_filecxx . . $ grn/dat/Trie#create_file(effadf6d9e160e1f).(const char *file_name,
186 UInt64cxx . . $ grn/dat/UInt64# file_size,
187 UInt32cxx . . $ grn/dat/UInt32# max_num_keys,
188 double num_nodes_per_key,
189 double average_key_length) {
190 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(PARAM_ERROR, (file_size == 0) && (max_num_keys == 0));
191 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(PARAM_ERROR, (file_size != 0) && (max_num_keys != 0));
192 if (max_num_keys == 0) {
193 const UInt64cxx . . $ grn/dat/UInt64# avail = file_size - sizeof(Headercxx . . $ grn/dat/Header#);
194 const double num_bytes_per_key = (sizeof(Nodecxx . . $ grn/dat/Node#) * num_nodes_per_key)
195 + (1.0 * sizeof(Blockcxx . . $ grn/dat/Block#) / BLOCK_SIZEcxx . . $ grn/dat/BLOCK_SIZE. * num_nodes_per_key)
196 + sizeof(Entrycxx . . $ grn/dat/Entry#)
197 + sizeof(UInt32cxx . . $ grn/dat/UInt32#) + sizeof(UInt8cxx . . $ grn/dat/UInt8#) + average_key_length + 1.5;
198 const UInt32cxx . . $ grn/dat/UInt32# available_num_keys =
199 static_cast<UInt32cxx . . $ grn/dat/UInt32#>(static_cast<double>(avail) / num_bytes_per_key);
200 if (available_num_keys > MAX_NUM_KEYScxx . . $ grn/dat/MAX_NUM_KEYS.) {
201 max_num_keys = MAX_NUM_KEYScxx . . $ grn/dat/MAX_NUM_KEYS.;
202 } else {
203 max_num_keys = available_num_keys;
204 }
205 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(PARAM_ERROR, max_num_keys == 0);
206 }
207
208 UInt32cxx . . $ grn/dat/UInt32# max_num_blocks;
209 {
210 const double max_num_nodes = num_nodes_per_key * max_num_keys;
211 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(PARAM_ERROR, (max_num_nodes - 1.0) >= MAX_NUM_NODES);
212 max_num_blocks = ((UInt32cxx . . $ grn/dat/UInt32#)max_num_nodes + BLOCK_SIZEcxx . . $ grn/dat/BLOCK_SIZE. - 1) / BLOCK_SIZEcxx . . $ grn/dat/BLOCK_SIZE.;
213 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(PARAM_ERROR, max_num_blocks == 0);
214 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(PARAM_ERROR, max_num_blocks > MAX_NUM_BLOCKS);
215 }
216
217 UInt32cxx . . $ grn/dat/UInt32# key_buf_size;
218 if (file_size == 0) {
219 const double total_key_length = average_key_length * max_num_keys;
220 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(PARAM_ERROR,
221 (total_key_length - 1.0) >= MAX_TOTAL_KEY_LENGTH);
222
223 // The last term is the estimated number of bytes that will be used for
224 // 32-bit alignment.
225 const UInt64cxx . . $ grn/dat/UInt64# total_num_bytes = (UInt64cxx . . $ grn/dat/UInt64#)(total_key_length)
226 + (UInt64cxx . . $ grn/dat/UInt64#)(sizeof(UInt32cxx . . $ grn/dat/UInt32#) + sizeof(UInt8cxx . . $ grn/dat/UInt8#)) * max_num_keys
227 + (UInt32cxx . . $ grn/dat/UInt32#)(max_num_keys * 1.5);
228 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(PARAM_ERROR,
229 (total_num_bytes / sizeof(UInt32)) >= MAX_KEY_BUF_SIZE);
230 key_buf_size = (UInt32cxx . . $ grn/dat/UInt32#)(total_num_bytes / sizeof(UInt32cxx . . $ grn/dat/UInt32#));
231
232 file_size = sizeof(Headercxx . . $ grn/dat/Header#)
233 + (sizeof(Blockcxx . . $ grn/dat/Block#) * max_num_blocks)
234 + (sizeof(Nodecxx . . $ grn/dat/Node#) * BLOCK_SIZEcxx . . $ grn/dat/BLOCK_SIZE. * max_num_blocks)
235 + (sizeof(Entrycxx . . $ grn/dat/Entry#) * max_num_keys)
236 + (sizeof(UInt32cxx . . $ grn/dat/UInt32#) * key_buf_size);
237 } else {
238 const UInt64cxx . . $ grn/dat/UInt64# avail = file_size - sizeof(Headercxx . . $ grn/dat/Header#)
239 - (sizeof(Blockcxx . . $ grn/dat/Block#) * max_num_blocks)
240 - (sizeof(Nodecxx . . $ grn/dat/Node#) * BLOCK_SIZEcxx . . $ grn/dat/BLOCK_SIZE. * max_num_blocks)
241 - (sizeof(Entrycxx . . $ grn/dat/Entry#) * max_num_keys);
242 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(PARAM_ERROR, (avail / sizeof(UInt32)) > MAX_KEY_BUF_SIZE);
243 key_buf_size = (UInt32cxx . . $ grn/dat/UInt32#)(avail / sizeof(UInt32cxx . . $ grn/dat/UInt32#));
244 }
245
246 create_filecxx . . $ grn/dat/Trie#create_file(9790cea5b3a5c247).(file_name, file_size, max_num_keys,
247 max_num_blocks, key_buf_size);
248 }
249
250 void Triecxx . . $ grn/dat/Trie#::create_filecxx . . $ grn/dat/Trie#create_file(9790cea5b3a5c247).(const char *file_name,
251 UInt64cxx . . $ grn/dat/UInt64# file_size,
252 UInt32cxx . . $ grn/dat/UInt32# max_num_keys,
253 UInt32cxx . . $ grn/dat/UInt32# max_num_blocks,
254 UInt32cxx . . $ grn/dat/UInt32# key_buf_size) {
255 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(PARAM_ERROR, file_size < (sizeof(Header)
256 + (sizeof(Block) * max_num_blocks)
257 + (sizeof(Node) * BLOCK_SIZE * max_num_blocks)
258 + (sizeof(Entry) * max_num_keys)
259 + (sizeof(UInt32) * key_buf_size)));
260
261 file_cxx . . $ grn/dat/Trie#file_..createcxx . . $ grn/dat/File#create(7cafb6e0818eff3b).(file_name, file_size);
262
263 Headercxx . . $ grn/dat/Header# * const header = static_cast<Headercxx . . $ grn/dat/Header# *>(file_cxx . . $ grn/dat/Trie#file_..ptrcxx . . $ grn/dat/File#ptr(45a5c5ac6be858a8).());
264 *header =cxx . . $ grn/dat/Header#`operator=`(140b2124e7878643). Headercxx . . $ grn/dat/Header#Header(49f6e7a06ebc5aa8).();
265 header->set_file_sizecxx . . $ grn/dat/Header#set_file_size(2c44cd906ae4e829).(file_size);
266 header->set_max_num_keyscxx . . $ grn/dat/Header#set_max_num_keys(cb2f890c2fdad230).(max_num_keys);
267 header->set_max_num_blockscxx . . $ grn/dat/Header#set_max_num_blocks(cb2f890c2fdad230).(max_num_blocks);
268 header->set_key_buf_sizecxx . . $ grn/dat/Header#set_key_buf_size(cb2f890c2fdad230).(key_buf_size);
269
270 map_addresscxx . . $ grn/dat/Trie#map_address(5d22bdacc48458e8).(file_cxx . . $ grn/dat/Trie#file_..ptrcxx . . $ grn/dat/File#ptr(45a5c5ac6be858a8).());
271
272 reserve_nodecxx . . $ grn/dat/Trie#reserve_node(cb2f890c2fdad230).(ROOT_NODE_IDcxx . . $ grn/dat/ROOT_NODE_ID.);
273 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(INVALID_OFFSETcxx . . $ grn/dat/INVALID_OFFSET.).set_is_offsetcxx . . $ grn/dat/Node#set_is_offset(b45ddcbc8423892c).(true);
274 }
275
276 void Triecxx . . $ grn/dat/Trie#::open_filecxx . . $ grn/dat/Trie#open_file(85c52e162fed56f9).(const char *file_name) {
277 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(PARAM_ERROR, file_name == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:416:9`!);
278
279 file_cxx . . $ grn/dat/Trie#file_..opencxx . . $ grn/dat/File#open(85c52e162fed56f9).(file_name);
280 map_addresscxx . . $ grn/dat/Trie#map_address(5d22bdacc48458e8).(file_cxx . . $ grn/dat/Trie#file_..ptrcxx . . $ grn/dat/File#ptr(45a5c5ac6be858a8).());
281 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(FORMAT_ERROR, file_size() != file_.size());
282 }
283
284 void Triecxx . . $ grn/dat/Trie#::map_addresscxx . . $ grn/dat/Trie#map_address(5d22bdacc48458e8).(void *address) {
285 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(PARAM_ERROR, address == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:416:9`!);
286
287 header_cxx . . $ grn/dat/Trie#header_. = static_cast<Headercxx . . $ grn/dat/Header# *>(address);
288 nodes_cxx . . $ grn/dat/Trie#nodes_..assigncxx . . $ grn/dat/Array#assign(67abb4dd43ac34c5).(header_cxx . . $ grn/dat/Trie#header_. + 1, max_num_nodescxx . . $ grn/dat/Trie#max_num_nodes(ddd8539a2fcdd4ce).());
289 blocks_cxx . . $ grn/dat/Trie#blocks_..assigncxx . . $ grn/dat/Array#assign(67abb4dd43ac34c5).(nodes_cxx . . $ grn/dat/Trie#nodes_..endcxx . . $ grn/dat/Array#end(155dc7f103cdb9db).(), max_num_blockscxx . . $ grn/dat/Trie#max_num_blocks(ddd8539a2fcdd4ce).());
290 entries_cxx . . $ grn/dat/Trie#entries_..assigncxx . . $ grn/dat/Array#assign(67abb4dd43ac34c5).(reinterpret_cast<Entrycxx . . $ grn/dat/Entry# *>(blocks_cxx . . $ grn/dat/Trie#blocks_..endcxx . . $ grn/dat/Array#end(155dc7f103cdb9db).()) - 1,
291 max_num_keyscxx . . $ grn/dat/Trie#max_num_keys(ddd8539a2fcdd4ce).() + 1);
292 key_buf_cxx . . $ grn/dat/Trie#key_buf_..assigncxx . . $ grn/dat/Array#assign(67abb4dd43ac34c5).(entries_cxx . . $ grn/dat/Trie#entries_..endcxx . . $ grn/dat/Array#end(155dc7f103cdb9db).(), key_buf_sizecxx . . $ grn/dat/Trie#key_buf_size(ddd8539a2fcdd4ce).());
293
294 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(UNEXPECTED_ERROR, static_cast<void *>(key_buf_.end())
295 > static_cast<void *>(static_cast<char *>(address) + file_size()));
296 }
297
298 void Triecxx . . $ grn/dat/Trie#::build_from_triecxx . . $ grn/dat/Trie#build_from_trie(47c3eab575beacb0).(const Triecxx . . $ grn/dat/Trie# &trie) {
299 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(SIZE_ERROR, max_num_keys() < trie.num_keys());
300 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(SIZE_ERROR, max_num_keys() < trie.max_key_id());
301
302 header_cxx . . $ grn/dat/Trie#header_.->set_total_key_lengthcxx . . $ grn/dat/Header#set_total_key_length(cb2f890c2fdad230).(trie.total_key_lengthcxx . . $ grn/dat/Trie#total_key_length(ddd8539a2fcdd4ce).());
303 header_cxx . . $ grn/dat/Trie#header_.->set_num_keyscxx . . $ grn/dat/Header#set_num_keys(cb2f890c2fdad230).(trie.num_keyscxx . . $ grn/dat/Trie#num_keys(ddd8539a2fcdd4ce).());
304 header_cxx . . $ grn/dat/Trie#header_.->set_max_key_idcxx . . $ grn/dat/Header#set_max_key_id(cb2f890c2fdad230).(trie.max_key_idcxx . . $ grn/dat/Trie#max_key_id(ddd8539a2fcdd4ce).());
305 header_cxx . . $ grn/dat/Trie#header_.->set_next_key_idcxx . . $ grn/dat/Header#set_next_key_id(cb2f890c2fdad230).(trie.next_key_idcxx . . $ grn/dat/Trie#next_key_id(ddd8539a2fcdd4ce).());
306 for (UInt32cxx . . $ grn/dat/UInt32# i = min_key_idcxx . . $ grn/dat/Trie#min_key_id(ddd8539a2fcdd4ce).(); i <= max_key_idcxx . . $ grn/dat/Trie#max_key_id(ddd8539a2fcdd4ce).(); ++i) {
307 ith_entrycxx . . $ grn/dat/Trie#ith_entry(23ff61182d9f5125).(i) =cxx . . $ grn/dat/Entry#`operator=`(90fc02dcd1f9a93). trie.ith_entrycxx . . $ grn/dat/Trie#ith_entry(4fe644a8fcf4134d).(i);
308 }
309 build_from_triecxx . . $ grn/dat/Trie#build_from_trie(a88efb538d233dc2).(trie, ROOT_NODE_IDcxx . . $ grn/dat/ROOT_NODE_ID., ROOT_NODE_IDcxx . . $ grn/dat/ROOT_NODE_ID.);
310 }
311
312 void Triecxx . . $ grn/dat/Trie#::build_from_triecxx . . $ grn/dat/Trie#build_from_trie(a88efb538d233dc2).(const Triecxx . . $ grn/dat/Trie# &trie, UInt32cxx . . $ grn/dat/UInt32# src, UInt32cxx . . $ grn/dat/UInt32# dest) {
313 // Keys are sorted in lexicographic order.
314 if (trie.ith_nodecxx . . $ grn/dat/Trie#ith_node(cc2414b1dc013100).(src).is_linkercxx . . $ grn/dat/Node#is_linker(50ce9a9e25b4a850).()) {
315 const Keycxx . . $ grn/dat/Key# &key = trie.get_keycxx . . $ grn/dat/Trie#get_key(ac1ad672cda84f14).(trie.ith_nodecxx . . $ grn/dat/Trie#ith_node(cc2414b1dc013100).(src).key_poscxx . . $ grn/dat/Node#key_pos(ddd8539a2fcdd4ce).());
316 Keycxx . . $ grn/dat/Key#::createcxx . . $ grn/dat/Key#create(66d57bc96acb1d3c).(key_buf_cxx . . $ grn/dat/Trie#key_buf_..ptrcxx . . $ grn/dat/Array#ptr(5a2a78a048fb49a8).() + next_key_poscxx . . $ grn/dat/Trie#next_key_pos(ddd8539a2fcdd4ce).(),
317 key.idcxx . . $ grn/dat/Key#id(ddd8539a2fcdd4ce).(), key.ptrcxx . . $ grn/dat/Key#ptr(3a8ef3fdc6e817ef).(), key.lengthcxx . . $ grn/dat/Key#length(ddd8539a2fcdd4ce).());
318 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(dest).set_key_poscxx . . $ grn/dat/Node#set_key_pos(cb2f890c2fdad230).(next_key_poscxx . . $ grn/dat/Trie#next_key_pos(ddd8539a2fcdd4ce).());
319 ith_entrycxx . . $ grn/dat/Trie#ith_entry(23ff61182d9f5125).(key.idcxx . . $ grn/dat/Key#id(ddd8539a2fcdd4ce).()).set_key_poscxx . . $ grn/dat/Entry#set_key_pos(cb2f890c2fdad230).(next_key_poscxx . . $ grn/dat/Trie#next_key_pos(ddd8539a2fcdd4ce).());
320 header_cxx . . $ grn/dat/Trie#header_.->set_next_key_poscxx . . $ grn/dat/Header#set_next_key_pos(cb2f890c2fdad230).(
321 next_key_poscxx . . $ grn/dat/Trie#next_key_pos(ddd8539a2fcdd4ce).() + Keycxx . . $ grn/dat/Key#::estimate_sizecxx . . $ grn/dat/Key#estimate_size(2141b656ce2cc063).(key.lengthcxx . . $ grn/dat/Key#length(ddd8539a2fcdd4ce).()));
322 return;
323 }
324
325 const UInt32cxx . . $ grn/dat/UInt32# src_offset = trie.ith_nodecxx . . $ grn/dat/Trie#ith_node(cc2414b1dc013100).(src).offsetcxx . . $ grn/dat/Node#offset(ddd8539a2fcdd4ce).();
326 UInt32cxx . . $ grn/dat/UInt32# dest_offset;
327 {
328 UInt16cxx . . $ grn/dat/UInt16# labels[MAX_LABELcxx . . $ grn/dat/MAX_LABEL. + 1];
329 UInt32cxx . . $ grn/dat/UInt32# num_labels = 0;
330
331 UInt32cxx . . $ grn/dat/UInt32# label = trie.ith_nodecxx . . $ grn/dat/Trie#ith_node(cc2414b1dc013100).(src).childcxx . . $ grn/dat/Node#child(ddd8539a2fcdd4ce).();
332 while (label != INVALID_LABELcxx . . $ grn/dat/INVALID_LABEL.) {
333 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(label > MAX_LABEL);
334 const UInt32cxx . . $ grn/dat/UInt32# child = src_offset ^ label;
335 if (trie.ith_nodecxx . . $ grn/dat/Trie#ith_node(cc2414b1dc013100).(child).is_linkercxx . . $ grn/dat/Node#is_linker(50ce9a9e25b4a850).() ||
336 (trie.ith_nodecxx . . $ grn/dat/Trie#ith_node(cc2414b1dc013100).(child).childcxx . . $ grn/dat/Node#child(ddd8539a2fcdd4ce).() != INVALID_LABELcxx . . $ grn/dat/INVALID_LABEL.)) {
337 labels[num_labels++] = static_cast<UInt16cxx . . $ grn/dat/UInt16#>(label);
338 }
339 label = trie.ith_nodecxx . . $ grn/dat/Trie#ith_node(cc2414b1dc013100).(child).siblingcxx . . $ grn/dat/Node#sibling(ddd8539a2fcdd4ce).();
340 }
341 if (num_labels == 0) {
342 return;
343 }
344
345 dest_offset = find_offsetcxx . . $ grn/dat/Trie#find_offset(d1a687133290a15f).(labels, num_labels);
346 for (UInt32cxx . . $ grn/dat/UInt32# i = 0; i < num_labels; ++i) {
347 const UInt32cxx . . $ grn/dat/UInt32# child = dest_offset ^ labels[i];
348 reserve_nodecxx . . $ grn/dat/Trie#reserve_node(cb2f890c2fdad230).(child);
349 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(child).set_labelcxx . . $ grn/dat/Node#set_label(cb2f890c2fdad230).(labels[i]);
350 if ((i + 1) < num_labels) {
351 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(child).set_siblingcxx . . $ grn/dat/Node#set_sibling(cb2f890c2fdad230).(labels[i + 1]);
352 }
353 }
354
355 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(ith_node(dest_offset).is_offset());
356 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(dest_offset).set_is_offsetcxx . . $ grn/dat/Node#set_is_offset(b45ddcbc8423892c).(true);
357 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(dest).set_offsetcxx . . $ grn/dat/Node#set_offset(cb2f890c2fdad230).(dest_offset);
358 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(dest).set_childcxx . . $ grn/dat/Node#set_child(cb2f890c2fdad230).(labels[0]);
359 }
360
361 UInt32cxx . . $ grn/dat/UInt32# label = ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(dest).childcxx . . $ grn/dat/Node#child(ddd8539a2fcdd4ce).();
362 while (label != INVALID_LABELcxx . . $ grn/dat/INVALID_LABEL.) {
363 build_from_triecxx . . $ grn/dat/Trie#build_from_trie(a88efb538d233dc2).(trie, src_offset ^ label, dest_offset ^ label);
364 label = ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(dest_offset ^ label).siblingcxx . . $ grn/dat/Node#sibling(ddd8539a2fcdd4ce).();
365 }
366 }
367
368 void Triecxx . . $ grn/dat/Trie#::repair_triecxx . . $ grn/dat/Trie#repair_trie(47c3eab575beacb0).(const Triecxx . . $ grn/dat/Trie# &trie) {
369 Vectorcxx . . $ grn/dat/Vector#<UInt32cxx . . $ grn/dat/UInt32#> valid_idscxx . . $ grn/dat/Vector#Vector(49f6e7a06ebc5aa8).;
370 header_cxx . . $ grn/dat/Trie#header_.->set_max_key_idcxx . . $ grn/dat/Header#set_max_key_id(cb2f890c2fdad230).(trie.max_key_idcxx . . $ grn/dat/Trie#max_key_id(ddd8539a2fcdd4ce).());
371 header_cxx . . $ grn/dat/Trie#header_.->set_next_key_idcxx . . $ grn/dat/Header#set_next_key_id(cb2f890c2fdad230).(trie.max_key_idcxx . . $ grn/dat/Trie#max_key_id(ddd8539a2fcdd4ce).() + 1);
372 UInt32cxx . . $ grn/dat/UInt32# prev_invalid_key_id = INVALID_KEY_IDcxx . . $ grn/dat/INVALID_KEY_ID.;
373 for (UInt32cxx . . $ grn/dat/UInt32# i = min_key_idcxx . . $ grn/dat/Trie#min_key_id(ddd8539a2fcdd4ce).(); i <= max_key_idcxx . . $ grn/dat/Trie#max_key_id(ddd8539a2fcdd4ce).(); ++i) {
374 const Entrycxx . . $ grn/dat/Entry# &entry = trie.ith_entrycxx . . $ grn/dat/Trie#ith_entry(4fe644a8fcf4134d).(i);
375 if (entry.is_validcxx . . $ grn/dat/Entry#is_valid(50ce9a9e25b4a850).()) {
376 valid_ids.push_backcxx . . $ grn/dat/Vector#push_back(77d9f17553126ecb).(i);
377 ith_entrycxx . . $ grn/dat/Trie#ith_entry(23ff61182d9f5125).(i) =cxx . . $ grn/dat/Entry#`operator=`(90fc02dcd1f9a93). entry;
378 const Keycxx . . $ grn/dat/Key# &key = trie.get_keycxx . . $ grn/dat/Trie#get_key(ac1ad672cda84f14).(entry.key_poscxx . . $ grn/dat/Entry#key_pos(ddd8539a2fcdd4ce).());
379 Keycxx . . $ grn/dat/Key#::createcxx . . $ grn/dat/Key#create(66d57bc96acb1d3c).(key_buf_cxx . . $ grn/dat/Trie#key_buf_..ptrcxx . . $ grn/dat/Array#ptr(5a2a78a048fb49a8).() + next_key_poscxx . . $ grn/dat/Trie#next_key_pos(ddd8539a2fcdd4ce).(),
380 key.idcxx . . $ grn/dat/Key#id(ddd8539a2fcdd4ce).(), key.ptrcxx . . $ grn/dat/Key#ptr(3a8ef3fdc6e817ef).(), key.lengthcxx . . $ grn/dat/Key#length(ddd8539a2fcdd4ce).());
381 ith_entrycxx . . $ grn/dat/Trie#ith_entry(23ff61182d9f5125).(i).set_key_poscxx . . $ grn/dat/Entry#set_key_pos(cb2f890c2fdad230).(next_key_poscxx . . $ grn/dat/Trie#next_key_pos(ddd8539a2fcdd4ce).());
382 header_cxx . . $ grn/dat/Trie#header_.->set_next_key_poscxx . . $ grn/dat/Header#set_next_key_pos(cb2f890c2fdad230).(
383 next_key_poscxx . . $ grn/dat/Trie#next_key_pos(ddd8539a2fcdd4ce).() + Keycxx . . $ grn/dat/Key#::estimate_sizecxx . . $ grn/dat/Key#estimate_size(2141b656ce2cc063).(key.lengthcxx . . $ grn/dat/Key#length(ddd8539a2fcdd4ce).()));
384 header_cxx . . $ grn/dat/Trie#header_.->set_total_key_lengthcxx . . $ grn/dat/Header#set_total_key_length(cb2f890c2fdad230).(
385 total_key_lengthcxx . . $ grn/dat/Trie#total_key_length(ddd8539a2fcdd4ce).() + key.lengthcxx . . $ grn/dat/Key#length(ddd8539a2fcdd4ce).());
386 header_cxx . . $ grn/dat/Trie#header_.->set_num_keyscxx . . $ grn/dat/Header#set_num_keys(cb2f890c2fdad230).(num_keyscxx . . $ grn/dat/Trie#num_keys(ddd8539a2fcdd4ce).() + 1);
387 } else {
388 if (prev_invalid_key_id == INVALID_KEY_IDcxx . . $ grn/dat/INVALID_KEY_ID.) {
389 header_cxx . . $ grn/dat/Trie#header_.->set_next_key_idcxx . . $ grn/dat/Header#set_next_key_id(cb2f890c2fdad230).(i);
390 } else {
391 ith_entrycxx . . $ grn/dat/Trie#ith_entry(23ff61182d9f5125).(prev_invalid_key_id).set_nextcxx . . $ grn/dat/Entry#set_next(cb2f890c2fdad230).(i);
392 }
393 prev_invalid_key_id = i;
394 }
395 }
396 if (prev_invalid_key_id != INVALID_KEY_IDcxx . . $ grn/dat/INVALID_KEY_ID.) {
397 ith_entrycxx . . $ grn/dat/Trie#ith_entry(23ff61182d9f5125).(prev_invalid_key_id).set_nextcxx . . $ grn/dat/Entry#set_next(cb2f890c2fdad230).(max_key_idcxx . . $ grn/dat/Trie#max_key_id(ddd8539a2fcdd4ce).() + 1);
398 }
399 mkq_sortcxx . . $ grn/dat/Trie#mkq_sort(1b48257950641a0d).(valid_ids.begincxx . . $ grn/dat/Vector#begin(155dc7f103cdb9db).(), valid_ids.endcxx . . $ grn/dat/Vector#end(155dc7f103cdb9db).(), 0);
400 build_from_keyscxx . . $ grn/dat/Trie#build_from_keys(4517b282e5acf643).(valid_ids.begincxx . . $ grn/dat/Vector#begin(155dc7f103cdb9db).(), valid_ids.endcxx . . $ grn/dat/Vector#end(155dc7f103cdb9db).(), 0, ROOT_NODE_IDcxx . . $ grn/dat/ROOT_NODE_ID.);
401 }
402
403 void Triecxx . . $ grn/dat/Trie#::build_from_keyscxx . . $ grn/dat/Trie#build_from_keys(4517b282e5acf643).(const UInt32cxx . . $ grn/dat/UInt32# *begin, const UInt32cxx . . $ grn/dat/UInt32# *end,
404 UInt32cxx . . $ grn/dat/UInt32# depth, UInt32cxx . . $ grn/dat/UInt32# node_id) {
405 if ((end - begin) == 1) {
406 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(node_id).set_key_poscxx . . $ grn/dat/Node#set_key_pos(cb2f890c2fdad230).(ith_entrycxx . . $ grn/dat/Trie#ith_entry(23ff61182d9f5125).(*begin).key_poscxx . . $ grn/dat/Entry#key_pos(ddd8539a2fcdd4ce).());
407 return;
408 }
409
410 UInt32cxx . . $ grn/dat/UInt32# offset;
411 {
412 UInt16cxx . . $ grn/dat/UInt16# labels[MAX_LABELcxx . . $ grn/dat/MAX_LABEL. + 2];
413 UInt32cxx . . $ grn/dat/UInt32# num_labels = 0;
414
415 const UInt32cxx . . $ grn/dat/UInt32# *it = begin;
416 if (ith_keycxx . . $ grn/dat/Trie#ith_key(ac1ad672cda84f14).(*it).lengthcxx . . $ grn/dat/Key#length(ddd8539a2fcdd4ce).() == depth) {
417 labels[num_labels++] = TERMINAL_LABELcxx . . $ grn/dat/TERMINAL_LABEL.;
418 ++it;
419 }
420
421 labels[num_labels++] = (UInt8cxx . . $ grn/dat/UInt8#)ith_keycxx . . $ grn/dat/Trie#ith_key(ac1ad672cda84f14).(*it)[cxx . . $ grn/dat/Key#`operator[]`(ffeb5165310d7d37).depth];
422 for (++it; it < end; ++it) {
423 const Keycxx . . $ grn/dat/Key# &key = ith_keycxx . . $ grn/dat/Trie#ith_key(ac1ad672cda84f14).(*it);
424 if ((UInt8cxx . . $ grn/dat/UInt8#)key[cxx . . $ grn/dat/Key#`operator[]`(ffeb5165310d7d37).depth] != labels[num_labels - 1]) {
425 labels[num_labels++] = (UInt8cxx . . $ grn/dat/UInt8#)key[cxx . . $ grn/dat/Key#`operator[]`(ffeb5165310d7d37).depth];
426 }
427 }
428 labels[num_labels] = INVALID_LABELcxx . . $ grn/dat/INVALID_LABEL.;
429
430 offset = find_offsetcxx . . $ grn/dat/Trie#find_offset(d1a687133290a15f).(labels, num_labels);
431 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(node_id).set_childcxx . . $ grn/dat/Node#set_child(cb2f890c2fdad230).(labels[0]);
432 for (UInt32cxx . . $ grn/dat/UInt32# i = 0; i < num_labels; ++i) {
433 const UInt32cxx . . $ grn/dat/UInt32# next = offset ^ labels[i];
434 reserve_nodecxx . . $ grn/dat/Trie#reserve_node(cb2f890c2fdad230).(next);
435 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(next).set_labelcxx . . $ grn/dat/Node#set_label(cb2f890c2fdad230).(labels[i]);
436 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(next).set_siblingcxx . . $ grn/dat/Node#set_sibling(cb2f890c2fdad230).(labels[i + 1]);
437 }
438
439 if (offset >= num_nodescxx . . $ grn/dat/Trie#num_nodes(ddd8539a2fcdd4ce).()) {
440 reserve_blockcxx . . $ grn/dat/Trie#reserve_block(cb2f890c2fdad230).(num_blockscxx . . $ grn/dat/Trie#num_blocks(ddd8539a2fcdd4ce).());
441 }
442 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(offset).set_is_offsetcxx . . $ grn/dat/Node#set_is_offset(b45ddcbc8423892c).(true);
443 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(node_id).set_offsetcxx . . $ grn/dat/Node#set_offset(cb2f890c2fdad230).(offset);
444 }
445
446 if (ith_keycxx . . $ grn/dat/Trie#ith_key(ac1ad672cda84f14).(*begin).lengthcxx . . $ grn/dat/Key#length(ddd8539a2fcdd4ce).() == depth) {
447 build_from_keyscxx . . $ grn/dat/Trie#build_from_keys(4517b282e5acf643).(begin, begin + 1, depth + 1, offset ^ TERMINAL_LABELcxx . . $ grn/dat/TERMINAL_LABEL.);
448 ++begin;
449 }
450
451 UInt16cxx . . $ grn/dat/UInt16# label = ith_keycxx . . $ grn/dat/Trie#ith_key(ac1ad672cda84f14).(*begin)[cxx . . $ grn/dat/Key#`operator[]`(ffeb5165310d7d37).depth];
452 for (const UInt32cxx . . $ grn/dat/UInt32# *it = begin + 1; it < end; ++it) {
453 const Keycxx . . $ grn/dat/Key# &key = ith_keycxx . . $ grn/dat/Trie#ith_key(ac1ad672cda84f14).(*it);
454 if ((UInt8cxx . . $ grn/dat/UInt8#)key[cxx . . $ grn/dat/Key#`operator[]`(ffeb5165310d7d37).depth] != label) {
455 build_from_keyscxx . . $ grn/dat/Trie#build_from_keys(4517b282e5acf643).(begin, it, depth + 1, offset ^ label);
456 label = (UInt8cxx . . $ grn/dat/UInt8#)key[cxx . . $ grn/dat/Key#`operator[]`(ffeb5165310d7d37).depth];
457 begin = it;
458 }
459 }
460 build_from_keyscxx . . $ grn/dat/Trie#build_from_keys(4517b282e5acf643).(begin, end, depth + 1, offset ^ label);
461 }
462
463 void Triecxx . . $ grn/dat/Trie#::mkq_sortcxx . . $ grn/dat/Trie#mkq_sort(1b48257950641a0d).(UInt32cxx . . $ grn/dat/UInt32# *l, UInt32cxx . . $ grn/dat/UInt32# *r, UInt32cxx . . $ grn/dat/UInt32# depth) {
464 while ((r - l) >= MKQ_SORT_THRESHOLDcxx . . $ grn/dat/MKQ_SORT_THRESHOLD.) {
465 UInt32cxx . . $ grn/dat/UInt32# *pl = l;
466 UInt32cxx . . $ grn/dat/UInt32# *pr = r;
467 UInt32cxx . . $ grn/dat/UInt32# *pivot_l = l;
468 UInt32cxx . . $ grn/dat/UInt32# *pivot_r = r;
469
470 const int pivot = get_mediancxx . . $ grn/dat/Trie#get_median(63a5c3b276ccf2c0).(*l, *(l + (r - l) / 2), *(r - 1), depth);
471 for ( ; ; ) {
472 while (pl < pr) {
473 const int label = get_labelcxx . . $ grn/dat/Trie#get_label(f3c4abd0428a43c1).(*pl, depth);
474 if (label > pivot) {
475 break;
476 } else if (label == pivot) {
477 swap_idscxx . . $ grn/dat/Trie#swap_ids(ce04c39653c001b6).(pl, pivot_l);
478 ++pivot_l;
479 }
480 ++pl;
481 }
482 while (pl < pr) {
483 const int label = get_labelcxx . . $ grn/dat/Trie#get_label(f3c4abd0428a43c1).(*--pr, depth);
484 if (label < pivot) {
485 break;
486 } else if (label == pivot) {
487 swap_idscxx . . $ grn/dat/Trie#swap_ids(ce04c39653c001b6).(pr, --pivot_r);
488 }
489 }
490 if (pl >= pr) {
491 break;
492 }
493 swap_idscxx . . $ grn/dat/Trie#swap_ids(ce04c39653c001b6).(pl, pr);
494 ++pl;
495 }
496 while (pivot_l > l) {
497 swap_idscxx . . $ grn/dat/Trie#swap_ids(ce04c39653c001b6).(--pivot_l, --pl);
498 }
499 while (pivot_r < r) {
500 swap_idscxx . . $ grn/dat/Trie#swap_ids(ce04c39653c001b6).(pivot_r, pr);
501 ++pivot_r;
502 ++pr;
503 }
504
505 if (((pl - l) > (pr - pl)) || ((r - pr) > (pr - pl))) {
506 if ((pr - pl) > 1) {
507 mkq_sortcxx . . $ grn/dat/Trie#mkq_sort(1b48257950641a0d).(pl, pr, depth + 1);
508 }
509
510 if ((pl - l) < (r - pr)) {
511 if ((pl - l) > 1) {
512 mkq_sortcxx . . $ grn/dat/Trie#mkq_sort(1b48257950641a0d).(l, pl, depth);
513 }
514 l = pr;
515 } else {
516 if ((r - pr) > 1) {
517 mkq_sortcxx . . $ grn/dat/Trie#mkq_sort(1b48257950641a0d).(pr, r, depth);
518 }
519 r = pl;
520 }
521 } else {
522 if ((pl - l) > 1) {
523 mkq_sortcxx . . $ grn/dat/Trie#mkq_sort(1b48257950641a0d).(l, pl, depth);
524 }
525
526 if ((r - pr) > 1) {
527 mkq_sortcxx . . $ grn/dat/Trie#mkq_sort(1b48257950641a0d).(pr, r, depth);
528 }
529
530 l = pl, r = pr;
531 if ((pr - pl) > 1) {
532 ++depth;
533 }
534 }
535 }
536
537 if ((r - l) > 1) {
538 insertion_sortcxx . . $ grn/dat/Trie#insertion_sort(1b48257950641a0d).(l, r, depth);
539 }
540 }
541
542 void Triecxx . . $ grn/dat/Trie#::insertion_sortcxx . . $ grn/dat/Trie#insertion_sort(1b48257950641a0d).(UInt32cxx . . $ grn/dat/UInt32# *l, UInt32cxx . . $ grn/dat/UInt32# *r, UInt32cxx . . $ grn/dat/UInt32# depth) {
543 for (UInt32cxx . . $ grn/dat/UInt32# *i = l + 1; i < r; ++i) {
544 for (UInt32cxx . . $ grn/dat/UInt32# *j = i; j > l; --j) {
545 if (less_thancxx . . $ grn/dat/Trie#less_than(971ac2092be9c647).(*(j - 1), *j, depth)) {
546 break;
547 }
548 swap_idscxx . . $ grn/dat/Trie#swap_ids(ce04c39653c001b6).(j - 1, j);
549 }
550 }
551 }
552
553 int Triecxx . . $ grn/dat/Trie#::get_mediancxx . . $ grn/dat/Trie#get_median(63a5c3b276ccf2c0).(UInt32cxx . . $ grn/dat/UInt32# a, UInt32cxx . . $ grn/dat/UInt32# b, UInt32cxx . . $ grn/dat/UInt32# c, UInt32cxx . . $ grn/dat/UInt32# depth) const {
554 const int x = get_labelcxx . . $ grn/dat/Trie#get_label(f3c4abd0428a43c1).(a, depth);
555 const int y = get_labelcxx . . $ grn/dat/Trie#get_label(f3c4abd0428a43c1).(b, depth);
556 const int z = get_labelcxx . . $ grn/dat/Trie#get_label(f3c4abd0428a43c1).(c, depth);
557 if (x < y) {
558 if (y < z) {
559 return y;
560 } else if (x < z) {
561 return z;
562 }
563 return x;
564 } else if (x < z) {
565 return x;
566 } else if (y < z) {
567 return z;
568 }
569 return y;
570 }
571
572 int Triecxx . . $ grn/dat/Trie#::get_labelcxx . . $ grn/dat/Trie#get_label(f3c4abd0428a43c1).(UInt32cxx . . $ grn/dat/UInt32# key_id, UInt32cxx . . $ grn/dat/UInt32# depth) const {
573 const Keycxx . . $ grn/dat/Key# &key = ith_keycxx . . $ grn/dat/Trie#ith_key(ac1ad672cda84f14).(key_id);
574 if (depth == key.lengthcxx . . $ grn/dat/Key#length(ddd8539a2fcdd4ce).()) {
575 return -1;
576 } else {
577 return (UInt8cxx . . $ grn/dat/UInt8#)key[cxx . . $ grn/dat/Key#`operator[]`(ffeb5165310d7d37).depth];
578 }
579 }
580
581 bool Triecxx . . $ grn/dat/Trie#::less_thancxx . . $ grn/dat/Trie#less_than(971ac2092be9c647).(UInt32cxx . . $ grn/dat/UInt32# lhs, UInt32cxx . . $ grn/dat/UInt32# rhs, UInt32cxx . . $ grn/dat/UInt32# depth) const {
582 const Keycxx . . $ grn/dat/Key# &lhs_key = ith_keycxx . . $ grn/dat/Trie#ith_key(ac1ad672cda84f14).(lhs);
583 const Keycxx . . $ grn/dat/Key# &rhs_key = ith_keycxx . . $ grn/dat/Trie#ith_key(ac1ad672cda84f14).(rhs);
584 const UInt32cxx . . $ grn/dat/UInt32# length = (lhs_key.lengthcxx . . $ grn/dat/Key#length(ddd8539a2fcdd4ce).() < rhs_key.lengthcxx . . $ grn/dat/Key#length(ddd8539a2fcdd4ce).()) ?
585 lhs_key.lengthcxx . . $ grn/dat/Key#length(ddd8539a2fcdd4ce).() : rhs_key.lengthcxx . . $ grn/dat/Key#length(ddd8539a2fcdd4ce).();
586 for (UInt32cxx . . $ grn/dat/UInt32# i = depth; i < length; ++i) {
587 if (lhs_key[cxx . . $ grn/dat/Key#`operator[]`(ffeb5165310d7d37).i] != rhs_key[cxx . . $ grn/dat/Key#`operator[]`(ffeb5165310d7d37).i]) {
588 return (UInt8cxx . . $ grn/dat/UInt8#)lhs_key[cxx . . $ grn/dat/Key#`operator[]`(ffeb5165310d7d37).i] < (UInt8cxx . . $ grn/dat/UInt8#)rhs_key[cxx . . $ grn/dat/Key#`operator[]`(ffeb5165310d7d37).i];
589 }
590 }
591 return lhs_key.lengthcxx . . $ grn/dat/Key#length(ddd8539a2fcdd4ce).() < rhs_key.lengthcxx . . $ grn/dat/Key#length(ddd8539a2fcdd4ce).();
592 }
593
594 void Triecxx . . $ grn/dat/Trie#::swap_idscxx . . $ grn/dat/Trie#swap_ids(ce04c39653c001b6).(UInt32cxx . . $ grn/dat/UInt32# *lhs, UInt32cxx . . $ grn/dat/UInt32# *rhs) {
595 UInt32cxx . . $ grn/dat/UInt32# temp = *lhs;
596 *lhs = *rhs;
597 *rhs = temp;
598 }
599
600 bool Triecxx . . $ grn/dat/Trie#::search_keycxx . . $ grn/dat/Trie#search_key(6e3e087186c1b682).(const UInt8cxx . . $ grn/dat/UInt8# *ptr, UInt32cxx . . $ grn/dat/UInt32# length, UInt32cxx . . $ grn/dat/UInt32# *key_pos) const {
601 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!((ptr == NULL) && (length != 0));
602
603 UInt32cxx . . $ grn/dat/UInt32# node_id = ROOT_NODE_IDcxx . . $ grn/dat/ROOT_NODE_ID.;
604 UInt32cxx . . $ grn/dat/UInt32# query_pos = 0;
605 if (!search_linkercxx . . $ grn/dat/Trie#search_linker(fcb4dcaf17b413c9).(ptr, length, node_id, query_pos)) {
606 return false;
607 }
608
609 const Basecxx . . $ grn/dat/Base# base = ith_nodecxx . . $ grn/dat/Trie#ith_node(cc2414b1dc013100).(node_id).basecxx . . $ grn/dat/Node#base(46688f87b1388fe2).();
610 if (!base.is_linkercxx . . $ grn/dat/Base#is_linker(50ce9a9e25b4a850).()) {
611 return false;
612 }
613
614 if (get_keycxx . . $ grn/dat/Trie#get_key(ac1ad672cda84f14).(base.key_poscxx . . $ grn/dat/Base#key_pos(ddd8539a2fcdd4ce).()).equals_tocxx . . $ grn/dat/Key#equals_to(4319e1f56ab94368).(ptr, length, query_pos)) {
615 if (key_pos != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:416:9`!) {
616 *key_pos = base.key_poscxx . . $ grn/dat/Base#key_pos(ddd8539a2fcdd4ce).();
617 }
618 return true;
619 }
620 return false;
621 }
622
623 bool Triecxx . . $ grn/dat/Trie#::search_linkercxx . . $ grn/dat/Trie#search_linker(fcb4dcaf17b413c9).(const UInt8cxx . . $ grn/dat/UInt8# *ptr, UInt32cxx . . $ grn/dat/UInt32# length,
624 UInt32cxx . . $ grn/dat/UInt32# &node_id, UInt32cxx . . $ grn/dat/UInt32# &query_pos) const {
625 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!((ptr == NULL) && (length != 0));
626
627 for ( ; query_pos < length; ++query_pos) {
628 const Basecxx . . $ grn/dat/Base# base = ith_nodecxx . . $ grn/dat/Trie#ith_node(cc2414b1dc013100).(node_id).basecxx . . $ grn/dat/Node#base(46688f87b1388fe2).();
629 if (base.is_linkercxx . . $ grn/dat/Base#is_linker(50ce9a9e25b4a850).()) {
630 return true;
631 }
632
633 const UInt32cxx . . $ grn/dat/UInt32# next = base.offsetcxx . . $ grn/dat/Base#offset(ddd8539a2fcdd4ce).() ^ ptr[query_pos];
634 if (ith_nodecxx . . $ grn/dat/Trie#ith_node(cc2414b1dc013100).(next).labelcxx . . $ grn/dat/Node#label(ddd8539a2fcdd4ce).() != ptr[query_pos]) {
635 return false;
636 }
637 node_id = next;
638 }
639
640 const Basecxx . . $ grn/dat/Base# base = ith_nodecxx . . $ grn/dat/Trie#ith_node(cc2414b1dc013100).(node_id).basecxx . . $ grn/dat/Node#base(46688f87b1388fe2).();
641 if (base.is_linkercxx . . $ grn/dat/Base#is_linker(50ce9a9e25b4a850).()) {
642 return true;
643 }
644
645 const UInt32cxx . . $ grn/dat/UInt32# next = base.offsetcxx . . $ grn/dat/Base#offset(ddd8539a2fcdd4ce).() ^ TERMINAL_LABELcxx . . $ grn/dat/TERMINAL_LABEL.;
646 if (ith_nodecxx . . $ grn/dat/Trie#ith_node(cc2414b1dc013100).(next).labelcxx . . $ grn/dat/Node#label(ddd8539a2fcdd4ce).() != TERMINAL_LABELcxx . . $ grn/dat/TERMINAL_LABEL.) {
647 return false;
648 }
649 node_id = next;
650 return ith_nodecxx . . $ grn/dat/Trie#ith_node(cc2414b1dc013100).(next).is_linkercxx . . $ grn/dat/Node#is_linker(50ce9a9e25b4a850).();
651 }
652
653 bool Triecxx . . $ grn/dat/Trie#::lcp_search_keycxx . . $ grn/dat/Trie#lcp_search_key(6e3e087186c1b682).(const UInt8cxx . . $ grn/dat/UInt8# *ptr, UInt32cxx . . $ grn/dat/UInt32# length,
654 UInt32cxx . . $ grn/dat/UInt32# *key_pos) const {
655 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!((ptr == NULL) && (length != 0));
656
657 bool found = false;
658 UInt32cxx . . $ grn/dat/UInt32# node_id = ROOT_NODE_IDcxx . . $ grn/dat/ROOT_NODE_ID.;
659 UInt32cxx . . $ grn/dat/UInt32# query_pos = 0;
660
661 for ( ; query_pos < length; ++query_pos) {
662 const Basecxx . . $ grn/dat/Base# base = ith_nodecxx . . $ grn/dat/Trie#ith_node(cc2414b1dc013100).(node_id).basecxx . . $ grn/dat/Node#base(46688f87b1388fe2).();
663 if (base.is_linkercxx . . $ grn/dat/Base#is_linker(50ce9a9e25b4a850).()) {
664 const Keycxx . . $ grn/dat/Key# &key = get_keycxx . . $ grn/dat/Trie#get_key(ac1ad672cda84f14).(base.key_poscxx . . $ grn/dat/Base#key_pos(ddd8539a2fcdd4ce).());
665 if ((key.lengthcxx . . $ grn/dat/Key#length(ddd8539a2fcdd4ce).() <= length) &&
666 key.equals_tocxx . . $ grn/dat/Key#equals_to(4319e1f56ab94368).(ptr, key.lengthcxx . . $ grn/dat/Key#length(ddd8539a2fcdd4ce).(), query_pos)) {
667 if (key_pos != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:416:9`!) {
668 *key_pos = base.key_poscxx . . $ grn/dat/Base#key_pos(ddd8539a2fcdd4ce).();
669 }
670 found = true;
671 }
672 return found;
673 }
674
675 if (ith_nodecxx . . $ grn/dat/Trie#ith_node(cc2414b1dc013100).(node_id).childcxx . . $ grn/dat/Node#child(ddd8539a2fcdd4ce).() == TERMINAL_LABELcxx . . $ grn/dat/TERMINAL_LABEL.) {
676 const Basecxx . . $ grn/dat/Base# linker_base =
677 ith_nodecxx . . $ grn/dat/Trie#ith_node(cc2414b1dc013100).(base.offsetcxx . . $ grn/dat/Base#offset(ddd8539a2fcdd4ce).() ^ TERMINAL_LABELcxx . . $ grn/dat/TERMINAL_LABEL.).basecxx . . $ grn/dat/Node#base(46688f87b1388fe2).();
678 if (linker_base.is_linkercxx . . $ grn/dat/Base#is_linker(50ce9a9e25b4a850).()) {
679 if (key_pos != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:416:9`!) {
680 *key_pos = linker_base.key_poscxx . . $ grn/dat/Base#key_pos(ddd8539a2fcdd4ce).();
681 }
682 found = true;
683 }
684 }
685
686 node_id = base.offsetcxx . . $ grn/dat/Base#offset(ddd8539a2fcdd4ce).() ^ ptr[query_pos];
687 if (ith_nodecxx . . $ grn/dat/Trie#ith_node(cc2414b1dc013100).(node_id).labelcxx . . $ grn/dat/Node#label(ddd8539a2fcdd4ce).() != ptr[query_pos]) {
688 return found;
689 }
690 }
691
692 const Basecxx . . $ grn/dat/Base# base = ith_nodecxx . . $ grn/dat/Trie#ith_node(cc2414b1dc013100).(node_id).basecxx . . $ grn/dat/Node#base(46688f87b1388fe2).();
693 if (base.is_linkercxx . . $ grn/dat/Base#is_linker(50ce9a9e25b4a850).()) {
694 const Keycxx . . $ grn/dat/Key# &key = get_keycxx . . $ grn/dat/Trie#get_key(ac1ad672cda84f14).(base.key_poscxx . . $ grn/dat/Base#key_pos(ddd8539a2fcdd4ce).());
695 if (key.lengthcxx . . $ grn/dat/Key#length(ddd8539a2fcdd4ce).() <= length) {
696 if (key_pos != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:416:9`!) {
697 *key_pos = base.key_poscxx . . $ grn/dat/Base#key_pos(ddd8539a2fcdd4ce).();
698 }
699 found = true;
700 }
701 } else if (ith_nodecxx . . $ grn/dat/Trie#ith_node(cc2414b1dc013100).(node_id).childcxx . . $ grn/dat/Node#child(ddd8539a2fcdd4ce).() == TERMINAL_LABELcxx . . $ grn/dat/TERMINAL_LABEL.) {
702 const Basecxx . . $ grn/dat/Base# linker_base = ith_nodecxx . . $ grn/dat/Trie#ith_node(cc2414b1dc013100).(base.offsetcxx . . $ grn/dat/Base#offset(ddd8539a2fcdd4ce).() ^ TERMINAL_LABELcxx . . $ grn/dat/TERMINAL_LABEL.).basecxx . . $ grn/dat/Node#base(46688f87b1388fe2).();
703 if (linker_base.is_linkercxx . . $ grn/dat/Base#is_linker(50ce9a9e25b4a850).()) {
704 if (key_pos != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:416:9`!) {
705 *key_pos = linker_base.key_poscxx . . $ grn/dat/Base#key_pos(ddd8539a2fcdd4ce).();
706 }
707 found = true;
708 }
709 }
710 return found;
711 }
712
713 bool Triecxx . . $ grn/dat/Trie#::remove_keycxx . . $ grn/dat/Trie#remove_key(41ee87f0602ae969).(const UInt8cxx . . $ grn/dat/UInt8# *ptr, UInt32cxx . . $ grn/dat/UInt32# length) {
714 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(STATUS_ERROR, (status_flags() & CHANGING_MASK) != 0);
715 StatusFlagManagercxx . . $ grn/dat/`$anonymous_namespace_lib/dat/trie.cpp`/StatusFlagManager# status_flag_managercxx . . $ grn/dat/`$anonymous_namespace_lib/dat/trie.cpp`/StatusFlagManager#StatusFlagManager(a9ec5a5b9fdbc3df).(header_cxx . . $ grn/dat/Trie#header_., REMOVING_FLAGcxx . . $ grn/dat/REMOVING_FLAG.);
716
717 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!((ptr == NULL) && (length != 0));
718
719 UInt32cxx . . $ grn/dat/UInt32# node_id = ROOT_NODE_IDcxx . . $ grn/dat/ROOT_NODE_ID.;
720 UInt32cxx . . $ grn/dat/UInt32# query_pos = 0;
721 if (!search_linkercxx . . $ grn/dat/Trie#search_linker(fcb4dcaf17b413c9).(ptr, length, node_id, query_pos)) {
722 return false;
723 }
724
725 const UInt32cxx . . $ grn/dat/UInt32# key_pos = ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(node_id).key_poscxx . . $ grn/dat/Node#key_pos(ddd8539a2fcdd4ce).();
726 if (!get_keycxx . . $ grn/dat/Trie#get_key(ac1ad672cda84f14).(key_pos).equals_tocxx . . $ grn/dat/Key#equals_to(4319e1f56ab94368).(ptr, length, query_pos)) {
727 return false;
728 }
729
730 const UInt32cxx . . $ grn/dat/UInt32# key_id = get_keycxx . . $ grn/dat/Trie#get_key(ac1ad672cda84f14).(key_pos).idcxx . . $ grn/dat/Key#id(ddd8539a2fcdd4ce).();
731 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(node_id).set_offsetcxx . . $ grn/dat/Node#set_offset(cb2f890c2fdad230).(INVALID_OFFSETcxx . . $ grn/dat/INVALID_OFFSET.);
732 ith_entrycxx . . $ grn/dat/Trie#ith_entry(23ff61182d9f5125).(key_id).set_nextcxx . . $ grn/dat/Entry#set_next(cb2f890c2fdad230).(next_key_idcxx . . $ grn/dat/Trie#next_key_id(ddd8539a2fcdd4ce).());
733
734 header_cxx . . $ grn/dat/Trie#header_.->set_next_key_idcxx . . $ grn/dat/Header#set_next_key_id(cb2f890c2fdad230).(key_id);
735 header_cxx . . $ grn/dat/Trie#header_.->set_total_key_lengthcxx . . $ grn/dat/Header#set_total_key_length(cb2f890c2fdad230).(total_key_lengthcxx . . $ grn/dat/Trie#total_key_length(ddd8539a2fcdd4ce).() - length);
736 header_cxx . . $ grn/dat/Trie#header_.->set_num_keyscxx . . $ grn/dat/Header#set_num_keys(cb2f890c2fdad230).(num_keyscxx . . $ grn/dat/Trie#num_keys(ddd8539a2fcdd4ce).() - 1);
737 return true;
738 }
739
740 bool Triecxx . . $ grn/dat/Trie#::insert_keycxx . . $ grn/dat/Trie#insert_key(72b38b1922c13078).(const UInt8cxx . . $ grn/dat/UInt8# *ptr, UInt32cxx . . $ grn/dat/UInt32# length, UInt32cxx . . $ grn/dat/UInt32# *key_pos) {
741 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(STATUS_ERROR, (status_flags() & CHANGING_MASK) != 0);
742 StatusFlagManagercxx . . $ grn/dat/`$anonymous_namespace_lib/dat/trie.cpp`/StatusFlagManager# status_flag_managercxx . . $ grn/dat/`$anonymous_namespace_lib/dat/trie.cpp`/StatusFlagManager#StatusFlagManager(a9ec5a5b9fdbc3df).(header_cxx . . $ grn/dat/Trie#header_., INSERTING_FLAGcxx . . $ grn/dat/INSERTING_FLAG.);
743
744 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!((ptr == NULL) && (length != 0));
745
746 UInt32cxx . . $ grn/dat/UInt32# node_id = ROOT_NODE_IDcxx . . $ grn/dat/ROOT_NODE_ID.;
747 UInt32cxx . . $ grn/dat/UInt32# query_pos = 0;
748
749 search_linkercxx . . $ grn/dat/Trie#search_linker(fcb4dcaf17b413c9).(ptr, length, node_id, query_pos);
750 if (!insert_linkercxx . . $ grn/dat/Trie#insert_linker(4a6d4260483f12ab).(ptr, length, node_id, query_pos)) {
751 if (key_pos != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:416:9`!) {
752 *key_pos = ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(node_id).key_poscxx . . $ grn/dat/Node#key_pos(ddd8539a2fcdd4ce).();
753 }
754 return false;
755 }
756
757 const UInt32cxx . . $ grn/dat/UInt32# new_key_id = next_key_idcxx . . $ grn/dat/Trie#next_key_id(ddd8539a2fcdd4ce).();
758 const UInt32cxx . . $ grn/dat/UInt32# new_key_pos = append_keycxx . . $ grn/dat/Trie#append_key(173b885284429e69).(ptr, length, new_key_id);
759
760 header_cxx . . $ grn/dat/Trie#header_.->set_total_key_lengthcxx . . $ grn/dat/Header#set_total_key_length(cb2f890c2fdad230).(total_key_lengthcxx . . $ grn/dat/Trie#total_key_length(ddd8539a2fcdd4ce).() + length);
761 header_cxx . . $ grn/dat/Trie#header_.->set_num_keyscxx . . $ grn/dat/Header#set_num_keys(cb2f890c2fdad230).(num_keyscxx . . $ grn/dat/Trie#num_keys(ddd8539a2fcdd4ce).() + 1);
762 if (new_key_id > max_key_idcxx . . $ grn/dat/Trie#max_key_id(ddd8539a2fcdd4ce).()) {
763 header_cxx . . $ grn/dat/Trie#header_.->set_max_key_idcxx . . $ grn/dat/Header#set_max_key_id(cb2f890c2fdad230).(new_key_id);
764 header_cxx . . $ grn/dat/Trie#header_.->set_next_key_idcxx . . $ grn/dat/Header#set_next_key_id(cb2f890c2fdad230).(new_key_id + 1);
765 } else {
766 header_cxx . . $ grn/dat/Trie#header_.->set_next_key_idcxx . . $ grn/dat/Header#set_next_key_id(cb2f890c2fdad230).(ith_entrycxx . . $ grn/dat/Trie#ith_entry(23ff61182d9f5125).(new_key_id).nextcxx . . $ grn/dat/Entry#next(ddd8539a2fcdd4ce).());
767 }
768
769 ith_entrycxx . . $ grn/dat/Trie#ith_entry(23ff61182d9f5125).(new_key_id).set_key_poscxx . . $ grn/dat/Entry#set_key_pos(cb2f890c2fdad230).(new_key_pos);
770 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(node_id).set_key_poscxx . . $ grn/dat/Node#set_key_pos(cb2f890c2fdad230).(new_key_pos);
771 if (key_pos != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:416:9`!) {
772 *key_pos = new_key_pos;
773 }
774 return true;
775 }
776
777 bool Triecxx . . $ grn/dat/Trie#::insert_linkercxx . . $ grn/dat/Trie#insert_linker(4a6d4260483f12ab).(const UInt8cxx . . $ grn/dat/UInt8# *ptr, UInt32cxx . . $ grn/dat/UInt32# length,
778 UInt32cxx . . $ grn/dat/UInt32# &node_id, UInt32cxx . . $ grn/dat/UInt32# query_pos) {
779 if (ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(node_id).is_linkercxx . . $ grn/dat/Node#is_linker(50ce9a9e25b4a850).()) {
780 const Keycxx . . $ grn/dat/Key# &key = get_keycxx . . $ grn/dat/Trie#get_key(ac1ad672cda84f14).(ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(node_id).key_poscxx . . $ grn/dat/Node#key_pos(ddd8539a2fcdd4ce).());
781 UInt32cxx . . $ grn/dat/UInt32# i = query_pos;
782 while ((i < length) && (i < key.lengthcxx . . $ grn/dat/Key#length(ddd8539a2fcdd4ce).())) {
783 if (ptr[i] != key[cxx . . $ grn/dat/Key#`operator[]`(ffeb5165310d7d37).i]) {
784 break;
785 }
786 ++i;
787 }
788 if ((i == length) && (i == key.lengthcxx . . $ grn/dat/Key#length(ddd8539a2fcdd4ce).())) {
789 return false;
790 }
791 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(SIZE_ERROR, num_keys() >= max_num_keys());
792 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(next_key_id() > max_num_keys());
793
794 for (UInt32cxx . . $ grn/dat/UInt32# j = query_pos; j < i; ++j) {
795 node_id = insert_nodecxx . . $ grn/dat/Trie#insert_node(d18a354f71bab922).(node_id, ptr[j]);
796 }
797 node_id = separatecxx . . $ grn/dat/Trie#separate(16fef09ca7e23a84).(ptr, length, node_id, i);
798 return true;
799 } else if (ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(node_id).labelcxx . . $ grn/dat/Node#label(ddd8539a2fcdd4ce).() == TERMINAL_LABELcxx . . $ grn/dat/TERMINAL_LABEL.) {
800 return true;
801 } else {
802 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(SIZE_ERROR, num_keys() >= max_num_keys());
803 const UInt16cxx . . $ grn/dat/UInt16# label = (query_pos < length) ?
804 (UInt16cxx . . $ grn/dat/UInt16#)ptr[query_pos] : (UInt16cxx . . $ grn/dat/UInt16#)TERMINAL_LABELcxx . . $ grn/dat/TERMINAL_LABEL.;
805 const Basecxx . . $ grn/dat/Base# base = ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(node_id).basecxx . . $ grn/dat/Node#base(46688f87b1388fe2).();
806 if ((base.offsetcxx . . $ grn/dat/Base#offset(ddd8539a2fcdd4ce).() == INVALID_OFFSETcxx . . $ grn/dat/INVALID_OFFSET.) ||
807 !ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(base.offsetcxx . . $ grn/dat/Base#offset(ddd8539a2fcdd4ce).() ^ label).is_phantomcxx . . $ grn/dat/Node#is_phantom(50ce9a9e25b4a850).()) {
808 resolvecxx . . $ grn/dat/Trie#resolve(272d193675e92631).(node_id, label);
809 }
810 node_id = insert_nodecxx . . $ grn/dat/Trie#insert_node(d18a354f71bab922).(node_id, label);
811 return true;
812 }
813 }
814
815 bool Triecxx . . $ grn/dat/Trie#::update_keycxx . . $ grn/dat/Trie#update_key(e88d0583c9a0e46c).(const Keycxx . . $ grn/dat/Key# &key, const UInt8cxx . . $ grn/dat/UInt8# *ptr, UInt32cxx . . $ grn/dat/UInt32# length,
816 UInt32cxx . . $ grn/dat/UInt32# *key_pos) {
817 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(STATUS_ERROR, (status_flags() & CHANGING_MASK) != 0);
818 StatusFlagManagercxx . . $ grn/dat/`$anonymous_namespace_lib/dat/trie.cpp`/StatusFlagManager# status_flag_managercxx . . $ grn/dat/`$anonymous_namespace_lib/dat/trie.cpp`/StatusFlagManager#StatusFlagManager(a9ec5a5b9fdbc3df).(header_cxx . . $ grn/dat/Trie#header_., UPDATING_FLAGcxx . . $ grn/dat/UPDATING_FLAG.);
819
820 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!((ptr == NULL) && (length != 0));
821
822 if (!key.is_validcxx . . $ grn/dat/Key#is_valid(50ce9a9e25b4a850).()) {
823 return false;
824 }
825
826 UInt32cxx . . $ grn/dat/UInt32# node_id = ROOT_NODE_IDcxx . . $ grn/dat/ROOT_NODE_ID.;
827 UInt32cxx . . $ grn/dat/UInt32# query_pos = 0;
828
829 search_linkercxx . . $ grn/dat/Trie#search_linker(fcb4dcaf17b413c9).(ptr, length, node_id, query_pos);
830 if (!insert_linkercxx . . $ grn/dat/Trie#insert_linker(4a6d4260483f12ab).(ptr, length, node_id, query_pos)) {
831 if (key_pos != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:416:9`!) {
832 *key_pos = ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(node_id).key_poscxx . . $ grn/dat/Node#key_pos(ddd8539a2fcdd4ce).();
833 }
834 return false;
835 }
836
837 const UInt32cxx . . $ grn/dat/UInt32# new_key_pos = append_keycxx . . $ grn/dat/Trie#append_key(173b885284429e69).(ptr, length, key.idcxx . . $ grn/dat/Key#id(ddd8539a2fcdd4ce).());
838 header_cxx . . $ grn/dat/Trie#header_.->set_total_key_lengthcxx . . $ grn/dat/Header#set_total_key_length(cb2f890c2fdad230).(total_key_lengthcxx . . $ grn/dat/Trie#total_key_length(ddd8539a2fcdd4ce).() + length - key.lengthcxx . . $ grn/dat/Key#length(ddd8539a2fcdd4ce).());
839 ith_entrycxx . . $ grn/dat/Trie#ith_entry(23ff61182d9f5125).(key.idcxx . . $ grn/dat/Key#id(ddd8539a2fcdd4ce).()).set_key_poscxx . . $ grn/dat/Entry#set_key_pos(cb2f890c2fdad230).(new_key_pos);
840 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(node_id).set_key_poscxx . . $ grn/dat/Node#set_key_pos(cb2f890c2fdad230).(new_key_pos);
841 if (key_pos != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:416:9`!) {
842 *key_pos = new_key_pos;
843 }
844
845 node_id = ROOT_NODE_IDcxx . . $ grn/dat/ROOT_NODE_ID.;
846 query_pos = 0;
847 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(UNEXPECTED_ERROR,
848 !search_linker(static_cast<const UInt8 *>(key.ptr()), key.length(),
849 node_id, query_pos));
850 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(node_id).set_offsetcxx . . $ grn/dat/Node#set_offset(cb2f890c2fdad230).(INVALID_OFFSETcxx . . $ grn/dat/INVALID_OFFSET.);
851 return true;
852 }
853
854 UInt32cxx . . $ grn/dat/UInt32# Triecxx . . $ grn/dat/Trie#::insert_nodecxx . . $ grn/dat/Trie#insert_node(d18a354f71bab922).(UInt32cxx . . $ grn/dat/UInt32# node_id, UInt16cxx . . $ grn/dat/UInt16# label) {
855 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(node_id >= num_nodes());
856 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(label > MAX_LABEL);
857
858 const Basecxx . . $ grn/dat/Base# base = ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(node_id).basecxx . . $ grn/dat/Node#base(46688f87b1388fe2).();
859 UInt32cxx . . $ grn/dat/UInt32# offset;
860 if (base.is_linkercxx . . $ grn/dat/Base#is_linker(50ce9a9e25b4a850).() || (base.offsetcxx . . $ grn/dat/Base#offset(ddd8539a2fcdd4ce).() == INVALID_OFFSETcxx . . $ grn/dat/INVALID_OFFSET.)) {
861 offset = find_offsetcxx . . $ grn/dat/Trie#find_offset(d1a687133290a15f).(&label, 1);
862 } else {
863 offset = base.offsetcxx . . $ grn/dat/Base#offset(ddd8539a2fcdd4ce).();
864 }
865
866 const UInt32cxx . . $ grn/dat/UInt32# next = offset ^ label;
867 reserve_nodecxx . . $ grn/dat/Trie#reserve_node(cb2f890c2fdad230).(next);
868
869 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(next).set_labelcxx . . $ grn/dat/Node#set_label(cb2f890c2fdad230).(label);
870 if (base.is_linkercxx . . $ grn/dat/Base#is_linker(50ce9a9e25b4a850).()) {
871 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(ith_node(offset).is_offset());
872 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(offset).set_is_offsetcxx . . $ grn/dat/Node#set_is_offset(b45ddcbc8423892c).(true);
873 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(next).set_key_poscxx . . $ grn/dat/Node#set_key_pos(cb2f890c2fdad230).(base.key_poscxx . . $ grn/dat/Base#key_pos(ddd8539a2fcdd4ce).());
874 } else if (base.offsetcxx . . $ grn/dat/Base#offset(ddd8539a2fcdd4ce).() == INVALID_OFFSETcxx . . $ grn/dat/INVALID_OFFSET.) {
875 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(ith_node(offset).is_offset());
876 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(offset).set_is_offsetcxx . . $ grn/dat/Node#set_is_offset(b45ddcbc8423892c).(true);
877 } else {
878 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(!ith_node(offset).is_offset());
879 }
880 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(node_id).set_offsetcxx . . $ grn/dat/Node#set_offset(cb2f890c2fdad230).(offset);
881
882 const UInt32cxx . . $ grn/dat/UInt32# child_label = ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(node_id).childcxx . . $ grn/dat/Node#child(ddd8539a2fcdd4ce).();
883 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(child_label == label);
884 if (child_label == INVALID_LABELcxx . . $ grn/dat/INVALID_LABEL.) {
885 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(node_id).set_childcxx . . $ grn/dat/Node#set_child(cb2f890c2fdad230).(label);
886 } else if ((label == TERMINAL_LABELcxx . . $ grn/dat/TERMINAL_LABEL.) ||
887 ((child_label != TERMINAL_LABELcxx . . $ grn/dat/TERMINAL_LABEL.) && (label < child_label))) {
888 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(ith_node(offset ^ child_label).is_phantom());
889 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(ith_node(offset ^ child_label).label() != child_label);
890 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(next).set_siblingcxx . . $ grn/dat/Node#set_sibling(cb2f890c2fdad230).(child_label);
891 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(node_id).set_childcxx . . $ grn/dat/Node#set_child(cb2f890c2fdad230).(label);
892 } else {
893 UInt32cxx . . $ grn/dat/UInt32# prev = offset ^ child_label;
894 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(ith_node(prev).label() != child_label);
895 UInt32cxx . . $ grn/dat/UInt32# sibling_label = ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(prev).siblingcxx . . $ grn/dat/Node#sibling(ddd8539a2fcdd4ce).();
896 while (label > sibling_label) {
897 prev = offset ^ sibling_label;
898 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(ith_node(prev).label() != sibling_label);
899 sibling_label = ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(prev).siblingcxx . . $ grn/dat/Node#sibling(ddd8539a2fcdd4ce).();
900 }
901 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(label == sibling_label);
902 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(next).set_siblingcxx . . $ grn/dat/Node#set_sibling(cb2f890c2fdad230).(ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(prev).siblingcxx . . $ grn/dat/Node#sibling(ddd8539a2fcdd4ce).());
903 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(prev).set_siblingcxx . . $ grn/dat/Node#set_sibling(cb2f890c2fdad230).(label);
904 }
905 return next;
906 }
907
908 UInt32cxx . . $ grn/dat/UInt32# Triecxx . . $ grn/dat/Trie#::append_keycxx . . $ grn/dat/Trie#append_key(173b885284429e69).(const UInt8cxx . . $ grn/dat/UInt8# *ptr, UInt32cxx . . $ grn/dat/UInt32# length, UInt32cxx . . $ grn/dat/UInt32# key_id) {
909 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(SIZE_ERROR, key_id > max_num_keys());
910
911 const UInt32cxx . . $ grn/dat/UInt32# key_pos = next_key_poscxx . . $ grn/dat/Trie#next_key_pos(ddd8539a2fcdd4ce).();
912 const UInt32cxx . . $ grn/dat/UInt32# key_size = Keycxx . . $ grn/dat/Key#::estimate_sizecxx . . $ grn/dat/Key#estimate_size(2141b656ce2cc063).(length);
913
914 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(SIZE_ERROR, key_size > (key_buf_size() - key_pos));
915 Keycxx . . $ grn/dat/Key#::createcxx . . $ grn/dat/Key#create(66d57bc96acb1d3c).(key_buf_cxx . . $ grn/dat/Trie#key_buf_..ptrcxx . . $ grn/dat/Array#ptr(5a2a78a048fb49a8).() + key_pos, key_id, ptr, length);
916
917 header_cxx . . $ grn/dat/Trie#header_.->set_next_key_poscxx . . $ grn/dat/Header#set_next_key_pos(cb2f890c2fdad230).(key_pos + key_size);
918 return key_pos;
919 }
920
921 UInt32cxx . . $ grn/dat/UInt32# Triecxx . . $ grn/dat/Trie#::separatecxx . . $ grn/dat/Trie#separate(16fef09ca7e23a84).(const UInt8cxx . . $ grn/dat/UInt8# *ptr, UInt32cxx . . $ grn/dat/UInt32# length,
922 UInt32cxx . . $ grn/dat/UInt32# node_id, UInt32cxx . . $ grn/dat/UInt32# i) {
923 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(node_id >= num_nodes());
924 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(!ith_node(node_id).is_linker());
925 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(i > length);
926
927 const UInt32cxx . . $ grn/dat/UInt32# key_pos = ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(node_id).key_poscxx . . $ grn/dat/Node#key_pos(ddd8539a2fcdd4ce).();
928 const Keycxx . . $ grn/dat/Key# &key = get_keycxx . . $ grn/dat/Trie#get_key(ac1ad672cda84f14).(key_pos);
929
930 UInt16cxx . . $ grn/dat/UInt16# labels[2];
931 labels[0] = (i < key.lengthcxx . . $ grn/dat/Key#length(ddd8539a2fcdd4ce).()) ? (UInt16cxx . . $ grn/dat/UInt16#)key[cxx . . $ grn/dat/Key#`operator[]`(ffeb5165310d7d37).i] : (UInt16cxx . . $ grn/dat/UInt16#)TERMINAL_LABELcxx . . $ grn/dat/TERMINAL_LABEL.;
932 labels[1] = (i < length) ? (UInt16cxx . . $ grn/dat/UInt16#)ptr[i] : (UInt16cxx . . $ grn/dat/UInt16#)TERMINAL_LABELcxx . . $ grn/dat/TERMINAL_LABEL.;
933 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(labels[0] == labels[1]);
934
935 const UInt32cxx . . $ grn/dat/UInt32# offset = find_offsetcxx . . $ grn/dat/Trie#find_offset(d1a687133290a15f).(labels, 2);
936
937 UInt32cxx . . $ grn/dat/UInt32# next = offset ^ labels[0];
938 reserve_nodecxx . . $ grn/dat/Trie#reserve_node(cb2f890c2fdad230).(next);
939 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(ith_node(offset).is_offset());
940
941 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(next).set_labelcxx . . $ grn/dat/Node#set_label(cb2f890c2fdad230).(labels[0]);
942 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(next).set_key_poscxx . . $ grn/dat/Node#set_key_pos(cb2f890c2fdad230).(key_pos);
943
944 next = offset ^ labels[1];
945 reserve_nodecxx . . $ grn/dat/Trie#reserve_node(cb2f890c2fdad230).(next);
946
947 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(next).set_labelcxx . . $ grn/dat/Node#set_label(cb2f890c2fdad230).(labels[1]);
948
949 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(offset).set_is_offsetcxx . . $ grn/dat/Node#set_is_offset(b45ddcbc8423892c).(true);
950 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(node_id).set_offsetcxx . . $ grn/dat/Node#set_offset(cb2f890c2fdad230).(offset);
951
952 if ((labels[0] == TERMINAL_LABELcxx . . $ grn/dat/TERMINAL_LABEL.) ||
953 ((labels[1] != TERMINAL_LABELcxx . . $ grn/dat/TERMINAL_LABEL.) && (labels[0] < labels[1]))) {
954 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(node_id).set_childcxx . . $ grn/dat/Node#set_child(cb2f890c2fdad230).(labels[0]);
955 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(offset ^ labels[0]).set_siblingcxx . . $ grn/dat/Node#set_sibling(cb2f890c2fdad230).(labels[1]);
956 } else {
957 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(node_id).set_childcxx . . $ grn/dat/Node#set_child(cb2f890c2fdad230).(labels[1]);
958 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(offset ^ labels[1]).set_siblingcxx . . $ grn/dat/Node#set_sibling(cb2f890c2fdad230).(labels[0]);
959 }
960 return next;
961 }
962
963 void Triecxx . . $ grn/dat/Trie#::resolvecxx . . $ grn/dat/Trie#resolve(272d193675e92631).(UInt32cxx . . $ grn/dat/UInt32# node_id, UInt16cxx . . $ grn/dat/UInt16# label) {
964 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(node_id >= num_nodes());
965 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(ith_node(node_id).is_linker());
966 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(label > MAX_LABEL);
967
968 UInt32cxx . . $ grn/dat/UInt32# offset = ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(node_id).offsetcxx . . $ grn/dat/Node#offset(ddd8539a2fcdd4ce).();
969 if (offset != INVALID_OFFSETcxx . . $ grn/dat/INVALID_OFFSET.) {
970 UInt16cxx . . $ grn/dat/UInt16# labels[MAX_LABELcxx . . $ grn/dat/MAX_LABEL. + 1];
971 UInt32cxx . . $ grn/dat/UInt32# num_labels = 0;
972
973 UInt32cxx . . $ grn/dat/UInt32# next_label = ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(node_id).childcxx . . $ grn/dat/Node#child(ddd8539a2fcdd4ce).();
974 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(next_label == INVALID_LABEL);
975 while (next_label != INVALID_LABELcxx . . $ grn/dat/INVALID_LABEL.) {
976 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(next_label > MAX_LABEL);
977 labels[num_labels++] = static_cast<UInt16cxx . . $ grn/dat/UInt16#>(next_label);
978 next_label = ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(offset ^ next_label).siblingcxx . . $ grn/dat/Node#sibling(ddd8539a2fcdd4ce).();
979 }
980 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(num_labels == 0);
981
982 labels[num_labels] = label;
983 offset = find_offsetcxx . . $ grn/dat/Trie#find_offset(d1a687133290a15f).(labels, num_labels + 1);
984 migrate_nodescxx . . $ grn/dat/Trie#migrate_nodes(5a50487d8a975787).(node_id, offset, labels, num_labels);
985 } else {
986 offset = find_offsetcxx . . $ grn/dat/Trie#find_offset(d1a687133290a15f).(&label, 1);
987 if (offset >= num_nodescxx . . $ grn/dat/Trie#num_nodes(ddd8539a2fcdd4ce).()) {
988 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!((offset / BLOCK_SIZE) != num_blocks());
989 reserve_blockcxx . . $ grn/dat/Trie#reserve_block(cb2f890c2fdad230).(num_blockscxx . . $ grn/dat/Trie#num_blocks(ddd8539a2fcdd4ce).());
990 }
991 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(offset).set_is_offsetcxx . . $ grn/dat/Node#set_is_offset(b45ddcbc8423892c).(true);
992 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(node_id).set_offsetcxx . . $ grn/dat/Node#set_offset(cb2f890c2fdad230).(offset);
993 }
994 }
995
996 void Triecxx . . $ grn/dat/Trie#::migrate_nodescxx . . $ grn/dat/Trie#migrate_nodes(5a50487d8a975787).(UInt32cxx . . $ grn/dat/UInt32# node_id, UInt32cxx . . $ grn/dat/UInt32# dest_offset,
997 const UInt16cxx . . $ grn/dat/UInt16# *labels, UInt32cxx . . $ grn/dat/UInt32# num_labels) {
998 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(node_id >= num_nodes());
999 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(ith_node(node_id).is_linker());
1000 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(labels == NULL);
1001 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(num_labels == 0);
1002 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(num_labels > (MAX_LABEL + 1));
1003
1004 const UInt32cxx . . $ grn/dat/UInt32# src_offset = ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(node_id).offsetcxx . . $ grn/dat/Node#offset(ddd8539a2fcdd4ce).();
1005 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(src_offset == INVALID_OFFSET);
1006 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(!ith_node(src_offset).is_offset());
1007
1008 for (UInt32cxx . . $ grn/dat/UInt32# i = 0; i < num_labels; ++i) {
1009 const UInt32cxx . . $ grn/dat/UInt32# src_node_id = src_offset ^ labels[i];
1010 const UInt32cxx . . $ grn/dat/UInt32# dest_node_id = dest_offset ^ labels[i];
1011 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(ith_node(src_node_id).is_phantom());
1012 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(ith_node(src_node_id).label() != labels[i]);
1013
1014 reserve_nodecxx . . $ grn/dat/Trie#reserve_node(cb2f890c2fdad230).(dest_node_id);
1015 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(dest_node_id).set_except_is_offsetcxx . . $ grn/dat/Node#set_except_is_offset(cb2f890c2fdad230).(
1016 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(src_node_id).except_is_offsetcxx . . $ grn/dat/Node#except_is_offset(ddd8539a2fcdd4ce).());
1017 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(dest_node_id).set_basecxx . . $ grn/dat/Node#set_base(ee515c6d8c83a2fa).(ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(src_node_id).basecxx . . $ grn/dat/Node#base(46688f87b1388fe2).());
1018 }
1019 header_cxx . . $ grn/dat/Trie#header_.->set_num_zombiescxx . . $ grn/dat/Header#set_num_zombies(cb2f890c2fdad230).(num_zombiescxx . . $ grn/dat/Trie#num_zombies(ddd8539a2fcdd4ce).() + num_labels);
1020
1021 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(ith_node(dest_offset).is_offset());
1022 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(dest_offset).set_is_offsetcxx . . $ grn/dat/Node#set_is_offset(b45ddcbc8423892c).(true);
1023 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(node_id).set_offsetcxx . . $ grn/dat/Node#set_offset(cb2f890c2fdad230).(dest_offset);
1024 }
1025
1026 UInt32cxx . . $ grn/dat/UInt32# Triecxx . . $ grn/dat/Trie#::find_offsetcxx . . $ grn/dat/Trie#find_offset(d1a687133290a15f).(const UInt16cxx . . $ grn/dat/UInt16# *labels, UInt32cxx . . $ grn/dat/UInt32# num_labels) {
1027 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(labels == NULL);
1028 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(num_labels == 0);
1029 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(num_labels > (MAX_LABEL + 1));
1030
1031 // Blocks are tested in descending order of level. Basically, a lower level
1032 // block contains more phantom nodes.
1033 UInt32cxx . . $ grn/dat/UInt32# level = 1;
1034 while (num_labels >= (1U << level)) {
1035 ++level;
1036 }
1037 level = (level < MAX_BLOCK_LEVELcxx . . $ grn/dat/MAX_BLOCK_LEVEL.) ? (MAX_BLOCK_LEVELcxx . . $ grn/dat/MAX_BLOCK_LEVEL. - level) : 0;
1038
1039 UInt32cxx . . $ grn/dat/UInt32# block_count = 0;
1040 do {
1041 UInt32cxx . . $ grn/dat/UInt32# leader = header_cxx . . $ grn/dat/Trie#header_.->ith_leadercxx . . $ grn/dat/Header#ith_leader(560347b7e9428769).(level);
1042 if (leader == INVALID_LEADERcxx . . $ grn/dat/INVALID_LEADER.) {
1043 // This level has no blocks and it is thus skipped.
1044 continue;
1045 }
1046
1047 UInt32cxx . . $ grn/dat/UInt32# block_id = leader;
1048 do {
1049 const Blockcxx . . $ grn/dat/Block# &block = ith_blockcxx . . $ grn/dat/Trie#ith_block(95549d8a1402ec44).(block_id);
1050 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(block.level() != level);
1051
1052 const UInt32cxx . . $ grn/dat/UInt32# first = (block_id * BLOCK_SIZEcxx . . $ grn/dat/BLOCK_SIZE.) | block.first_phantomcxx . . $ grn/dat/Block#first_phantom(ddd8539a2fcdd4ce).();
1053 UInt32cxx . . $ grn/dat/UInt32# node_id = first;
1054 do {
1055 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(!ith_node(node_id).is_phantom());
1056 const UInt32cxx . . $ grn/dat/UInt32# offset = node_id ^ labels[0];
1057 if (!ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(offset).is_offsetcxx . . $ grn/dat/Node#is_offset(50ce9a9e25b4a850).()) {
1058 UInt32cxx . . $ grn/dat/UInt32# i = 1;
1059 for ( ; i < num_labels; ++i) {
1060 if (!ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(offset ^ labels[i]).is_phantomcxx . . $ grn/dat/Node#is_phantom(50ce9a9e25b4a850).()) {
1061 break;
1062 }
1063 }
1064 if (i >= num_labels) {
1065 return offset;
1066 }
1067 }
1068 node_id = (block_id * BLOCK_SIZEcxx . . $ grn/dat/BLOCK_SIZE.) | ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(node_id).nextcxx . . $ grn/dat/Node#next(ddd8539a2fcdd4ce).();
1069 } while (node_id != first);
1070
1071 const UInt32cxx . . $ grn/dat/UInt32# prev = block_id;
1072 const UInt32cxx . . $ grn/dat/UInt32# next = block.nextcxx . . $ grn/dat/Block#next(ddd8539a2fcdd4ce).();
1073 block_id = next;
1074 ith_blockcxx . . $ grn/dat/Trie#ith_block(95549d8a1402ec44).(prev).set_failure_countcxx . . $ grn/dat/Block#set_failure_count(cb2f890c2fdad230).(ith_blockcxx . . $ grn/dat/Trie#ith_block(95549d8a1402ec44).(prev).failure_countcxx . . $ grn/dat/Block#failure_count(ddd8539a2fcdd4ce).() + 1);
1075
1076 // The level of a block is updated when this function fails many times,
1077 // actually MAX_FAILURE_COUNT times, in that block.
1078 if (ith_blockcxx . . $ grn/dat/Trie#ith_block(95549d8a1402ec44).(prev).failure_countcxx . . $ grn/dat/Block#failure_count(ddd8539a2fcdd4ce).() == MAX_FAILURE_COUNTcxx . . $ grn/dat/MAX_FAILURE_COUNT.) {
1079 update_block_levelcxx . . $ grn/dat/Trie#update_block_level(b4d55b1286ff73e8).(prev, level + 1);
1080 if (next == leader) {
1081 break;
1082 } else {
1083 // Note that the leader might be updated in the level update.
1084 leader = header_cxx . . $ grn/dat/Trie#header_.->ith_leadercxx . . $ grn/dat/Header#ith_leader(560347b7e9428769).(level);
1085 continue;
1086 }
1087 }
1088 } while ((++block_count < MAX_BLOCK_COUNTcxx . . $ grn/dat/MAX_BLOCK_COUNT.) && (block_id != leader));
1089 } while ((block_count < MAX_BLOCK_COUNTcxx . . $ grn/dat/MAX_BLOCK_COUNT.) && (level-- != 0));
1090
1091 return num_nodescxx . . $ grn/dat/Trie#num_nodes(ddd8539a2fcdd4ce).() ^ labels[0];
1092 }
1093
1094 void Triecxx . . $ grn/dat/Trie#::reserve_nodecxx . . $ grn/dat/Trie#reserve_node(cb2f890c2fdad230).(UInt32cxx . . $ grn/dat/UInt32# node_id) {
1095 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(node_id > num_nodes());
1096 if (node_id >= num_nodescxx . . $ grn/dat/Trie#num_nodes(ddd8539a2fcdd4ce).()) {
1097 reserve_blockcxx . . $ grn/dat/Trie#reserve_block(cb2f890c2fdad230).(node_id / BLOCK_SIZEcxx . . $ grn/dat/BLOCK_SIZE.);
1098 }
1099
1100 Nodecxx . . $ grn/dat/Node# &node = ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(node_id);
1101 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(!node.is_phantom());
1102
1103 const UInt32cxx . . $ grn/dat/UInt32# block_id = node_id / BLOCK_SIZEcxx . . $ grn/dat/BLOCK_SIZE.;
1104 Blockcxx . . $ grn/dat/Block# &block = ith_blockcxx . . $ grn/dat/Trie#ith_block(95549d8a1402ec44).(block_id);
1105 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(block.num_phantoms() == 0);
1106
1107 const UInt32cxx . . $ grn/dat/UInt32# next = (block_id * BLOCK_SIZEcxx . . $ grn/dat/BLOCK_SIZE.) | node.nextcxx . . $ grn/dat/Node#next(ddd8539a2fcdd4ce).();
1108 const UInt32cxx . . $ grn/dat/UInt32# prev = (block_id * BLOCK_SIZEcxx . . $ grn/dat/BLOCK_SIZE.) | node.prevcxx . . $ grn/dat/Node#prev(ddd8539a2fcdd4ce).();
1109 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(next >= num_nodes());
1110 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(prev >= num_nodes());
1111
1112 if ((node_id & BLOCK_MASKcxx . . $ grn/dat/BLOCK_MASK.) == block.first_phantomcxx . . $ grn/dat/Block#first_phantom(ddd8539a2fcdd4ce).()) {
1113 // The first phantom node is removed from the block and the second phantom
1114 // node comes first.
1115 block.set_first_phantomcxx . . $ grn/dat/Block#set_first_phantom(cb2f890c2fdad230).(next & BLOCK_MASKcxx . . $ grn/dat/BLOCK_MASK.);
1116 }
1117
1118 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(next).set_prevcxx . . $ grn/dat/Node#set_prev(cb2f890c2fdad230).(prev & BLOCK_MASKcxx . . $ grn/dat/BLOCK_MASK.);
1119 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(prev).set_nextcxx . . $ grn/dat/Node#set_next(cb2f890c2fdad230).(next & BLOCK_MASKcxx . . $ grn/dat/BLOCK_MASK.);
1120
1121 if (block.levelcxx . . $ grn/dat/Block#level(ddd8539a2fcdd4ce).() != MAX_BLOCK_LEVELcxx . . $ grn/dat/MAX_BLOCK_LEVEL.) {
1122 const UInt32cxx . . $ grn/dat/UInt32# threshold = 1U << ((MAX_BLOCK_LEVELcxx . . $ grn/dat/MAX_BLOCK_LEVEL. - block.levelcxx . . $ grn/dat/Block#level(ddd8539a2fcdd4ce).() - 1) * 2);
1123 if (block.num_phantomscxx . . $ grn/dat/Block#num_phantoms(ddd8539a2fcdd4ce).() == threshold) {
1124 update_block_levelcxx . . $ grn/dat/Trie#update_block_level(b4d55b1286ff73e8).(block_id, block.levelcxx . . $ grn/dat/Block#level(ddd8539a2fcdd4ce).() + 1);
1125 }
1126 }
1127 block.set_num_phantomscxx . . $ grn/dat/Block#set_num_phantoms(cb2f890c2fdad230).(block.num_phantomscxx . . $ grn/dat/Block#num_phantoms(ddd8539a2fcdd4ce).() - 1);
1128
1129 node.set_is_phantomcxx . . $ grn/dat/Node#set_is_phantom(b45ddcbc8423892c).(false);
1130
1131 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(node.offset() != INVALID_OFFSET);
1132 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(node.label() != INVALID_LABEL);
1133
1134 header_cxx . . $ grn/dat/Trie#header_.->set_num_phantomscxx . . $ grn/dat/Header#set_num_phantoms(cb2f890c2fdad230).(num_phantomscxx . . $ grn/dat/Trie#num_phantoms(ddd8539a2fcdd4ce).() - 1);
1135 }
1136
1137 void Triecxx . . $ grn/dat/Trie#::reserve_blockcxx . . $ grn/dat/Trie#reserve_block(cb2f890c2fdad230).(UInt32cxx . . $ grn/dat/UInt32# block_id) {
1138 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(block_id != num_blocks());
1139 GRN_DAT_THROW_IFcxx . . $ `lib/dat/dat.hpp:232:9`!(SIZE_ERROR, block_id >= max_num_blocks());
1140
1141 header_cxx . . $ grn/dat/Trie#header_.->set_num_blockscxx . . $ grn/dat/Header#set_num_blocks(cb2f890c2fdad230).(block_id + 1);
1142 ith_blockcxx . . $ grn/dat/Trie#ith_block(95549d8a1402ec44).(block_id).set_failure_countcxx . . $ grn/dat/Block#set_failure_count(cb2f890c2fdad230).(0);
1143 ith_blockcxx . . $ grn/dat/Trie#ith_block(95549d8a1402ec44).(block_id).set_first_phantomcxx . . $ grn/dat/Block#set_first_phantom(cb2f890c2fdad230).(0);
1144 ith_blockcxx . . $ grn/dat/Trie#ith_block(95549d8a1402ec44).(block_id).set_num_phantomscxx . . $ grn/dat/Block#set_num_phantoms(cb2f890c2fdad230).(BLOCK_SIZEcxx . . $ grn/dat/BLOCK_SIZE.);
1145
1146 const UInt32cxx . . $ grn/dat/UInt32# begin = block_id * BLOCK_SIZEcxx . . $ grn/dat/BLOCK_SIZE.;
1147 const UInt32cxx . . $ grn/dat/UInt32# end = begin + BLOCK_SIZEcxx . . $ grn/dat/BLOCK_SIZE.;
1148 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(end != num_nodes());
1149
1150 Basecxx . . $ grn/dat/Base# basecxx . . $ grn/dat/Base#Base(49f6e7a06ebc5aa8).;
1151 base.set_offsetcxx . . $ grn/dat/Base#set_offset(cb2f890c2fdad230).(INVALID_OFFSETcxx . . $ grn/dat/INVALID_OFFSET.);
1152
1153 Checkcxx . . $ grn/dat/Check# checkcxx . . $ grn/dat/Check#Check(49f6e7a06ebc5aa8).;
1154 check.set_is_phantomcxx . . $ grn/dat/Check#set_is_phantom(b45ddcbc8423892c).(true);
1155
1156 for (UInt32cxx . . $ grn/dat/UInt32# i = begin; i < end; ++i) {
1157 check.set_prevcxx . . $ grn/dat/Check#set_prev(cb2f890c2fdad230).((i - 1) & BLOCK_MASKcxx . . $ grn/dat/BLOCK_MASK.);
1158 check.set_nextcxx . . $ grn/dat/Check#set_next(cb2f890c2fdad230).((i + 1) & BLOCK_MASKcxx . . $ grn/dat/BLOCK_MASK.);
1159 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(i).set_basecxx . . $ grn/dat/Node#set_base(ee515c6d8c83a2fa).(base);
1160 ith_nodecxx . . $ grn/dat/Trie#ith_node(945db613494e192f).(i).set_checkcxx . . $ grn/dat/Node#set_check(50df4e9dae9488df).(check);
1161 }
1162
1163 // The level of the new block is 0.
1164 set_block_levelcxx . . $ grn/dat/Trie#set_block_level(b4d55b1286ff73e8).(block_id, 0);
1165 header_cxx . . $ grn/dat/Trie#header_.->set_num_phantomscxx . . $ grn/dat/Header#set_num_phantoms(cb2f890c2fdad230).(num_phantomscxx . . $ grn/dat/Trie#num_phantoms(ddd8539a2fcdd4ce).() + BLOCK_SIZEcxx . . $ grn/dat/BLOCK_SIZE.);
1166 }
1167
1168 void Triecxx . . $ grn/dat/Trie#::update_block_levelcxx . . $ grn/dat/Trie#update_block_level(b4d55b1286ff73e8).(UInt32cxx . . $ grn/dat/UInt32# block_id, UInt32cxx . . $ grn/dat/UInt32# level) {
1169 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(block_id >= num_blocks());
1170 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(level > MAX_BLOCK_LEVEL);
1171
1172 unset_block_levelcxx . . $ grn/dat/Trie#unset_block_level(cb2f890c2fdad230).(block_id);
1173 set_block_levelcxx . . $ grn/dat/Trie#set_block_level(b4d55b1286ff73e8).(block_id, level);
1174 }
1175
1176 void Triecxx . . $ grn/dat/Trie#::set_block_levelcxx . . $ grn/dat/Trie#set_block_level(b4d55b1286ff73e8).(UInt32cxx . . $ grn/dat/UInt32# block_id, UInt32cxx . . $ grn/dat/UInt32# level) {
1177 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(block_id >= num_blocks());
1178 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(level > MAX_BLOCK_LEVEL);
1179
1180 const UInt32cxx . . $ grn/dat/UInt32# leader = header_cxx . . $ grn/dat/Trie#header_.->ith_leadercxx . . $ grn/dat/Header#ith_leader(560347b7e9428769).(level);
1181 if (leader == INVALID_LEADERcxx . . $ grn/dat/INVALID_LEADER.) {
1182 // The new block becomes the only one block of the linked list.
1183 ith_blockcxx . . $ grn/dat/Trie#ith_block(95549d8a1402ec44).(block_id).set_nextcxx . . $ grn/dat/Block#set_next(cb2f890c2fdad230).(block_id);
1184 ith_blockcxx . . $ grn/dat/Trie#ith_block(95549d8a1402ec44).(block_id).set_prevcxx . . $ grn/dat/Block#set_prev(cb2f890c2fdad230).(block_id);
1185 header_cxx . . $ grn/dat/Trie#header_.->set_ith_leadercxx . . $ grn/dat/Header#set_ith_leader(b4d55b1286ff73e8).(level, block_id);
1186 } else {
1187 // The new block is added to the end of the list.
1188 const UInt32cxx . . $ grn/dat/UInt32# next = leader;
1189 const UInt32cxx . . $ grn/dat/UInt32# prev = ith_blockcxx . . $ grn/dat/Trie#ith_block(95549d8a1402ec44).(leader).prevcxx . . $ grn/dat/Block#prev(ddd8539a2fcdd4ce).();
1190 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(next >= num_blocks());
1191 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(prev >= num_blocks());
1192 ith_blockcxx . . $ grn/dat/Trie#ith_block(95549d8a1402ec44).(block_id).set_nextcxx . . $ grn/dat/Block#set_next(cb2f890c2fdad230).(next);
1193 ith_blockcxx . . $ grn/dat/Trie#ith_block(95549d8a1402ec44).(block_id).set_prevcxx . . $ grn/dat/Block#set_prev(cb2f890c2fdad230).(prev);
1194 ith_blockcxx . . $ grn/dat/Trie#ith_block(95549d8a1402ec44).(next).set_prevcxx . . $ grn/dat/Block#set_prev(cb2f890c2fdad230).(block_id);
1195 ith_blockcxx . . $ grn/dat/Trie#ith_block(95549d8a1402ec44).(prev).set_nextcxx . . $ grn/dat/Block#set_next(cb2f890c2fdad230).(block_id);
1196 }
1197 ith_blockcxx . . $ grn/dat/Trie#ith_block(95549d8a1402ec44).(block_id).set_levelcxx . . $ grn/dat/Block#set_level(cb2f890c2fdad230).(level);
1198 ith_blockcxx . . $ grn/dat/Trie#ith_block(95549d8a1402ec44).(block_id).set_failure_countcxx . . $ grn/dat/Block#set_failure_count(cb2f890c2fdad230).(0);
1199 }
1200
1201 void Triecxx . . $ grn/dat/Trie#::unset_block_levelcxx . . $ grn/dat/Trie#unset_block_level(cb2f890c2fdad230).(UInt32cxx . . $ grn/dat/UInt32# block_id) {
1202 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(block_id >= num_blocks());
1203
1204 const UInt32cxx . . $ grn/dat/UInt32# level = ith_blockcxx . . $ grn/dat/Trie#ith_block(95549d8a1402ec44).(block_id).levelcxx . . $ grn/dat/Block#level(ddd8539a2fcdd4ce).();
1205 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(level > MAX_BLOCK_LEVEL);
1206
1207 const UInt32cxx . . $ grn/dat/UInt32# leader = header_cxx . . $ grn/dat/Trie#header_.->ith_leadercxx . . $ grn/dat/Header#ith_leader(560347b7e9428769).(level);
1208 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(leader == INVALID_LEADER);
1209
1210 const UInt32cxx . . $ grn/dat/UInt32# next = ith_blockcxx . . $ grn/dat/Trie#ith_block(95549d8a1402ec44).(block_id).nextcxx . . $ grn/dat/Block#next(ddd8539a2fcdd4ce).();
1211 const UInt32cxx . . $ grn/dat/UInt32# prev = ith_blockcxx . . $ grn/dat/Trie#ith_block(95549d8a1402ec44).(block_id).prevcxx . . $ grn/dat/Block#prev(ddd8539a2fcdd4ce).();
1212 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(next >= num_blocks());
1213 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(prev >= num_blocks());
1214
1215 if (next == block_id) {
1216 // The linked list becomes empty.
1217 header_cxx . . $ grn/dat/Trie#header_.->set_ith_leadercxx . . $ grn/dat/Header#set_ith_leader(b4d55b1286ff73e8).(level, INVALID_LEADERcxx . . $ grn/dat/INVALID_LEADER.);
1218 } else {
1219 ith_blockcxx . . $ grn/dat/Trie#ith_block(95549d8a1402ec44).(next).set_prevcxx . . $ grn/dat/Block#set_prev(cb2f890c2fdad230).(prev);
1220 ith_blockcxx . . $ grn/dat/Trie#ith_block(95549d8a1402ec44).(prev).set_nextcxx . . $ grn/dat/Block#set_next(cb2f890c2fdad230).(next);
1221 if (block_id == leader) {
1222 // The second block becomes the leader of the linked list.
1223 header_cxx . . $ grn/dat/Trie#header_.->set_ith_leadercxx . . $ grn/dat/Header#set_ith_leader(b4d55b1286ff73e8).(level, next);
1224 }
1225 }
1226 }
1227
1228 } // namespace dat
1229 } // namespace grn