swarm-support
[Top][All Lists]
Advanced

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

Re: Want to delete item from list. Can't understand archived notes


From: Chimera
Subject: Re: Want to delete item from list. Can't understand archived notes
Date: Fri, 17 Jul 1998 13:23:08 -0700

 Paul;

   If you want to "remove: aType"  then I think you have to set up your list 
this way:

      listType = [List customizeBegin: [self getZone]];
      [listType setIndexFromMemberLoc: offsetof( AdultAphytis, listMember )];
      listType = [listType customizeEnd];

      adultAphytisList = [listType create: [self getZone]];

I believe most of these examples live in Grid Turtle.

You should note, however, that in implementation, this is no different than 
just finding the member,
creating an index to the top of the list, searching the list for a match to the 
member, and then
doing an [index remove].  This is actually one of the things I tried to get 
fixed in Swarm a while
back (before Marcus came on).  If you have the member id that you want to 
remove, you shouldn't have
to search the whole list a second time and then do a remove.  This turns a list 
remove O(1) to O(n);
And no, at present, I have NO desire to update collections myself, I am only 
willing to complain.
Also, my advisor would shoot me if I worked on anything that did not have 
dissertation directly
attached to it. :-)

In your case, I wonder if you could just:

            index = [invitationsList begin: [self getZone]];
            removeIndex=[invitationsList begin: [self getZone]];
           while (( aRecruiter = [index next]) )
           {

                  proposal= [aRecruiter getProposal];
                  disutility = [self distFromIdeal: proposal];
                  if( disutility < bestValue )
                  {
                       bestValue=disutility;
                       bestAlternative=aRecruiter;
                       removeIndex=index;
                  }

            }

            [invitationsRanking addLast: bestAlternative];
            [removeIndex remove];
/ /  Remember to drop indexes
            [removeIndex drop];
            [index drop];

This would save you (in you case) two additional searches of the list.  Note 
that I have never tried
this, but it is worth a try.

Cheers,

   D3


Paul Johnson wrote:

> I have a list of objects, each is evaluated by a criterion, I pick the
> best and add it to another list. Then I want to delete that best
> alternative from the list, do the same procedure to pick the second best,
> add it on that other list.  The problem is that I can't seem to find
> a way to code the removal from the list that does not cause a seg fault.
>
> I found in the mailing list archives (May 22, 1998) a discussion between 
> Roger,
> Doug D,  Marcus, and Geoff Schultz, and I'm too dense to understand how to
> adapt their suggestions.
>
> Here is my code snippet that finds the alternative with the lowest disutility
> from the list invitationsList and adds it to invitationsRanking.
>
>            invitationsRanking=[List create: [self getZone]];
>             bestValue=100000.0;
>            index = [invitationsList begin: [self getZone]];
>
>            while (( aRecruiter = [index next]) ) {
>
>                   proposal= [aRecruiter getProposal];
>                   disutility = [self distFromIdeal: proposal];
>                   if(disutility < bestValue) { bestValue=disutility; 
> bestAlternative=aRecruiter;}
>
>               }
>
>             [invitationsRanking addLast: bestAlternative];
>
> This code runs FINE to pick the bestAlternaive.  It only works when
> I want to pick the single
> best alternative, and I want to cycle through it again to pick the second best
> as well.  To do that I need to remove bestAlternative from the 
> invitationsList.
>
> I tried just putting
>                 [invitationsList remove: bestAlternative];
> at the end of all this, but it seg faults big time.
>
> If you have an idea, please let me know!
>
> Incidentally, I got into this because I got lots of strange output from the
> Qsort method  in Simtools.  I asked about that method a couple of weeks ago in
> here and didn't find any authorities on it, so I gave up. The problem seems
> to be that the Sort method insists the criterion be an integer, rather than
> a double.  Oh, well, if I can find a way to pick the second best, third best,
> etc, I will be happy and it won't take as much time as a full Qsort anyway.
>
> Paul E. Johnson                      address@hidden
> Dept. of Political Science           http://lark.cc.ukans.edu/~pauljohn
> University of Kansas                 Office: (913) 864-9086
> Lawrence, Kansas 66045               FAX: (913) 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.
>                   ==================================



--
*********************************************************************
* Doug Donalson                 Office: (805) 893-2962
* Ecology, Evolution,           Home:   (805) 961-4447
* and Marine Biology            email address@hidden
* UC Santa Barbara
* Santa Barbara Ca. 93106
*********************************************************************
*
*   The most exciting phrase to hear in science, the one that
*   heralds new discoveries, is not "EUREKA" (I have found it) but
*   "That's funny ...?"
*
*       Isaac Asimov
*
*********************************************************************



                  ==================================
   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]