swarm-support
[Top][All Lists]
Advanced

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

Re: [Question] using Map, setCompareFunction, ordering lists


From: Paul E. Johnson
Subject: Re: [Question] using Map, setCompareFunction, ordering lists
Date: Tue, 15 Jun 1999 20:52:59 -0500

Norberto Eiji Nawa wrote:
> 
> Hello Marcus,
> 
> NEN> The problem is that I am getting a segmentation fault in [c1 getPrice],
> NEN> when sellList contains already one element.
> 
> Marcus> Are you using objects or integers as your Map key?
> 
> Your question helped me clarify how the at:insert: Map method
> works. Needless to say, I was missing the point here.
> 
> For your reference of what a imaginative mind of a new user can think,
> here follows my mistake (mea culpa :-)
> 
> When inserting an object in a list, I was doing:
> 
> [sellList at: (id)auxPrice insert: bo];
> 
> Somehow, after reading the documentation, I imagined that I should
> pass the value of object bo's "key" (int auxPrice) in at:insert:
> 
> The problem was that I was trying to retrieve the value of the key
> from inside the compare function, calling my method from one int
> casted into one id!!!
> 
> The correct way (I guess) should be:
> 
> [sellList at: (id)bo insert: bo];
> 
> Thanks a lot,
> 
> Eiji
> 
I have been using some Maps lately, but I'm not an expert. However, this
usage seems to indicate you ought to use the Set class rather than Map.
Set is for cases where the object being stored is the same as the key. 
I've never had occasion to write this kind of class, but let me tell you
more about Maps, which I've used lately. 

A Map is more suited to something like this.  Suppose an agent offers me
a basket.  In my map, I want to keep the baskets offered and I'll use
the agent's identity as the key, something like 

  [sellList at: agent insert: basket];

Then when you want the basket offered by an agent, you ask by the key
name.

I keep telling everybody to go look at the Grid Turtle example program
3, where there are examples of Maps that have keys that are objects and
integers.  The integer one might be useful if, for example, each agent
who gives you a basket can answer to something like [agent
getYourInteger]. if you saved the return value, then cast it as (id),
you can add integer-keyed items  (this requires setting the compare
function, using a map with object keys does not).  

Sorry I can't write more right now.

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