bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Node to first or last element of a sequential list in module list/xl


From: Marc Nieper-Wißkirchen
Subject: Re: Node to first or last element of a sequential list in module list/xlist
Date: Sat, 3 Apr 2021 12:00:26 +0200

Am Sa., 3. Apr. 2021 um 11:49 Uhr schrieb Bruno Haible <bruno@clisp.org>:
Marc Nieper-Wißkirchen wrote:
> > I don't understand. You want to use a list_node_t while adding nodes to
> > the list? This is invalid, since the comments in gl_list.h say:
> >
> >   /* Type representing the position of an element in the list, in a way
> > that
> >      is more adapted to the list implementation than a plain index.
> >      Note: It is invalidated by insertions and removals!  */
> >   typedef struct gl_list_node_impl * gl_list_node_t;
> >
>
> It won't work with removals but it does work with insertions because
> gl_list_add_before/gl_list_add_after/... etc. all return new, valid list
> node objects.

While this may be true for the linked-list implementation, it is not true
for the array-list and other implementation. But the point of the Gnulib
list module is to allow the developer to switch to a different implementation
without changing their algorithms. [1]

I understand the point about being able to switch to a different implementation and subscribe to it, but I don't understand why there should be a problem with array-list or other implementations. When I look into "lib/gl_array_list.c", I see that a valid node is returned, namely the node corresponding to the newly inserted element.  Besides, what's the point of returning nodes if they weren't valid?  Note that we are not talking about reusing the node object used as the argument to add_before or add_after.  That is invalid, indeed.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]