1995-10-26 01:16:38 +00:00
|
|
|
/* Concrete implementation of NSSet based on GNU Set class
|
1998-10-08 13:46:53 +00:00
|
|
|
Copyright (C) 1995, 1996, 1998 Free Software Foundation, Inc.
|
1995-10-26 01:16:38 +00:00
|
|
|
|
1996-04-17 20:17:45 +00:00
|
|
|
Written by: Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
|
1996-02-22 15:18:57 +00:00
|
|
|
Created: September 1995
|
1998-10-08 13:46:53 +00:00
|
|
|
Rewrite by: Richard frith-Macdonald <richard@brainstorm.co.uk>
|
1995-10-26 01:16:38 +00:00
|
|
|
|
1996-05-12 00:56:10 +00:00
|
|
|
This file is part of the GNUstep Base Library.
|
1995-10-26 01:16:38 +00:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
License along with this library; if not, write to the Free
|
1999-09-09 02:56:20 +00:00
|
|
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
1995-10-26 01:16:38 +00:00
|
|
|
*/
|
|
|
|
|
1997-11-06 00:51:23 +00:00
|
|
|
#include <config.h>
|
1998-10-08 13:46:53 +00:00
|
|
|
#include <Foundation/NSSet.h>
|
1998-12-20 21:27:47 +00:00
|
|
|
#include <base/behavior.h>
|
1998-10-17 06:47:46 +00:00
|
|
|
#include <Foundation/NSAutoreleasePool.h>
|
2000-08-07 22:00:31 +00:00
|
|
|
#include <Foundation/NSArray.h>
|
1998-10-17 06:47:46 +00:00
|
|
|
#include <Foundation/NSException.h>
|
1995-10-26 01:16:38 +00:00
|
|
|
#include <Foundation/NSUtilities.h>
|
|
|
|
#include <Foundation/NSString.h>
|
1998-10-08 13:46:53 +00:00
|
|
|
#include <Foundation/NSPortCoder.h>
|
1999-11-07 14:50:30 +00:00
|
|
|
#include <Foundation/NSDebug.h>
|
2000-10-31 11:05:23 +00:00
|
|
|
#include <Foundation/NSObjCRuntime.h>
|
1998-10-08 13:46:53 +00:00
|
|
|
|
1999-06-21 08:30:26 +00:00
|
|
|
#define GSI_MAP_HAS_VALUE 0
|
|
|
|
#define GSI_MAP_KTYPES GSUNION_OBJ
|
1998-10-08 13:46:53 +00:00
|
|
|
|
1999-06-21 08:30:26 +00:00
|
|
|
#include <base/GSIMap.h>
|
1998-10-08 13:46:53 +00:00
|
|
|
|
|
|
|
@class NSSetNonCore;
|
|
|
|
@class NSMutableSetNonCore;
|
|
|
|
|
|
|
|
@interface NSGSet : NSSet
|
|
|
|
{
|
|
|
|
@public
|
1999-06-21 08:30:26 +00:00
|
|
|
GSIMapTable_t map;
|
1998-10-08 13:46:53 +00:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface NSGMutableSet : NSMutableSet
|
|
|
|
{
|
|
|
|
@public
|
1999-06-21 08:30:26 +00:00
|
|
|
GSIMapTable_t map;
|
1998-10-08 13:46:53 +00:00
|
|
|
}
|
|
|
|
@end
|
1995-10-26 01:16:38 +00:00
|
|
|
|
|
|
|
@interface NSGSetEnumerator : NSEnumerator
|
|
|
|
{
|
1998-10-27 08:12:49 +00:00
|
|
|
NSGSet *set;
|
1999-06-21 08:30:26 +00:00
|
|
|
GSIMapNode node;
|
1995-10-26 01:16:38 +00:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSGSetEnumerator
|
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
- (id) initWithSet: (NSSet*)d
|
1995-10-26 01:16:38 +00:00
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
self = [super init];
|
|
|
|
if (self != nil)
|
|
|
|
{
|
|
|
|
set = (NSGSet*)RETAIN(d);
|
|
|
|
node = set->map.firstNode;
|
|
|
|
}
|
1998-10-27 08:12:49 +00:00
|
|
|
return self;
|
1995-10-26 01:16:38 +00:00
|
|
|
}
|
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
- (id) nextObject
|
1995-10-26 01:16:38 +00:00
|
|
|
{
|
1999-06-21 08:30:26 +00:00
|
|
|
GSIMapNode old = node;
|
1998-10-08 13:46:53 +00:00
|
|
|
|
1998-10-27 08:12:49 +00:00
|
|
|
if (node == 0)
|
|
|
|
{
|
|
|
|
return nil;
|
1998-10-08 13:46:53 +00:00
|
|
|
}
|
1998-10-27 08:12:49 +00:00
|
|
|
node = node->nextInMap;
|
1999-04-12 12:53:30 +00:00
|
|
|
return old->key.obj;
|
1995-10-26 01:16:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
1999-07-03 19:59:44 +00:00
|
|
|
RELEASE(set);
|
1998-10-27 08:12:49 +00:00
|
|
|
[super dealloc];
|
1995-10-26 01:16:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
@implementation NSGSet
|
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
static Class arrayClass;
|
|
|
|
static Class setClass;
|
|
|
|
static Class mutableSetClass;
|
|
|
|
|
1995-10-26 01:16:38 +00:00
|
|
|
+ (void) initialize
|
|
|
|
{
|
1998-10-27 08:12:49 +00:00
|
|
|
if (self == [NSGSet class])
|
|
|
|
{
|
|
|
|
class_add_behavior(self, [NSSetNonCore class]);
|
2000-08-07 22:00:31 +00:00
|
|
|
arrayClass = [NSArray class];
|
|
|
|
setClass = [NSGSet class];
|
|
|
|
mutableSetClass = [NSGMutableSet class];
|
1998-10-08 13:46:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (unsigned) count
|
|
|
|
{
|
1998-10-27 08:12:49 +00:00
|
|
|
return map.nodeCount;
|
1998-10-08 13:46:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
1999-06-21 08:30:26 +00:00
|
|
|
GSIMapEmptyMap(&map);
|
1998-10-27 08:12:49 +00:00
|
|
|
[super dealloc];
|
1998-10-08 13:46:53 +00:00
|
|
|
}
|
1995-10-26 01:16:38 +00:00
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
/* Designated initialiser */
|
|
|
|
- (id) initWithObjects: (id*)objs count: (unsigned)c
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
GSIMapInitWithZoneAndCapacity(&map, [self zone], c);
|
|
|
|
for (i = 0; i < c; i++)
|
|
|
|
{
|
|
|
|
GSIMapNode node;
|
|
|
|
|
|
|
|
if (objs[i] == nil)
|
|
|
|
{
|
|
|
|
IF_NO_GC(AUTORELEASE(self));
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"Tried to init set with nil value"];
|
|
|
|
}
|
|
|
|
node = GSIMapNodeForKey(&map, (GSIMapKey)objs[i]);
|
|
|
|
if (node == 0)
|
|
|
|
{
|
|
|
|
GSIMapAddKey(&map, (GSIMapKey)objs[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) member: (id)anObject
|
|
|
|
{
|
|
|
|
if (anObject)
|
|
|
|
{
|
|
|
|
GSIMapNode node = GSIMapNodeForKey(&map, (GSIMapKey)anObject);
|
|
|
|
|
|
|
|
if (node)
|
|
|
|
{
|
|
|
|
return node->key.obj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSEnumerator*) objectEnumerator
|
|
|
|
{
|
|
|
|
return AUTORELEASE([[NSGSetEnumerator alloc] initWithSet: self]);
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSGSet (NonCore)
|
|
|
|
|
|
|
|
- (NSArray*) allObjects
|
|
|
|
{
|
|
|
|
id objs[map.nodeCount];
|
|
|
|
GSIMapNode node = map.firstNode;
|
|
|
|
unsigned i = 0;
|
|
|
|
|
|
|
|
while (node != 0)
|
|
|
|
{
|
|
|
|
objs[i++] = node->key.obj;
|
|
|
|
node = node->nextInMap;
|
|
|
|
}
|
|
|
|
return AUTORELEASE([[arrayClass allocWithZone: NSDefaultMallocZone()]
|
|
|
|
initWithObjects: objs count: i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) anyObject
|
|
|
|
{
|
|
|
|
if (map.nodeCount > 0)
|
|
|
|
return map.firstNode->key.obj;
|
|
|
|
else
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
1998-10-08 13:46:53 +00:00
|
|
|
- (void) encodeWithCoder: (NSCoder*)aCoder
|
|
|
|
{
|
1998-10-27 08:12:49 +00:00
|
|
|
unsigned count = map.nodeCount;
|
1999-06-21 08:30:26 +00:00
|
|
|
GSIMapNode node = map.firstNode;
|
1998-10-27 08:12:49 +00:00
|
|
|
SEL sel = @selector(encodeObject:);
|
|
|
|
IMP imp = [aCoder methodForSelector: sel];
|
1998-10-08 13:46:53 +00:00
|
|
|
|
1998-10-27 08:12:49 +00:00
|
|
|
[aCoder encodeValueOfObjCType: @encode(unsigned) at: &count];
|
|
|
|
while (node != 0)
|
|
|
|
{
|
1999-04-12 12:53:30 +00:00
|
|
|
(*imp)(aCoder, sel, node->key.obj);
|
1998-10-27 08:12:49 +00:00
|
|
|
node = node->nextInMap;
|
1995-10-26 01:16:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-10-27 08:12:49 +00:00
|
|
|
- (unsigned) hash
|
|
|
|
{
|
|
|
|
return map.nodeCount;
|
|
|
|
}
|
|
|
|
|
1998-10-08 13:46:53 +00:00
|
|
|
- (id) initWithCoder: (NSCoder*)aCoder
|
|
|
|
{
|
1998-10-27 08:12:49 +00:00
|
|
|
unsigned count;
|
|
|
|
id value;
|
|
|
|
SEL sel = @selector(decodeValueOfObjCType:at:);
|
|
|
|
IMP imp = [aCoder methodForSelector: sel];
|
|
|
|
const char *type = @encode(id);
|
1995-10-26 01:16:38 +00:00
|
|
|
|
1998-10-27 08:12:49 +00:00
|
|
|
(*imp)(aCoder, sel, @encode(unsigned), &count);
|
1995-10-26 01:16:38 +00:00
|
|
|
|
1999-06-21 08:30:26 +00:00
|
|
|
GSIMapInitWithZoneAndCapacity(&map, [self zone], count);
|
1998-10-27 08:12:49 +00:00
|
|
|
while (count-- > 0)
|
|
|
|
{
|
|
|
|
(*imp)(aCoder, sel, type, &value);
|
1999-06-21 08:30:26 +00:00
|
|
|
GSIMapAddKeyNoRetain(&map, (GSIMapKey)value);
|
1998-10-08 13:46:53 +00:00
|
|
|
}
|
|
|
|
|
1998-10-27 08:12:49 +00:00
|
|
|
return self;
|
1998-10-08 13:46:53 +00:00
|
|
|
}
|
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
- (BOOL) intersectsSet: (NSSet*) otherSet
|
1995-10-26 01:16:38 +00:00
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
Class c;
|
1998-10-27 08:12:49 +00:00
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
/*
|
|
|
|
* If this set is empty, or the other is nil, this method should return NO.
|
|
|
|
*/
|
|
|
|
if (map.nodeCount == 0)
|
|
|
|
return NO;
|
|
|
|
if (otherSet == nil)
|
|
|
|
return NO;
|
|
|
|
|
|
|
|
// Loop for all members in otherSet
|
2000-10-31 16:17:33 +00:00
|
|
|
c = GSObjCClass(otherSet);
|
2000-08-07 22:00:31 +00:00
|
|
|
if (c == setClass || c == mutableSetClass)
|
1998-10-27 08:12:49 +00:00
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
GSIMapNode node = ((NSGSet*)otherSet)->map.firstNode;
|
1998-10-17 06:47:46 +00:00
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
while (node != 0)
|
1998-10-27 08:12:49 +00:00
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
if (GSIMapNodeForKey(&map, node->key) != 0)
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
node = node->nextInMap;
|
1998-10-17 06:47:46 +00:00
|
|
|
}
|
2000-08-07 22:00:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSEnumerator *e;
|
|
|
|
id o;
|
|
|
|
|
|
|
|
e = [otherSet objectEnumerator];
|
|
|
|
while ((o = [e nextObject])) // 1. pick a member from otherSet.
|
1998-10-27 08:12:49 +00:00
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
if (GSIMapNodeForKey(&map, (GSIMapKey)o) != 0)
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
}
|
1998-10-08 13:46:53 +00:00
|
|
|
}
|
2000-08-07 22:00:31 +00:00
|
|
|
return NO;
|
1998-10-08 13:46:53 +00:00
|
|
|
}
|
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
- (BOOL) isSubsetOfSet: (NSSet*) otherSet
|
1998-10-08 13:46:53 +00:00
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
GSIMapNode node = map.firstNode;
|
|
|
|
|
|
|
|
// -1. members of this set(self) <= that of otherSet
|
|
|
|
if (map.nodeCount > [otherSet count])
|
|
|
|
return NO;
|
|
|
|
|
|
|
|
// 0. Loop for all members in this set(self).
|
|
|
|
while (node != 0)
|
1998-10-27 08:12:49 +00:00
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
// 1. check the member is in the otherSet.
|
|
|
|
if ([otherSet member: node->key.obj])
|
|
|
|
{
|
|
|
|
// 1.1 if true -> continue, try to check the next member.
|
|
|
|
node = node->nextInMap;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// 1.2 if false -> return NO;
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 2. return YES; all members in this set are also in the otherSet.
|
|
|
|
return YES;
|
|
|
|
}
|
1998-10-08 13:46:53 +00:00
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
- (BOOL) isEqualToSet: (NSSet*)other
|
|
|
|
{
|
|
|
|
if (other == nil)
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
else if (other == self)
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-10-31 16:17:33 +00:00
|
|
|
Class c = GSObjCClass(other);
|
2000-08-07 22:00:31 +00:00
|
|
|
|
|
|
|
if (c == setClass || c == mutableSetClass)
|
1998-10-27 08:12:49 +00:00
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
if (map.nodeCount != ((NSGSet*)other)->map.nodeCount)
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GSIMapNode node = map.firstNode;
|
|
|
|
|
|
|
|
while (node != 0)
|
|
|
|
{
|
|
|
|
if (GSIMapNodeForKey(&(((NSGSet*)other)->map), node->key)
|
|
|
|
== 0)
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
node = node->nextInMap;
|
|
|
|
}
|
|
|
|
}
|
1998-10-17 06:47:46 +00:00
|
|
|
}
|
2000-08-07 22:00:31 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (map.nodeCount != [other count])
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GSIMapNode node = map.firstNode;
|
|
|
|
|
|
|
|
while (node != 0)
|
|
|
|
{
|
|
|
|
if ([other member: node->key.obj] == nil)
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
node = node->nextInMap;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return YES;
|
1998-10-08 13:46:53 +00:00
|
|
|
}
|
1995-10-26 01:16:38 +00:00
|
|
|
}
|
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
- (void) makeObjectsPerform: (SEL)aSelector
|
1995-10-30 01:51:46 +00:00
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
GSIMapNode node = map.firstNode;
|
|
|
|
|
|
|
|
while (node != 0)
|
|
|
|
{
|
|
|
|
[node->key.obj performSelector: aSelector];
|
|
|
|
node = node->nextInMap;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) makeObjectsPerformSelector: (SEL)aSelector
|
|
|
|
{
|
|
|
|
GSIMapNode node = map.firstNode;
|
|
|
|
|
|
|
|
while (node != 0)
|
|
|
|
{
|
|
|
|
[node->key.obj performSelector: aSelector];
|
|
|
|
node = node->nextInMap;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) makeObjectsPerformSelector: (SEL)aSelector withObject: argument
|
|
|
|
{
|
|
|
|
GSIMapNode node = map.firstNode;
|
|
|
|
|
|
|
|
while (node != 0)
|
|
|
|
{
|
|
|
|
[node->key.obj performSelector: aSelector withObject: argument];
|
|
|
|
node = node->nextInMap;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) makeObjectsPerform: (SEL)aSelector withObject: argument
|
|
|
|
{
|
|
|
|
GSIMapNode node = map.firstNode;
|
|
|
|
|
|
|
|
while (node != 0)
|
|
|
|
{
|
|
|
|
[node->key.obj performSelector: aSelector withObject: argument];
|
|
|
|
node = node->nextInMap;
|
|
|
|
}
|
1995-10-30 01:51:46 +00:00
|
|
|
}
|
1998-10-08 13:46:53 +00:00
|
|
|
|
1995-10-26 01:16:38 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSGMutableSet
|
|
|
|
|
|
|
|
+ (void) initialize
|
|
|
|
{
|
1998-10-27 08:12:49 +00:00
|
|
|
if (self == [NSGMutableSet class])
|
|
|
|
{
|
|
|
|
class_add_behavior(self, [NSMutableSetNonCore class]);
|
|
|
|
class_add_behavior(self, [NSGSet class]);
|
1995-10-26 01:16:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-10-08 13:46:53 +00:00
|
|
|
/* Designated initialiser */
|
|
|
|
- (id) initWithCapacity: (unsigned)cap
|
|
|
|
{
|
1999-06-21 08:30:26 +00:00
|
|
|
GSIMapInitWithZoneAndCapacity(&map, [self zone], cap);
|
1998-10-27 08:12:49 +00:00
|
|
|
return self;
|
1998-10-08 13:46:53 +00:00
|
|
|
}
|
1995-10-26 01:16:38 +00:00
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
- (id) initWithObjects: (id*)objects
|
|
|
|
count: (unsigned)count
|
|
|
|
{
|
|
|
|
self = [self initWithCapacity: count];
|
|
|
|
|
|
|
|
while (count--)
|
|
|
|
{
|
|
|
|
id anObject = objects[count];
|
|
|
|
|
|
|
|
if (anObject == nil)
|
|
|
|
{
|
|
|
|
NSLog(@"Tried to init a set with a nil object");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GSIMapNode node;
|
|
|
|
|
|
|
|
node = GSIMapNodeForKey(&map, (GSIMapKey)anObject);
|
|
|
|
if (node == 0)
|
|
|
|
{
|
|
|
|
GSIMapAddKey(&map, (GSIMapKey)anObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
1998-10-08 13:46:53 +00:00
|
|
|
- (void) addObject: (NSObject*)anObject
|
|
|
|
{
|
1999-06-21 08:30:26 +00:00
|
|
|
GSIMapNode node;
|
1995-10-26 01:16:38 +00:00
|
|
|
|
1998-10-27 08:12:49 +00:00
|
|
|
if (anObject == nil)
|
|
|
|
{
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
2000-08-07 22:00:31 +00:00
|
|
|
format: @"Tried to add nil to set"];
|
1998-10-17 06:47:46 +00:00
|
|
|
}
|
1999-06-21 08:30:26 +00:00
|
|
|
node = GSIMapNodeForKey(&map, (GSIMapKey)anObject);
|
1998-10-27 08:12:49 +00:00
|
|
|
if (node == 0)
|
|
|
|
{
|
1999-06-21 08:30:26 +00:00
|
|
|
GSIMapAddKey(&map, (GSIMapKey)anObject);
|
1998-10-08 13:46:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) removeObject: (NSObject *)anObject
|
1995-10-26 01:16:38 +00:00
|
|
|
{
|
1999-11-04 10:42:20 +00:00
|
|
|
if (anObject == nil)
|
1998-10-27 08:12:49 +00:00
|
|
|
{
|
1999-11-07 14:50:30 +00:00
|
|
|
NSWarnMLog(@"attempt to remove nil object", 0);
|
1999-11-04 10:42:20 +00:00
|
|
|
return;
|
1998-10-17 06:47:46 +00:00
|
|
|
}
|
1999-11-04 10:42:20 +00:00
|
|
|
GSIMapRemoveKey(&map, (GSIMapKey)anObject);
|
1995-10-26 01:16:38 +00:00
|
|
|
}
|
|
|
|
|
1998-10-08 13:46:53 +00:00
|
|
|
- (void) removeAllObjects
|
1995-10-30 01:51:46 +00:00
|
|
|
{
|
1999-06-21 08:30:26 +00:00
|
|
|
GSIMapCleanMap(&map);
|
1995-10-30 01:51:46 +00:00
|
|
|
}
|
|
|
|
|
1995-10-26 01:16:38 +00:00
|
|
|
@end
|
2000-08-07 22:00:31 +00:00
|
|
|
|
|
|
|
@implementation NSGMutableSet (NonCore)
|
|
|
|
|
|
|
|
- (void) addObjectsFromArray: (NSArray*)array
|
|
|
|
{
|
|
|
|
unsigned count = [array count];
|
|
|
|
|
|
|
|
while (count--)
|
|
|
|
{
|
|
|
|
id anObject = [array objectAtIndex: count];
|
|
|
|
|
|
|
|
if (anObject == nil)
|
|
|
|
{
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"Tried to add nil to set"];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GSIMapNode node;
|
|
|
|
|
|
|
|
node = GSIMapNodeForKey(&map, (GSIMapKey)anObject);
|
|
|
|
if (node == 0)
|
|
|
|
{
|
|
|
|
GSIMapAddKey(&map, (GSIMapKey)anObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) unionSet: (NSSet*) other
|
|
|
|
{
|
|
|
|
if (other != self)
|
|
|
|
{
|
|
|
|
NSEnumerator *e = [other objectEnumerator];
|
|
|
|
id anObject;
|
|
|
|
|
|
|
|
while ((anObject = [e nextObject]) != nil)
|
|
|
|
{
|
|
|
|
GSIMapNode node;
|
|
|
|
|
|
|
|
if (anObject == nil)
|
|
|
|
{
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"Tried to add nil to set"];
|
|
|
|
}
|
|
|
|
node = GSIMapNodeForKey(&map, (GSIMapKey)anObject);
|
|
|
|
if (node == 0)
|
|
|
|
{
|
|
|
|
GSIMapAddKey(&map, (GSIMapKey)anObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) intersectSet: (NSSet*) other
|
|
|
|
{
|
|
|
|
if (other != self)
|
|
|
|
{
|
|
|
|
GSIMapNode node = map.firstNode;
|
|
|
|
|
|
|
|
while (node != 0)
|
|
|
|
{
|
|
|
|
GSIMapNode next = node->nextInMap;
|
|
|
|
|
|
|
|
if ([other containsObject: node->key.obj] == NO)
|
|
|
|
{
|
|
|
|
GSIMapRemoveKey(&map, node->key);
|
|
|
|
}
|
|
|
|
node = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) minusSet: (NSSet*) other
|
|
|
|
{
|
|
|
|
if (other == self)
|
|
|
|
{
|
|
|
|
GSIMapCleanMap(&map);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSEnumerator *e = [other objectEnumerator];
|
|
|
|
id anObject;
|
|
|
|
|
|
|
|
while ((anObject = [e nextObject]) != nil)
|
|
|
|
{
|
|
|
|
GSIMapRemoveKey(&map, (GSIMapKey)anObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|