Lines Matching refs:node

78 static int node_add_child(struct trie *trie, struct trie_node *node, struct trie_node *node_child, …  in node_add_child()  argument
82 … child = reallocarray(node->children, node->children_count + 1, sizeof(struct trie_child_entry)); in node_add_child()
86 node->children = child; in node_add_child()
88 node->children[node->children_count].c = c; in node_add_child()
89 node->children[node->children_count].child = node_child; in node_add_child()
90 node->children_count++; in node_add_child()
91 typesafe_qsort(node->children, node->children_count, trie_children_cmp); in node_add_child()
97 static struct trie_node *node_lookup(const struct trie_node *node, uint8_t c) { in node_lookup() argument
102 child = typesafe_bsearch(&search, node->children, node->children_count, trie_children_cmp); in node_lookup()
108 static void trie_node_cleanup(struct trie_node *node) { in trie_node_cleanup() argument
109 if (!node) in trie_node_cleanup()
112 for (size_t i = 0; i < node->children_count; i++) in trie_node_cleanup()
113 trie_node_cleanup(node->children[i].child); in trie_node_cleanup()
114 free(node->children); in trie_node_cleanup()
115 free(node->values); in trie_node_cleanup()
116 free(node); in trie_node_cleanup()
135 static int trie_node_add_value(struct trie *trie, struct trie_node *node, in trie_node_add_value() argument
154 if (node->values_count) { in trie_node_add_value()
160 … val = typesafe_bsearch_r(&search, node->values, node->values_count, trie_values_cmp, trie); in trie_node_add_value()
173 val = reallocarray(node->values, node->values_count + 1, sizeof(struct trie_value_entry)); in trie_node_add_value()
177 node->values = val; in trie_node_add_value()
178 node->values[node->values_count] = (struct trie_value_entry) { in trie_node_add_value()
185 node->values_count++; in trie_node_add_value()
186 typesafe_qsort_r(node->values, node->values_count, trie_values_cmp, trie); in trie_node_add_value()
190 static int trie_insert(struct trie *trie, struct trie_node *node, const char *search, in trie_insert() argument
200 for (p = 0; (c = trie->strings->buf[node->prefix_off + p]); p++) { in trie_insert()
215 .prefix_off = node->prefix_off + p+1, in trie_insert()
216 .children = node->children, in trie_insert()
217 .children_count = node->children_count, in trie_insert()
218 .values = node->values, in trie_insert()
219 .values_count = node->values_count, in trie_insert()
223 s = strndup(trie->strings->buf + node->prefix_off, p); in trie_insert()
231 *node = (struct trie_node) { in trie_insert()
234 r = node_add_child(trie, node, new_child, c); in trie_insert()
245 … return trie_node_add_value(trie, node, key, value, filename, file_priority, line_number, compat); in trie_insert()
247 child = node_lookup(node, c); in trie_insert()
265 r = node_add_child(trie, node, new_child, c); in trie_insert()
273 node = child; in trie_insert()
288 static void trie_store_nodes_size(struct trie_f *trie, struct trie_node *node, bool compat) { in trie_store_nodes_size() argument
289 for (uint64_t i = 0; i < node->children_count; i++) in trie_store_nodes_size()
290 trie_store_nodes_size(trie, node->children[i].child, compat); in trie_store_nodes_size()
293 for (uint64_t i = 0; i < node->children_count; i++) in trie_store_nodes_size()
295 for (uint64_t i = 0; i < node->values_count; i++) in trie_store_nodes_size()
299 static int64_t trie_store_nodes(struct trie_f *trie, struct trie_node *node, bool compat) { in trie_store_nodes() argument
301 .prefix_off = htole64(trie->strings_off + node->prefix_off), in trie_store_nodes()
302 .children_count = node->children_count, in trie_store_nodes()
303 .values_count = htole64(node->values_count), in trie_store_nodes()
308 if (node->children_count) { in trie_store_nodes()
309 children = new(struct trie_child_entry_f, node->children_count); in trie_store_nodes()
315 for (uint64_t i = 0; i < node->children_count; i++) { in trie_store_nodes()
318 child_off = trie_store_nodes(trie, node->children[i].child, compat); in trie_store_nodes()
323 .c = node->children[i].c, in trie_store_nodes()
334 if (node->children_count) { in trie_store_nodes()
335 fwrite(children, sizeof(struct trie_child_entry_f), node->children_count, trie->f); in trie_store_nodes()
336 trie->children_count += node->children_count; in trie_store_nodes()
340 for (uint64_t i = 0; i < node->values_count; i++) { in trie_store_nodes()
342 .key_off = htole64(trie->strings_off + node->values[i].key_off), in trie_store_nodes()
343 .value_off = htole64(trie->strings_off + node->values[i].value_off), in trie_store_nodes()
344 .filename_off = htole64(trie->strings_off + node->values[i].filename_off), in trie_store_nodes()
345 .line_number = htole32(node->values[i].line_number), in trie_store_nodes()
346 .file_priority = htole16(node->values[i].file_priority), in trie_store_nodes()
351 trie->values_count += node->values_count; in trie_store_nodes()