[pacman-dev] alpm_list: missing quick access to last element

Jürgen Hötzel juergen at hoetzel.info
Mon Mar 5 14:02:10 EST 2007


On Mon, Mar 05, 2007 at 09:56:43AM -0600, Aaron Griffin wrote:
> On 3/5/07, Jürgen Hötzel <juergen at 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://archlinux.org/pipermail/pacman-dev/attachments/20070305/3d96224a/attachment.pgp>


More information about the pacman-dev mailing list