[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: multiple attributes
From: |
James Joseph Clark |
Subject: |
Re: multiple attributes |
Date: |
Fri, 14 Mar 1997 17:12:06 -0500 |
>
> Imagine a heatbugs-based application, but one where you want
> a (possibly large) number of attributes for each world grid
> site.
>
> Does anyone have an opinion as to what would be more efficient,
> having multiple 'heat spaces', or coding a new kind of space
> where each site points to a LIST of attributes (e.g. a list of
> integers) ?
>
> I know the first alternative is doable (I currently have 3 spaces),
> but slow. Has anyone made any attempts toward the second alternative?
>
> Sven
>
>
Actually, I have done something like this, and put it in the
contributed files area of the Swarm ftp site. My approach is called a
"strattice" (for "stratified lattice"). It is basically the second of
your alternatives. Here is the code:
/* A 2d discrete stratified lattice (strattice).
*
* Copyright (C) 1996, James J. Clark
* Centre for Intelligent Machines
* McGill University
*
* A keyed collection (Map) of Grid2d objects (strata).
*
* -allocStratum: aString
* This method treats the String object passed as a key into the
* StratticeMap. If an entry already exists matching that key, then
* that entry is returned. Otherwise a new entry is made and returned.
*
*/
#import <collections.h>
#import <swarmobject/SwarmObject.h>
#import <space.h>
#import <stdlib.h>
@interface Strattice : SwarmObject {
id StratticeMap;
int xsize, ysize;
}
+createBegin: (id) aZone;
-createEnd;
-(Grid2d *)allocStratum: (id) aString;
-setSizeX: (int) x Y: (int) y;
@end
@implementation Strattice
-setSizeX: (int) x Y: (int) y {
if (xsize)
[InvalidArgument raiseEvent: "You cannot change the strattice size.\n"];
xsize = x;
ysize = y;
return self;
}
+createBegin: (id) aZone {
Strattice * obj;
obj = [super createBegin: aZone];
return obj;
}
-createEnd {
if (xsize <= 0 || ysize <= 0)
[InvalidCombination raiseEvent: "invalid size in creation of Strattice\n"];
StratticeMap = [Map create: [self getZone]];
if(!StratticeMap) return nil;
return self;
}
-(Grid2d *)allocStratum: aString {
Grid2d *stratum;
stratum = [StratticeMap at: aString]; // see if entry already exists
if(stratum) return stratum;
// create the Grid2d to be used as the storage array
stratum = [Grid2d createBegin: [self getZone]];
[stratum setSizeX: xsize Y: ysize];
stratum = [stratum createEnd];
[StratticeMap at: aString insert: stratum];
return stratum;
}
@end