#ifndef HASHTABLE_H #define HASHTABLE_H #include #include #include "vars.h" #ifdef __KERNEL_V_2_4__ #include #endif #define TABLE_NAMESIZE 20 /* A static array of these is allocated to create addressable buckets */ typedef struct Bucket { list_head bucket; list_head * curr; ulong count; } Bucket; #define BSIZE sizeof(Bucket) /* Meta-data of the hashtable */ typedef struct HashTable { ulong (*hash)(void *); bool (*equal)(void *, void *); char slab_name[TABLE_NAMESIZE]; ulong count, hash_size, //number of buckets bits, //number of bucket pages in power of 2 ibits, //number of buckets in power of 2 curr; Bucket *table; kmem_cache_t *entries; } HashTable; /* Each bucket contains a linked-list of these entry structures */ typedef struct Entry { list_head mapping; void * key; void * data; ulong curr; } Entry; /* Prototypes */ int init_table(HashTable *, int *, ulong (*hash) (void *), bool (*equal) (void *, void *), char *); void clean_table(HashTable *); void insert_table(HashTable *, void *, void *); void * remove_table(HashTable *, void *); void * remove_current_in_table(HashTable *); void * get_key_at_current(HashTable *); void * lookup_table(HashTable *, void *); void dump_table(HashTable *); void * next_in_table(HashTable *); void rewind_table(HashTable *); #endif