swarm-support
[Top][All Lists]
Advanced

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

RE: integer wrappers for Swarm Maps: did I miss something?


From: Benedikt Stefánsson
Subject: RE: integer wrappers for Swarm Maps: did I miss something?
Date: Wed, 15 Sep 1999 17:05:32 +0100

The answer is to obvious, so maybe you meant something else, but you can always 
keep an Integer instance around and just set the integer to the value you want, 
then you pass the instance to the map to retrieve the object:

   // Create w/o value
  anInteger = [Integer createBegin: [self getZone]; 
  
  // Search for item at i

  [anInteger setValue: i]
  objectYouWanted = [mapOfPreferences at: anInteger];

Although it is not quite kosher you can also get away with using straight C int 
keys, casting them to id and passing them to the Map.   

Benedikt

-----Original Message-----
From:   Paul Johnson [SMTP:address@hidden
Sent:   15. september 1999 16:39
To:     address@hidden
Subject:        integer wrappers for Swarm Maps: did I miss something?

Ok, so I'm writing more swarm user guide and I come to Maps.  It seems
to me that if you use an Integer wrapper class to put things into a Map,
you also need to maintain an Array of the Integer objects so you can
retrieve things from the Map when you want them.  Not so?  

Here is the example code:


An Integer wrapper class (ripped off from Marcus's test program
comparing Set and List):

//Integer.h
#import <defobj/Create.h>

@interface Integer: CreateDrop
{
int value;
member_t link;
}
- setValue: (int)value;
- (int)getValue;
@end

//Integer.m
@implementation Integer
- setValue: (int)theValue
{
value = theValue;
return self;
}

- (int)getValue
{
return value;
}

@end

And suppose we use that class to wrap integers, as in this code snippet:

#include Integer.h
#include Preference

//Suppose this is in the middle of a buildObjects method ...

id <Array> arrayOfIntegers;
id <Map> mapOfPreferences;

//This will contain the integer wrapper objects
arrayOfIntegers=[Array create: [self getZone] setCount: 50];

for(i=0; i < 50; i++)
{
  id aPreference;

  aPreference = [Preference createBegin: [self getZone]];
  aPreference = [aPreference createEnd];

  anInteger = [[Integer createBegin: [self getZone] setValue: i]
createEnd];

  [arrayOfIntegers atOffset: i put: anInteger];
  
  [mapOfPreferences at: anInteger insert: aPreference];
}

// When you want the item from the map with integer value 15, you have
to do:

   anInteger = [arrayOfIntegers atOffset: 15];
   objectYouWanted = [mapOfPreferences at: anInteger];


Is there a simpler way to do this?


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

<<application/ms-tnef>>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]