diff options
author | epochqwert <epoch@53flpnlls43fcguy.onion> | 2015-03-28 00:16:57 -0500 |
---|---|---|
committer | epochqwert <epoch@53flpnlls43fcguy.onion> | 2015-03-28 00:16:57 -0500 |
commit | 7f43ddc3b96848b1a788a86ae663279dead86f27 (patch) | |
tree | e5eff4a1146267325451959741546ff7f6d74df6 /libhashtable | |
parent | 9429905cb75e36107df9c0b44a3dd9293520f4f2 (diff) | |
download | segfault-7f43ddc3b96848b1a788a86ae663279dead86f27.tar.gz segfault-7f43ddc3b96848b1a788a86ae663279dead86f27.zip |
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.
Diffstat (limited to 'libhashtable')
-rw-r--r-- | libhashtable/libhashtable.c | 23 |
1 files changed, 14 insertions, 9 deletions
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)); +} |