Lines Matching refs:trie

37 struct trie {  struct
78 static int node_add_child(struct trie *trie, struct trie_node *node, struct trie_node *node_child, … in node_add_child() argument
87 trie->children_count++; in node_add_child()
92 trie->nodes_count++; in node_add_child()
119 static struct trie* trie_free(struct trie *trie) { in trie_free() argument
120 if (!trie) in trie_free()
123 trie_node_cleanup(trie->root); in trie_free()
124 strbuf_free(trie->strings); in trie_free()
125 return mfree(trie); in trie_free()
128 DEFINE_TRIVIAL_CLEANUP_FUNC(struct trie*, trie_free);
130 …values_cmp(const struct trie_value_entry *a, const struct trie_value_entry *b, struct trie *trie) { in trie_values_cmp() argument
131 return strcmp(trie->strings->buf + a->key_off, in trie_values_cmp()
132 trie->strings->buf + b->key_off); in trie_values_cmp()
135 static int trie_node_add_value(struct trie *trie, struct trie_node *node, in trie_node_add_value() argument
141 k = strbuf_add_string(trie->strings, key, strlen(key)); in trie_node_add_value()
144 v = strbuf_add_string(trie->strings, value, strlen(value)); in trie_node_add_value()
149 fn = strbuf_add_string(trie->strings, filename, strlen(filename)); 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()
176 trie->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()
223 s = strndup(trie->strings->buf + node->prefix_off, p); in trie_insert()
227 off = strbuf_add_string(trie->strings, s, p); 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()
257 off = strbuf_add_string(trie->strings, search + i+1, strlen(search + i+1)); in trie_insert()
265 r = node_add_child(trie, node, new_child, c); in trie_insert()
270 … return trie_node_add_value(trie, child, key, value, filename, file_priority, line_number, compat); in trie_insert()
279 struct trie *trie; member
288 static void trie_store_nodes_size(struct trie_f *trie, struct trie_node *node, bool compat) { in trie_store_nodes_size() argument
290 trie_store_nodes_size(trie, node->children[i].child, compat); in trie_store_nodes_size()
292 trie->strings_off += sizeof(struct trie_node_f); in trie_store_nodes_size()
294 trie->strings_off += sizeof(struct trie_child_entry_f); in trie_store_nodes_size()
296trie->strings_off += compat ? sizeof(struct trie_value_entry_f) : sizeof(struct trie_value_entry2_… 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()
318 child_off = trie_store_nodes(trie, node->children[i].child, compat); in trie_store_nodes()
329 node_off = ftello(trie->f); in trie_store_nodes()
330 fwrite(&n, sizeof(struct trie_node_f), 1, trie->f); in trie_store_nodes()
331 trie->nodes_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()
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()
349 …e(&v, compat ? sizeof(struct trie_value_entry_f) : sizeof(struct trie_value_entry2_f), 1, trie->f); in trie_store_nodes()
351 trie->values_count += node->values_count; in trie_store_nodes()
356 static int trie_store(struct trie *trie, const char *filename, bool compat) { in trie_store() argument
358 .trie = trie, in trie_store()
376 trie_store_nodes_size(&t, trie->root, compat); in trie_store()
387 root_off = trie_store_nodes(&t, trie->root, compat); in trie_store()
393 fwrite(trie->strings->buf, trie->strings->len, 1, t.f); in trie_store()
394 h.strings_len = htole64(trie->strings->len); in trie_store()
424 log_debug("string store: %8zu bytes", trie->strings->len); in trie_store()
435 static int insert_data(struct trie *trie, char **match_list, char *line, const char *filename, in insert_data() argument
459 … trie_insert(trie, trie->root, *entry, line, value, filename, file_priority, line_number, compat); in insert_data()
464 static int import_file(struct trie *trie, const char *filename, uint16_t file_priority, bool compat… in import_file() argument
547 … err = insert_data(trie, match_list, line, filename, file_priority, line_number, compat); in import_file()
568 … err = insert_data(trie, match_list, line, filename, file_priority, line_number, compat); in import_file()
584 _cleanup_(trie_freep) struct trie *trie = NULL; in hwdb_update() local
594 trie = new0(struct trie, 1); in hwdb_update()
595 if (!trie) in hwdb_update()
599 trie->strings = strbuf_new(); in hwdb_update()
600 if (!trie->strings) in hwdb_update()
604 trie->root = new0(struct trie_node, 1); in hwdb_update()
605 if (!trie->root) in hwdb_update()
608 trie->nodes_count++; in hwdb_update()
616 err = import_file(trie, *f, file_priority++, compat); in hwdb_update()
621 strbuf_complete(trie->strings); in hwdb_update()
625 trie->nodes_count * sizeof(struct trie_node), trie->nodes_count); in hwdb_update()
627 trie->children_count * sizeof(struct trie_child_entry), trie->children_count); in hwdb_update()
629 trie->values_count * sizeof(struct trie_value_entry), trie->values_count); in hwdb_update()
631 trie->strings->len); in hwdb_update()
633 trie->strings->in_len, trie->strings->in_count); in hwdb_update()
635 trie->strings->dedup_len, trie->strings->dedup_count); in hwdb_update()
642 err = trie_store(trie, hwdb_bin, compat); in hwdb_update()