swarm-support
[Top][All Lists]
Advanced

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

Re: one more list question


From: Roger M. Burkhart
Subject: Re: one more list question
Date: Thu, 8 Feb 1996 15:00:16 -0600

> I have another question about lists.  Is there any way to tell what the 
> index of a member within a list is?  I want to know because at a certain 
> point I want to build a mirror to one of my id lists, full of ints, so that 
> the each indexed int would correspond to its respective id.

An Index object doesn't have a unique associated member, since it may be
positioned to different members at different times.  However, each member
has a unique integer offset defined within the collection, defined as the
relative position at which an index started at the beginning of the
collection would find the member.  The most common case of using such
integer offsets is on arrays, since they implement fast access by integer
position, but the offsets are defined on any collection.

To get the member at offset i, use:

  obj = [aCollection atOffset: i];

To replace the member at offset i, use:

  [aCollection atOffset: i put: anObject];

Neither of these messages changes the count of the collection.  You must
still add initial members using other methods such as addLast:.  Once you
have members in the collection, however, they provide an alternate way
to access the members in each member slot.

When you have an index to a collection, you can get its offset with getOffset:

  index = [aCollection begin: scratchZone];
  while ( [index next] ) {
    ...;  i = [index getOffset]; ...
  }  

Other possible ways to implement your member-associated integer might
be to store it within the member, or to use the member as the key of a
Map with the integer as associated member value.

Hope your question is answered here somewhere.

Roger


reply via email to

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