swarm-support
[Top][All Lists]
Advanced

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

Re: problem with adding to Map collection


From: Paul E. Johnson
Subject: Re: problem with adding to Map collection
Date: Tue, 10 Aug 1999 09:29:35 -0500

Welcome to swarm!

Here is an example of Map usage in my new collection of examples:

http://lark.cc.ukans.edu/~pauljohn/SwarmFaq/WorkingExampleCode/MapOfMapsOfLists.txt

I think the problem with your example is that the Map is using integers
as the "key" values, but you don't set the compare function to tell the
Map you are using integers and you don't cast your integers as (id) when
you use them.

If you look at the gridTurtle example in swarmdocs, you will see that if
your key is an object, then there is no need to worry about those
details. But if you use an int, you have to.

Marcus's example I refer to above shows also  the setCompareFunction
usage.

pj

Ach.
> 
> Question:
> - What am I doing wrong here?
> - Is this a good solution anyway?
> 
> ...
> ...
>   //Reading functionValues into List
>   // and next List into Map
>   functionCollection = [Map create: [self getZone]];
>   for (functcount=0; functcount < ([readFunction 
> getNrOfRelations]);functcount++){
>         [readFunction readRelation];
>         passor = [readFunction getPassor];
>         actor = [readFunction getActor];
>         radius = [readFunction getRadius];
>         printf("Passor: %d, Actor: %d, Neigborhood %d\n", passor, actor, 
> radius);
>         functionValueList = [List create: [self getZone]];
>         for (functvaluecount=0; functvaluecount < radius; functvaluecount++){
>                 functvalue = [readFunction readFunctions];
>                 [functionValueList addLast: functvalue];
>         }
> 
>         printf("nr of elements in list: %d\n",[functionValueList getCount]);
>         [functionCollection at: functcount  insert: functionValueList];
> }
> 
>         //debuging stuff
>         printf("the number of elements in the 
> functionCollection%d\n",[functionCollection getCount]);
>         printf("And here the values of each list stored in the Map collection 
> object\n");
>         indexje = [functionCollection begin: [self getZone]];
>         for (theSet = [indexje next]; [indexje getLoc] == Member; theSet = 
> [indexje next] ){
>                 index = [theSet begin: [self getZone]];
>                 for (fromMap = [index next]; [index getLoc] == Member; 
> fromMap = [index next]){
>                         printf("value: %d\n",fromMap);
>                 }
>         [index drop];
>         }
>         [indexje drop];
>         // end debuging stuff
> 
> Arend Ligtenberg
> Wageningen University and Research Centre
> Centre for Geo-information
> Laboratory Geo-Information Science and Remote Sensing
> Po Box 339
> 6700 AH Wageningen
> tel: ++31 317 474640
> www.gis.wau.nl/girs
> 
>                   ==================================
>    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.

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