swarm-support
[Top][All Lists]
Advanced

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

Re: Map


From: Paul E. Johnson
Subject: Re: Map
Date: Thu, 08 Apr 1999 16:43:32 -0500

LIK MUI wrote:
> 
> --------
> 
> Hello,
> 
> I am trying out the Map collection class but find the key-comparison
> is "object-equality" as opposed to "value-equality".  Is there a
> collection class that belong to the latter?  (From looking at
> MapIndex, I am not sure what "The index behavior for a Map" is.)
> 
> More generally, I am trying to have a "randomly accessible" list of
> swarm objects.  The default "List" only allows add/remove from beginning
> and end.  Is "Map" the best option is Swarm?
> 
I've just been studying this myself. The docs aren't totally clear, but
the examples in part 3 of the gridturtle collection show usage of Map
and help quite a bit. A Map object maintains these two "parallel
structures", one containing the keys and the other containing the
objects you put in.  The keys are, by default, objects of type id.  They
can be other things, like values, but then you have to specify a compare
function (same sort as used in qsort or such).

As far as I understand it, a MapIndex type is the sort of index that is
automatically created when you use the "begin" command to create an
index from an object of type Map.  When the index is defined, you can
grab the identity of the key at the current position of the index in the
Map, and so forth.
  
If you want the "random access" according to some integer, then you set
the compareFunction.  Swarm has several compare functions in the
library, and you can design your own from looking at them.  The
compareIntegers function will let you use integers as keys, and they are
cast as type (id) for storage in the map, and then you can cast them as
int when you want to retrieve key values.    

Incidentally, perhaps one of the experts will correct me, but I don't
think the current Swarm library supports "random access" in a fast way. 
If you tell a map object you want an object at a particular key value,
the Map object will begin at the beginning and check, one by one, until
it finds the object whose key matches the one you request.  So, if the
one you want happens to be at the end, you end up stepping through the
whole map.  Conceptually, I don't think it is different than a Swarm
List in which you look for specific items by checking each one until one
of them responds to a particular message in a particular way.

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