27 lines
622 B
C
27 lines
622 B
C
#pragma once
|
|
#include <stdint.h>
|
|
#include <stddef.h>
|
|
#include "list.h"
|
|
|
|
struct hash_pair {
|
|
void *key, *value;
|
|
struct list_head link;
|
|
};
|
|
|
|
#define HASH_DEBUG
|
|
|
|
struct hash {
|
|
size_t (*hash) (const void *);
|
|
struct hash_pair *(*pair_new) (void *, void *);
|
|
void (*pair_free) (struct hash_pair *);
|
|
int (*keycmp) (const void *, const void *);
|
|
|
|
size_t bucket_count;
|
|
struct list_head *buckets;
|
|
};
|
|
|
|
int shash_init(struct hash *h, size_t cap);
|
|
void hash_free(struct hash *h);
|
|
int hash_insert(struct hash *h, const void *key, void *value);
|
|
struct hash_pair *hash_lookup(struct hash *h, const void *key);
|