[ccan] Question on list module

Kim Hawtin kim at hawtin.net.au
Tue Dec 14 10:27:56 EST 2010


Hi Richard,

richard wrote:
> I'm using the list module. It is very nice.
> But now I'm facing a little problem.
> It seems that a list node can (by design) only be a member of one linked list.
> In my case i need to have list nodes which are present in many lists.
> 
> E.g:
> struct _item {
>  struct list_node list;
>  // lots of data
> };
> struct _item i1;
> 
> list_add(&h1, &i1.list);
> list_add(&h2, &i1.list);
> ...
> list_add(&hN, &i1.list);
> 
> 
> Does anyone know a trick how to achieve this?
> I really don't want to go back to "void *"-style linked lists...

not put a lot of thought into this however, but could you put in a link 
count the same way that a file system can have many hard links to a 
single inode/file?

i have had a similar problem in the past where i had a data object, 
where it needed to be referenced by several lists, the list item 
contained a pointer to the data object. there was one insert only doubly 
linked list that contained *all* the data objects and the smaller lists 
that did the 'work' which added and removed list items but never touched 
the actual data... if that makes sense. finally at the end of the long 
lived batch runs i would prune the lists before dumping out to files.

i am sure there are much better ways out there.

perhaps you might explain a bit more about the problem?

for example, why are you adding the same data object to multiple lists?

perhaps there are better data structures for your problem?

cheers,

kim



More information about the ccan mailing list