Add lladdend function and use in makewordlist.
authorJonathan McDowell <noodles@earth.li>
Thu, 21 Oct 2004 14:47:44 +0000 (14:47 +0000)
committerJonathan McDowell <noodles@earth.li>
Thu, 21 Oct 2004 14:47:44 +0000 (14:47 +0000)
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.

ll.c
ll.h
wordlist.c

diff --git a/ll.c b/ll.c
index 3545a9c48232221a7ea9ffedfa7b69f3dd98de83..018ea0d72ccdc19fee6877357d3741282e6fa01e 100644 (file)
--- 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 d4152cce04e2903bdc877d3684bd0af7a9935636..464f99b0553eaf23c8f112af4ffd20feb2fb084e 100644 (file)
--- 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.
index 71299e12c88fd3e811965bbd337ba8c9ad07fd5b..0c2cb62c8154b22540ce749a940493fcc4c3d572 100644 (file)
@@ -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);
                        }
                }
        }