From 7f43ddc3b96848b1a788a86ae663279dead86f27 Mon Sep 17 00:00:00 2001 From: epochqwert Date: Sat, 28 Mar 2015 00:16:57 -0500 Subject: added a function to deleted an individual key:value in libhashtable added a function that does line cutting to libirc (and its prototype in the header) made segfault take advantage of the new cutting function. --- libhashtable/libhashtable.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'libhashtable') diff --git a/libhashtable/libhashtable.c b/libhashtable/libhashtable.c index 02b981e..496a3ee 100644 --- a/libhashtable/libhashtable.c +++ b/libhashtable/libhashtable.c @@ -129,32 +129,37 @@ int ht_setkey(struct hashtable *ht,char *key,void *value) { return 0; } -struct entry *ll_getentry(struct entry *start,char *msg) { +struct entry *ll_getentry(struct entry *start,char *key) { struct entry *m; - if(!msg) return NULL; + if(!key) return NULL; if(!start) return NULL; for(m=start;m;m=m->next) { - if(!strncmp(msg,m->original,strlen(m->original)) && (msg[strlen(m->original)]==' ' || msg[strlen(m->original)] == 0)) {//this allows !c to get called when using !c2 if !c2 is defined after !c. >_> + if(!strncmp(key,m->original,strlen(m->original)) && (key[strlen(m->original)]==' ' || key[strlen(m->original)] == 0)) {//this allows !c to get called when using !c2 if !c2 is defined after !c. >_> return m; } } return NULL; } -//returns the linked list at the key. +//returns the table entry (a linked list) at the key. struct entry *ht_getentry(struct hashtable *ht,char *key) { unsigned short h=hash(key); if(!ht->bucket[h]) return NULL; return ht->bucket[h]->ll; } -//returns the node -struct entry *ht_getnode(struct hashtable *ht,char *msg) { - return ll_getentry(ht_getentry(ht,msg),msg); +//returns the node in the linked list in the table entry that matches the key. +struct entry *ht_getnode(struct hashtable *ht,char *key) { + return ll_getentry(ht_getentry(ht,key),key); } //you'll probably want to use me. -void *ht_getvalue(struct hashtable *ht,char *msg) { - struct entry *tmp=ll_getentry(ht_getentry(ht,msg),msg); +void *ht_getvalue(struct hashtable *ht,char *key) { + struct entry *tmp=ll_getentry(ht_getentry(ht,key),key); return tmp?tmp->target:0; } + +//delete the node in the linked list in the table entry that matches the key. +void *ht_delete(struct hashtable *ht,char *key) { + ll_delete(ht_getentry(ht,key)); +} -- cgit v1.2.3