#include <stdlib.h>
#include <stdio.h>
+#define INLINE inline __attribute__((always_inline))
+//#define INLINE
-#define CLOADFACTOR 0.25
-#define CHASH_SIZE 1024
-
-typedef struct chashlistnode {
- unsigned int key;
+typedef struct cnode {
+ void * key;
void *val; //this can be cast to another type or used to point to a larger structure
- struct chashlistnode *next;
-} chashlistnode_t;
+ struct cnode *next;
+ struct cnode *lnext;
+} cnode_t;
-typedef struct chashtable {
- chashlistnode_t *table; // points to beginning of hash table
+typedef struct ctable {
+ cnode_t *table; // points to beginning of hash table
unsigned int size;
unsigned int mask;
unsigned int numelements;
+ unsigned int resize;
float loadfactor;
-} chashtable_t;
+ struct cnode *listhead;
+} ctable_t;
/* Prototypes for hash*/
-chashtable_t *chashCreate(unsigned int size, float loadfactor);
-static unsigned int chashFunction(chashtable_t *table, unsigned int key);
-unsigned int chashInsert(chashtable_t *table, unsigned int key, void *val);
-void *chashSearch(chashtable_t *table, unsigned int key); //returns val, NULL if not found
-unsigned int chashRemove(chashtable_t *table, unsigned int key); //returns -1 if not found
-unsigned int chashResize(chashtable_t *table, unsigned int newsize);
-void chashDelete(chashtable_t *table);
+ctable_t *cCreate(unsigned int size, float loadfactor);
+void cInsert(ctable_t *table, void * key, void * val);
+void * cSearch(ctable_t *table, void * key); //returns val, NULL if not found
+unsigned int cRemove(ctable_t *table, void * key); //returns -1 if not found
+unsigned int cResize(ctable_t *table, unsigned int newsize);
+void cDelete(ctable_t *table);
+void crehash(ctable_t *table);
/* end hash */
#endif