On Mon, Mar 05, 2007 at 09:56:43AM -0600, Aaron Griffin wrote:
On 3/5/07, Jürgen Hötzel <juergen@hoetzel.info> wrote:
Circular lists are different. There is NO end of the list. consider alpm_list_find: it will loop forever ;) pacmans implementation expects "non-circular" lists everywhere. Just an example:
for(lp = info->files; lp; lp = lp->next) { fprintf(fp, "%s\n", (char *)lp->data); }
True. Using circular lists would cause a bit of a problem here. The only problem with the ->last implementation is that it's a mostly NULL pointer. Generally, if something is NULL for an entire list, except for one node, there's probably a better way to do it. For instance, if we go with the fairly typical: struct list_node { struct list_node *next, *prev; void *data; }; struct list { struct list_node *head, *tail; };
Yes, "struct list" is like the sentinel node i proposed in my previous post. I'm quite impressed by the simple and elegant "Linux Kernel Linked Lists" (http://isis.poly.edu/kulesh/stuff/src/klist/ proposed by Dan) and currently merge them with ALPM's code into a new implementation using sentinel nodes. I will post details soon. Jürgen