summaryrefslogtreecommitdiff
path: root/example.c
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 /example.c
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 'example.c')
-rw-r--r--example.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/example.c b/example.c
index 919d75c..fa98098 100644
--- a/example.c
+++ b/example.c
@@ -7,18 +7,23 @@ int main(int argc,char *argv[]) {
struct hashtable ht;
int i;
char *name;
+ char *tmp;
char *value;
- inittable(&ht,65535);
+ inittable(&ht,1000);
for(i=0;environ[i];i++) {
name=strdup(environ[i]);
- if((value=strchr(name,'=') )){
- *value=0;
- value++;
+ if((tmp=strchr(name,'=') )){
+ *tmp=0;
+ tmp++;
}
+ value=strdup(tmp);
ht_setkey(&ht,name,value);
free(name);
}
- printf("PATH='%s'\n",ht_getvalue(&ht,"PATH"));
+ printf("ht.size: %u\n",ht.size);
+ printf("before: PATH='%s'\n",ht_getvalue(&ht,"PATH"));
+ ht_delete(&ht,"PATH");
+ printf("after: PATH='%s'\n",ht_getvalue(&ht,"PATH"));
//if you want to get a whole entry struct use ht_getnode();
//getentry() just returns the first struct in the linked list in that bucket.
return 0;