#import <simtools.h>     // initSwarm () and swarmGUIMode
#import <objectbase/SwarmObject.h>

@interface ObjKey : SwarmObject
{
  int number;
}
- setNumber: (int) n;
- (int)getNumber;
@end
@implementation ObjKey
- setNumber: (int) n {
  number = n;
  return self;
}
- (int) getNumber {
  return number;
}
@end
@interface Obj : SwarmObject
{
}
@end
@implementation Obj
@end

int
cFunc (id obj1, id obj2)
{
  if ([obj1 getNumber] < [obj2 getNumber])
    return -1;
  else if ([obj1 getNumber] > [obj2 getNumber])
    return 1;
  return 0;
}

int
main (int argc, const char **argv)
{
  id <Map> aMap = nil;
  id <Map> mapCopy = nil;
  id objKey = nil;
  id obj = nil;

  initSwarm (argc, argv);

  aMap = [Map createBegin: globalZone];
  [aMap setCompareFunction: cFunc];
  aMap = [aMap createEnd];

  objKey = [ObjKey create: globalZone];
  [objKey setNumber: 1L];
  obj = [Obj create: globalZone];
  [aMap at: objKey insert: obj];

  objKey = [ObjKey create: globalZone];
  [objKey setNumber: 2L];
  obj = [Obj create: globalZone];
  [aMap at: objKey insert: obj];

  fprintf(stderr, "Before the copy.\n");
  xfprint(aMap);
  fprintf(stderr, "compare_t %p\n", [aMap getCompareFunction]);

  mapCopy = [aMap copy: globalZone];

  fprintf(stderr, "After the copy.\n");
  xfprint(mapCopy);
  fprintf(stderr, "compare_t %p\n", [mapCopy getCompareFunction]);

  return 0;
}
