summaryrefslogtreecommitdiff
path: root/include/str_table.h
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2021-03-07 01:14:13 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2021-03-07 01:18:03 +0100
commit257a5737d708b706be29526050f61ded9793d0ab (patch)
treeb7b5789e63a85187c0cbffb965c9c7233bb26249 /include/str_table.h
parent5cc1d55d769e278f51eeb057b08d04afd6bb0c44 (diff)
Rewrite the str_table to internally use the more opimized hash_table
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'include/str_table.h')
-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);