summaryrefslogtreecommitdiff
path: root/hashtable.h
diff options
context:
space:
mode:
authorepochqwert <epoch@hacking.allowed.org>2015-05-13 06:29:43 -0500
committerepochqwert <epoch@hacking.allowed.org>2015-05-13 06:29:43 -0500
commita91d1a2b3cd7b3b65ba86ac1f5a94d3e806a109c (patch)
tree3f27529df301739044d7d1adb90ea524b4e49192 /hashtable.h
parent8a679c4ce561110321504d6149888e8868a1b249 (diff)
downloadlibhashtable-a91d1a2b3cd7b3b65ba86ac1f5a94d3e806a109c.tar.gz
libhashtable-a91d1a2b3cd7b3b65ba86ac1f5a94d3e806a109c.zip
fixed some really stupid stuff.
ll_getentry wasn't comparing key and stored key right. ht_delete wasn't deleting stuff if it was the last in the bucket. the hash got upgraded to one I took from wikipedia. the hash is now 32 bit unsigned and is modulo table-size.
Diffstat (limited to 'hashtable.h')
-rw-r--r--hashtable.h15
1 files changed, 9 insertions, 6 deletions
diff --git a/hashtable.h b/hashtable.h
index 60d1b50..0d6112b 100644
--- a/hashtable.h
+++ b/hashtable.h
@@ -1,7 +1,7 @@
-struct entry {//linked list node.
+struct entry {
char *original;
void *target;
- struct entry *prev;// doubly linked list. why?
+ struct entry *prev;
struct entry *next;
};
@@ -10,12 +10,14 @@ struct hitem {
};
struct hashtable {
- int kl;//number of keys in the table
+ unsigned int kl;
+ unsigned int size;
struct hitem **bucket;
- int *keys;
+ unsigned int *keys;
};
-unsigned short hash(char *key);//maybe use a seeded rand()? :) Thanks FreeArtMan
-void inittable(struct hashtable *ht,int tsize);
+unsigned int murmur3_32(const char *key, unsigned int len, unsigned int seed);
+unsigned int hash(char *key);
+void inittable(struct hashtable *ht,unsigned int tsize);
void ll_delete(struct entry *ll);
void ll_destroy(struct entry *ll);
void ht_destroy(struct hashtable *ht);
@@ -25,4 +27,5 @@ struct entry *ll_getentry(struct entry *start,char *key);
struct entry *ht_getentry(struct hashtable *ht,char *key);
struct entry *ht_getnode(struct hashtable *ht,char *key);
void *ht_getvalue(struct hashtable *ht,char *key);
+struct hitem *ht_getbucket(struct hashtable *ht,char *key);
void ht_delete(struct hashtable *ht,char *key);