+
+/*
+ * A tiny size_t key-value hashtbale for tracking vector and hashtable
+ * sizes. We can use it for other things too, if we need to. This is
+ * very TIGHT, and efficent in terms of space though.
+ */
+static stat_size_table_t stat_size_new() {
+ return (stat_size_table_t)memset(
+ mem_a(sizeof(stat_size_entry_t*) * ST_SIZE),
+ 0, ST_SIZE * sizeof(stat_size_entry_t*)
+ );
+}
+
+static void stat_size_del(stat_size_table_t table) {
+ size_t i = 0;
+ for (; i < ST_SIZE; i++) if(table[i]) mem_d(table[i]);
+ mem_d(table);
+}
+
+static stat_size_entry_t *stat_size_get(stat_size_table_t table, size_t key) {
+ size_t hash = (key % ST_SIZE);
+ while (table[hash] && table[hash]->key != key)
+ hash = (hash + 1) % ST_SIZE;
+ return table[hash];
+}
+static void stat_size_put(stat_size_table_t table, size_t key, size_t value) {
+ size_t hash = (key % ST_SIZE);
+ while (table[hash] && table[hash]->key != key)
+ hash = (hash + 1) % ST_SIZE;
+ table[hash] = (stat_size_entry_t*)mem_a(sizeof(stat_size_entry_t));
+ table[hash]->key = key;
+ table[hash]->value = value;
+}
+