};
typedef struct {
- int nelem, curnelem;
+ unsigned dupes : 1;
+ int nelem;
+ int curnelem;
struct hash_elem **table;
-} HASH;
+} hash_t;
-#define hash_find(table, key) \
- hash_find_hash(table, hash_string((unsigned char *)key, table->nelem), key)
+hash_t *hash_init(hash_t *, int nelem, int allow_dup);
+static inline hash_t *hash_new(int nelem, int allow_dup) {
+ return hash_init(p_new(hash_t, 1), nelem, allow_dup);
+}
-#define hash_delete(table,key,data,destroy) \
- hash_delete_hash(table, hash_string((unsigned char *)key, table->nelem), key, data, destroy)
+void hash_wipe(hash_t*, void (*dtor)(void*));
+static inline void hash_delete(hash_t **h, void (*dtor)(void*)) {
+ if (*h) {
+ hash_wipe(*h, dtor);
+ p_delete(h);
+ }
+}
-HASH *hash_create(int nelem);
int hash_string(const unsigned char *s, int n);
-int hash_insert(HASH *table, const char *key, void *data, int allow_dup);
-HASH *hash_resize(HASH *table, int nelem);
-void *hash_find_hash(const HASH *table, int hash, const char *key);
-void hash_delete_hash(HASH *table, int hash, const char *key,
- const void *data, void (*destroy)(void *));
-void hash_destroy(HASH **hash, void (*destroy)(void *));
-
-void hash_map(HASH *table,
+void hash_resize(hash_t *table, int nelem);
+
+int hash_insert(hash_t *table, const char *key, void *data);
+void *hash_find(const hash_t *table, const char *key);
+void hash_remove(hash_t *table, const char *key, const void *data,
+ void (*destroy)(void *));
+
+void hash_map(hash_t *table,
void (*mapfunc)(const char *key, void *data, unsigned long more),
unsigned long more);