Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2001:
[Freeciv-Dev] Re: {gen,spec,sort}list stuff
Home

[Freeciv-Dev] Re: {gen,spec,sort}list stuff

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: "Ross W. Wetmore" <rwetmore@xxxxxxxxxxxx>
Cc: Justin Moore <justin@xxxxxxxxxxx>, freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: {gen,spec,sort}list stuff
From: Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 29 Aug 2001 10:13:27 +0200
Reply-to: rf13@xxxxxxxxxxxxxxxxxxxxxx

On Tue, Aug 28, 2001 at 08:21:23PM -0400, Ross W. Wetmore wrote:
> At 05:23 PM 01/08/28 +0200, Raimar Falke wrote:
> >On Tue, Aug 28, 2001 at 10:27:28AM -0400, Justin Moore wrote:
> >> 
> >> > > done at the end, so there are potential inconsistancies.  The macros
> >> > > (essentially) do this:
> >> > >
> >> > > while(ITERATOR_PTR(X)) {
> >> > >   ITERATOR_NEXT(X);
> >> > >   /* Do stuff */
> >> > > }
> >> >
> >> > No. It does:
> >> >
> >> >   for(; ITERATOR_PTR(myiter);) {
> >> >     var=(atype *)ITERATOR_PTR(myiter);
> >> >     ITERATOR_NEXT(myiter);
> >> >     /* Do stuff */
> >> >   }
> >> >
> >> > So the loop body (if it doesn't look at myiter) will see in the first
> >> > pass the first element.
> >> 
> >>    Yes, I know.  Ok, I left out the variable assignment; I assumed people
> >> knew the assignment happened along with the ITERATOR_PTR call.  I was just
> >> using the 'while' construct to visually demonstrate my point about where
> >> the iterator is advanced.  
> >
> >> There are places where the iterator is used or passed as a variable
> >> to another function.  When this is done inside of a macro-based loop
> >> it might not yield the right results.
> >
> >Now I see. I consider this broken or at least very ugly.
> 
> You may want to be a little careful around here. The list types 1&2 below
> are probably indicative of techniques where you advance the list to get the 
> next position before you delete the element inside the list and so if not
> careful would also lose the iteration thread.
> 
> With the saved pointer you just continue merrily.
> 
> This will likely cause a number of complications with sorted array lists
> that do slot recovery on every deletion as I think Justin found.
> 
> These are valid techniques for the current GENLIST flavour, but may not
> tranfer easily to others and may not be easily spotted.

Ok but can't we in preparation of other lists restrict the things you
can do with the current list?

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "- Amiga Y2K fixes (a bit late, wouldn't you say?)"
    -- Linus Torvalds about linux 2.4.0 at 4 Jan 2001


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