swarm-support
[Top][All Lists]
Advanced

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

Re: simple List index question


From: Roger M. Burkhart
Subject: Re: simple List index question
Date: Mon, 20 Nov 95 14:40:23 CST

> I just want to check to be sure I am using 
> List indexing correctly.  Is the basic idea:
> 
>     id index, other;
>     index = [siteNbors begin: xZone];
>     for ( other=[index next]; other; other=[index next] ) {
>       [other calcE];
>     } 
>     [index dropFrom: xZone];

Yes, this is fine.  I usually use a while loop rather than a for loop,
like this:

  index = [siteNbors begin: xZone];
  while ( (other = [index next]) ) [other calcE];
  [index dropFrom: xZone];

(The extra parentheses around the assignment used as a while condition are
needed to suppress a gcc warning under -Wall.)

> As I understand it, when I dropFrom the index,
> I'm just getting rid of it, not anything in the
> siteNbors List itself...is that right?
> 
> Also, am I right that the index and the original List
> don't have to be in the same zone?

Yes on both.  An index is often allocated in a scratch zone for local,
temporary use and dropped as soon as it is no longer needed.  It is intended
to be a very low overhead object for collection traversal.  It always does
a good job of sequential traversal (forward or backward), but random position
access (for example, to a random position via [index setOffset: iOffset])
depends on the underlying implementation.  For the current list, this is
no better than sequentially traversing up to the requested offset.  For
other list implementations and for Array (both to be provided) random
position access will be much faster.  If you want fast random access
today, the only way to get it is to allocate your own array of id pointers
and index that directly in C.

Roger


reply via email to

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