#pragma once #include #include // The data field is a compact representation of a // [(string, struct tree_node*)] list. The strings are all non-empty. // Representation: for every list element, first a null-terminated sequence of // chars (the string), then sizeof(void*) bytes (the pointer, potentially // NULL). After the last list element, an additional 0 byte, which could be // interpreted as an empty string, but instead means the end of the list. struct tree_node { size_t total_files; size_t total_dirs; size_t total_size; // sum of on-disk sizes (in bytes) uint8_t *data; }; // A single element in a child list. struct tree_pair { const char *name; // ownership is retained by the producer of this tree_pair struct tree_node *sub; // can be NULL }; // The names are copied out of 'pairs'. struct tree_node* tree_make(const struct tree_pair *pairs, size_t npairs, size_t disk_size); // Frees recursively. void tree_free(struct tree_node *node); size_t tree_num_children(const struct tree_node *node); struct tree_pair tree_index(struct tree_node *node, size_t index); struct tree_iter { struct tree_node *node; size_t off; }; struct tree_iter tree_iter_start(struct tree_node *node); // Returns whether there was another child bool tree_iter_next(struct tree_iter *iter, struct tree_pair *dst);