swarm-support
[Top][All Lists]
Advanced

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

Map question: findNext does not work the way I expected


From: Paul Johnson
Subject: Map question: findNext does not work the way I expected
Date: Tue, 12 Oct 1999 15:56:53 -0500

OK, I've run into a question. I have a swarm map called "renewalMap" and
an index for it called "renewalMapIndex".  There is no compare function
defined, I want it to just us the location of an object as the keys. 
This code does what I want, it checks to see if an object "recruiter" is
a key in the map, and extracts the stored object:


    if ((anOffer=[renewalMap removeKey:recruiter]) != nil) 
        {
          [recruiter addToWastedLetterCounter];
           if (calculatedDisutility  < tolerance ) 
             {
              anOffer setDisutility: calculatedDisutility];
             }
           else
             {
               [offerRecycleList addLast:  anOffer];
             }
        }
  
So I decided to do the same thing using the Index tools, because I've
become concerned about altering collections when their indexes exist. 
In my understanding, you can change a collection as long as you do it
though the index, but if you change the collection through the
collection tools, then you get nonsense next time you use the index. 

So I did this:

  [renewalMapIndex setLoc: Start]; 
  if ([renewalMapIndex findNext:recruiter] != nil) 
    //if ((anOffer=[renewalMap removeKey:recruiter]) != nil) 
        {
          printf("\n I found one \n");
          [recruiter addToWastedLetterCounter];
           if (calculatedDisutility  < tolerance ) 
             {
               anOffer=[renewalMapIndex remove];
               [anOffer setDisutility: calculatedDisutility];
             }
           else
             {
               [offerRecycleList addLast:  [renewalMapIndex remove] ];
             }
        }

I expect these two code snips should do the same thing: find the object
with key "recruiter" and remove it, and call it "anOffer".  

BUT the second one does not work.  It never finds the first if statement
is valid, I never finds the key.

So the inner part never executes.

How could I use this renewalMapIndex differently, to find and remove?
  
-- 
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]