From: Jonathan McDowell Date: Thu, 21 Oct 2004 14:47:44 +0000 (+0000) Subject: Add lladdend function and use in makewordlist. X-Git-Url: https://git.sommitrealweird.co.uk/onak.git/commitdiff_plain/01c34102a1d2f1aefaa1bf3c4fb95ba46c46b551 Add lladdend function and use in makewordlist. Add a new function that adds an object to the end of a linked list. We make use of this in makewordlist, which means we search for keys containing words from the start of the email address first, rather than starting with the words at the end. When you're dealing with TLDs like com, net, org this makes a big difference, as you don't end up with a huge list from the first word you try. --- diff --git a/ll.c b/ll.c index 3545a9c..018ea0d 100644 --- a/ll.c +++ b/ll.c @@ -28,6 +28,33 @@ struct ll *lladd(struct ll *curll, void *object) return new; } +struct ll *lladdend(struct ll *curll, void *object) +{ + struct ll *new; + struct ll *cur; + + if ((new = malloc(sizeof(struct ll))) == NULL) { + logthing(LOGTHING_ERROR, + "Couldn't allocate memory in lladdend()"); + return NULL; + } + + new->next = NULL; + new->object = object; + + if (curll != NULL) { + cur = curll; + while (cur->next != NULL) { + cur = cur->next; + } + cur->next = new; + } else { + curll = new; + } + + return curll; +} + struct ll *lldel(struct ll *curll, void *object, int (*objectcmp) (const void *object1, const void *object2)) { diff --git a/ll.h b/ll.h index d4152cc..464f99b 100644 --- a/ll.h +++ b/ll.h @@ -49,6 +49,15 @@ struct ll { */ struct ll *lladd(struct ll *curll, void *object); +/** + * lladdend - Add an item to the end of a linked list. + * @curll: The list to add to. Can be NULL to create a new list. + * @object: The object to add. + * + * Returns a pointer to the head of the new list. + */ +struct ll *lladdend(struct ll *curll, void *object); + /** * lldel - Remove an item from a linked list. * @curll: The list to remove the item from. diff --git a/wordlist.c b/wordlist.c index 71299e1..0c2cb62 100644 --- a/wordlist.c +++ b/wordlist.c @@ -57,7 +57,7 @@ struct ll *makewordlist(struct ll *wordlist, char *word) if (llfind(wordlist, start, (int (*)(const void *, const void *)) strcmp ) == NULL) { - wordlist = lladd(wordlist, start); + wordlist = lladdend(wordlist, start); } } }