From f8fcbc7648da8da67426d8ce738cdfbe6b70f0fd Mon Sep 17 00:00:00 2001 From: erubow Date: Thu, 1 Mar 2007 18:52:34 +0000 Subject: [PATCH] generic hashtable interface --- Robust/src/Runtime/DSTM/interface/hashtable.h | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Robust/src/Runtime/DSTM/interface/hashtable.h diff --git a/Robust/src/Runtime/DSTM/interface/hashtable.h b/Robust/src/Runtime/DSTM/interface/hashtable.h new file mode 100644 index 00000000..54940542 --- /dev/null +++ b/Robust/src/Runtime/DSTM/interface/hashtable.h @@ -0,0 +1,30 @@ +#ifndef _HASHTABLE_H_ +#define _HASHTABLE_H_ + +#define LOADFACTOR 0.75 +#define HASH_SIZE 100 + +typedef struct hashlistnode { + unsigned int key; + void *val; //this can be cast to another type or used to point to a larger structure + struct hashlistnode *next; +} hashlistnode_t; + +typedef struct hashtable { + hashlistnode_t *table; // points to beginning of hash table + unsigned int size; + unsigned int numelements; + float loadfactor; +} hashtable_t; + +/* Prototypes for hash*/ +hashtable_t *hashCreate(unsigned int size, float loadfactor); +unsigned int hashFunction(hashtable_t *table, unsigned int key); +void hashInsert(hashtable_t *table, unsigned int key, void *val); +void *hashSearch(hashtable_t *table, unsigned int key); //returns val, NULL if not found +int hashRemove(hashtable_t *table, unsigned int key); //returns -1 if not found +void hashResize(hashtable_t *table, unsigned int newsize); +/* end hash */ + +#endif + -- 2.34.1