1 /* SPDX-License-Identifier: LGPL-2.1-or-later */ 2 #pragma once 3 4 #include <stddef.h> 5 #include <stdint.h> 6 #include <sys/types.h> 7 8 #include "macro.h" 9 10 struct strbuf { 11 char *buf; 12 size_t len; 13 struct strbuf_node *root; 14 15 size_t nodes_count; 16 size_t in_count; 17 size_t in_len; 18 size_t dedup_len; 19 size_t dedup_count; 20 }; 21 22 struct strbuf_node { 23 size_t value_off; 24 size_t value_len; 25 26 struct strbuf_child_entry *children; 27 uint8_t children_count; 28 }; 29 30 struct strbuf_child_entry { 31 uint8_t c; 32 struct strbuf_node *child; 33 }; 34 35 struct strbuf* strbuf_new(void); 36 ssize_t strbuf_add_string(struct strbuf *str, const char *s, size_t len); 37 void strbuf_complete(struct strbuf *str); 38 struct strbuf* strbuf_free(struct strbuf *str); 39 DEFINE_TRIVIAL_CLEANUP_FUNC(struct strbuf*, strbuf_free); 40