[ccan] [PATCH 1/4] queue: Simple queue implementation

David Gibson david at gibson.dropbear.id.au
Wed Jul 9 20:58:22 EST 2014


On Tue, Jul 08, 2014 at 07:34:57PM +1000, Sam Watkins wrote:
> On Mon, Jul 07, 2014 at 11:13:58PM -0400, Cody P Schafer wrote:
> > On Mon, Jul 7, 2014 at 8:51 AM, David Gibson
> > <david at gibson.dropbear.id.au> wrote:
> > > This new module provides a simple queue implementation as a singly linked
> > > (circular) list.
> > >
> > > Signed-off-by: David Gibson <david at gibson.dropbear.id.au>
> > 
> > I've been looking for a singly-linked list for places where I don't
> > necessarily need a doubly linked one (as provided by ccan/list).
> > 
> > Would it be possible to format the api for this singly-linked list
> > more like the current list.h api?
> 
> here is an idea for generic singly-linked lists and other data
> structures, put the link at the start of the structure instead of at the
> end, then you can do generic operations on it without having to know
> what kind of element it has.
> 
> e.g.
> 
> struct car {
> 	struct car *next;
> 	char *rego;
> 	char *make;
> 	char *model;
> }
> 
> I rarely saw that, but I think it's a good idea.

Has a few problems.  First, it's no good if you need your elements to
live in multiple lists.  Second, depending on the details it can be
really risky - if someone moves the list element not realising the
constraint, will you be able to detect this and give a useful error?

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.ozlabs.org/pipermail/ccan/attachments/20140709/8ee3b290/attachment.sig>


More information about the ccan mailing list