summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/str_table.h27
1 files changed, 18 insertions, 9 deletions
diff --git a/include/str_table.h b/include/str_table.h
index 7ae050e..206fa3a 100644
--- a/include/str_table.h
+++ b/include/str_table.h
@@ -8,28 +8,37 @@
#define STR_TABLE_H
#include "sqfs/predef.h"
+#include "array.h"
+#include "hash_table.h"
-typedef struct str_bucket_t {
- struct str_bucket_t *next;
- char *str;
+typedef struct {
size_t index;
size_t refcount;
+ char string[];
} str_bucket_t;
/* Stores strings in a hash table and assigns an incremental, unique ID to
each string. Subsequent additions return the existing ID. The ID can be
used for (hopefully) constant time lookup of the original string. */
typedef struct {
- str_bucket_t **buckets;
- size_t num_buckets;
+ /* an array that resolves index to bucket pointer */
+ array_t bucket_ptrs;
+
+ /* hash table with the string buckets attached */
+ struct hash_table *ht;
- char **strings;
- size_t num_strings;
- size_t max_strings;
+ /* the next ID we are going to allocate */
+ size_t next_index;
} str_table_t;
+/* the number of strings currently stored in the table */
+static SQFS_INLINE size_t str_table_count(const str_table_t *table)
+{
+ return table->next_index;
+}
+
/* `size` is the number of hash table buckets to use internally. */
-SQFS_INTERNAL int str_table_init(str_table_t *table, size_t size);
+SQFS_INTERNAL int str_table_init(str_table_t *table);
SQFS_INTERNAL void str_table_cleanup(str_table_t *table);