swarm-support
[Top][All Lists]
Advanced

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

Re: Ordered Lists


From: Paul E. Johnson
Subject: Re: Ordered Lists
Date: Wed, 07 Jun 2000 15:41:55 -0500

> 1.)  Create a list using member_t and "getOffset".
I'm sorry, I don't understand that.
> 
> 2.)  To insert in an ordered list I would first:
> 
>        Use index: getKey to find the key of the present member.
>        If key was less than or equal to the new insert, then use
> insertBefore or insertAfter?
>        Is there an addBefore or addAfter?  I thought I have seen them
> somewhere in the documentation
>        but I can't find them now.
Look under the index protocols.
> 
> Am I on the right track?
> 
I did this recently by creating a new class and in it I store the
calculated value and the object, then I put these new things into a
list. I did it this way because the agent doing the sorting did not want
to write in the original object and did not want to repeatedly calculate
its value each time a comparison was to be made.  Those storage objects
give back a value in response to getValue.   
        
        list=[List create: [self getZone];
        index=[list begin: [self getZone]];

        Then march the index to the right spot in the list. I'm cutting some
details out of this code because they are specific to a project, but do
it like this. Suppose.

        calculatedValue = value of object being inserted.
        
   [index setLoc:start];
    while( ((anOffer=[index next])!=nil))
        {
          if ( calculatedValue < [anOffer getValue] )
            {
              i++;
            }
          else
            {
              break;
            }
        }


  This moves the index until it is on the object that is not better than
what you are inserting.  Add the "theObject" with

        [index addBefore: theObject];

I was using the i++ to printout the position, just for fun.  I realize
this method is not fast because it starts at the beginning and checks
each item.

-- 
Paul E. Johnson                         email: address@hidden
Dept. of Political Science              http://lark.cc.ukans.edu/~pauljohn
University of Kansas                    Office: (785) 864-9086
Lawrence, Kansas 66045                  FAX: (785) 864-5700

                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

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