chiark / gitweb /
shared: strbuf - add description
authorKay Sievers <kay@vrfy.org>
Mon, 22 Oct 2012 14:54:14 +0000 (16:54 +0200)
committerKay Sievers <kay@vrfy.org>
Mon, 22 Oct 2012 14:57:49 +0000 (16:57 +0200)
src/shared/strbuf.c

index 5c858cb68e1832e354bec226d12a43b137338383..9314f097ab5950091eb0977b87106883c828bd43 100644 (file)
 #include "util.h"
 #include "strbuf.h"
 
 #include "util.h"
 #include "strbuf.h"
 
+/*
+ * Strbuf stores given strings in a single continous allocated memory
+ * area. Identical strings are de-duplicated. If the tail of a string
+ * already exist in the buffer, the tail is returned.
+ *
+ * A Particia Trie is used to maintain the information about the stored
+ * strings.
+ *
+ * Example of udev rules:
+ *   $ ./udevadm test .
+ *   ...
+ *   read rules file: /usr/lib/udev/rules.d/99-systemd.rules
+ *   rules contain 196608 bytes tokens (16384 * 12 bytes), 39742 bytes strings
+ *   23939 strings (207859 bytes), 20404 de-duplicated (171653 bytes), 3536 trie nodes used
+ *   ...
+ */
+
 struct strbuf *strbuf_new(void) {
         struct strbuf *str;
 
 struct strbuf *strbuf_new(void) {
         struct strbuf *str;
 
@@ -58,6 +75,7 @@ static void strbuf_node_cleanup(struct strbuf_node *node) {
         free(node);
 }
 
         free(node);
 }
 
+/* clean up trie data, leave only the string buffer */
 void strbuf_complete(struct strbuf *str) {
         if (!str)
                 return;
 void strbuf_complete(struct strbuf *str) {
         if (!str)
                 return;
@@ -66,6 +84,7 @@ void strbuf_complete(struct strbuf *str) {
         str->root = NULL;
 }
 
         str->root = NULL;
 }
 
+/* clean up everything */
 void strbuf_cleanup(struct strbuf *str) {
         if (!str)
                 return;
 void strbuf_cleanup(struct strbuf *str) {
         if (!str)
                 return;
@@ -82,6 +101,7 @@ static int strbuf_children_cmp(const void *v1, const void *v2) {
         return n1->c - n2->c;
 }
 
         return n1->c - n2->c;
 }
 
+/* add string, return the index/offset into the buffer */
 ssize_t strbuf_add_string(struct strbuf *str, const char *s, size_t len) {
         uint8_t c;
         struct strbuf_node *node;
 ssize_t strbuf_add_string(struct strbuf *str, const char *s, size_t len) {
         uint8_t c;
         struct strbuf_node *node;