mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 00:30:53 +00:00
Tidyups and implementation of setSet: method
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@10010 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
5588f5026c
commit
5ac4382a6b
9 changed files with 78 additions and 38 deletions
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
||||||
|
2001-05-22 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
* Headers/Foundation/NSSet.h: Added ([-setSet:])
|
||||||
|
* Source/GSSet.m: Optimise ([-unionSet:])
|
||||||
|
* Source/GSArray.m: Tidy NSWarnMLog macros.
|
||||||
|
* Source/GSAttributedString.m: ditto
|
||||||
|
* Source/GSCountedSet.m: ditto
|
||||||
|
* Source/GSDictionary.m: ditto
|
||||||
|
* Source/NSArray.m: ditto
|
||||||
|
* Source/NSDictionary.m: ditto
|
||||||
|
* Source/NSSet.m: Implement ([-setSet:])
|
||||||
|
|
||||||
2001-05-18 Richard Frith-Macdonald <rfm@gnu.org>
|
2001-05-18 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Source/NSDate.m: check for nil dates in some init methods so
|
* Source/NSDate.m: check for nil dates in some init methods so
|
||||||
|
|
|
@ -73,8 +73,10 @@
|
||||||
- (void) minusSet: (NSSet*)other;
|
- (void) minusSet: (NSSet*)other;
|
||||||
- (void) removeAllObjects;
|
- (void) removeAllObjects;
|
||||||
- (void) removeObject: (id)anObject;
|
- (void) removeObject: (id)anObject;
|
||||||
|
#ifndef STRICT_OPENSTEP
|
||||||
|
- (void) setSet: (NSSet*)other;
|
||||||
|
#endif
|
||||||
- (void) unionSet: (NSSet*)other;
|
- (void) unionSet: (NSSet*)other;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface NSCountedSet : NSMutableSet
|
@interface NSCountedSet : NSMutableSet
|
||||||
|
|
|
@ -470,7 +470,7 @@ static SEL eqSel;
|
||||||
|
|
||||||
if (anObject == nil)
|
if (anObject == nil)
|
||||||
{
|
{
|
||||||
NSWarnMLog(@"attempt to remove nil object", 0);
|
NSWarnMLog(@"attempt to remove nil object");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
index = _count;
|
index = _count;
|
||||||
|
@ -540,7 +540,7 @@ static SEL eqSel;
|
||||||
|
|
||||||
if (anObject == nil)
|
if (anObject == nil)
|
||||||
{
|
{
|
||||||
NSWarnMLog(@"attempt to remove nil object", 0);
|
NSWarnMLog(@"attempt to remove nil object");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
index = _count;
|
index = _count;
|
||||||
|
@ -653,7 +653,7 @@ static SEL eqSel;
|
||||||
#ifdef GSWARN
|
#ifdef GSWARN
|
||||||
if (badComparison == YES)
|
if (badComparison == YES)
|
||||||
{
|
{
|
||||||
NSWarnMLog(@"Detected bad return value from comparison", 0);
|
NSWarnMLog(@"Detected bad return value from comparison");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -610,7 +610,7 @@ SANITY();
|
||||||
|
|
||||||
if (range.length == 0)
|
if (range.length == 0)
|
||||||
{
|
{
|
||||||
NSWarnMLog(@"Attempt to set attribute for zero-length range", 0);
|
NSWarnMLog(@"Attempt to set attribute for zero-length range");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (attributes == nil)
|
if (attributes == nil)
|
||||||
|
|
|
@ -284,7 +284,7 @@
|
||||||
|
|
||||||
if (anObject == nil)
|
if (anObject == nil)
|
||||||
{
|
{
|
||||||
NSWarnMLog(@"attempt to remove nil object", 0);
|
NSWarnMLog(@"attempt to remove nil object");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bucket = GSIMapBucketForKey(&map, (GSIMapKey)anObject);
|
bucket = GSIMapBucketForKey(&map, (GSIMapKey)anObject);
|
||||||
|
|
|
@ -566,7 +566,7 @@ static Class mutableSetClass;
|
||||||
{
|
{
|
||||||
if (anObject == nil)
|
if (anObject == nil)
|
||||||
{
|
{
|
||||||
NSWarnMLog(@"attempt to remove nil object", 0);
|
NSWarnMLog(@"attempt to remove nil object");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GSIMapRemoveKey(&map, (GSIMapKey)anObject);
|
GSIMapRemoveKey(&map, (GSIMapKey)anObject);
|
||||||
|
@ -577,21 +577,27 @@ static Class mutableSetClass;
|
||||||
if (other != self)
|
if (other != self)
|
||||||
{
|
{
|
||||||
NSEnumerator *e = [other objectEnumerator];
|
NSEnumerator *e = [other objectEnumerator];
|
||||||
id anObject;
|
|
||||||
|
|
||||||
while ((anObject = [e nextObject]) != nil)
|
if (e != nil)
|
||||||
{
|
{
|
||||||
GSIMapNode node;
|
id anObject;
|
||||||
|
SEL sel = @selector(nextObject);
|
||||||
|
IMP imp = [e methodForSelector: sel];
|
||||||
|
|
||||||
if (anObject == nil)
|
while ((anObject = (*imp)(e, sel)) != nil)
|
||||||
{
|
{
|
||||||
[NSException raise: NSInvalidArgumentException
|
GSIMapNode node;
|
||||||
format: @"Tried to add nil to set"];
|
|
||||||
}
|
if (anObject == nil)
|
||||||
node = GSIMapNodeForKey(&map, (GSIMapKey)anObject);
|
{
|
||||||
if (node == 0)
|
[NSException raise: NSInvalidArgumentException
|
||||||
{
|
format: @"Tried to add nil to set"];
|
||||||
GSIMapAddKey(&map, (GSIMapKey)anObject);
|
}
|
||||||
|
node = GSIMapNodeForKey(&map, (GSIMapKey)anObject);
|
||||||
|
if (node == 0)
|
||||||
|
{
|
||||||
|
GSIMapAddKey(&map, (GSIMapKey)anObject);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -993,7 +993,7 @@ static NSString *indentStrings[] = {
|
||||||
|
|
||||||
if (anObject == nil)
|
if (anObject == nil)
|
||||||
{
|
{
|
||||||
NSWarnMLog(@"attempt to remove nil object", 0);
|
NSWarnMLog(@"attempt to remove nil object");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
i = [self count];
|
i = [self count];
|
||||||
|
@ -1026,7 +1026,7 @@ static NSString *indentStrings[] = {
|
||||||
|
|
||||||
if (anObject == nil)
|
if (anObject == nil)
|
||||||
{
|
{
|
||||||
NSWarnMLog(@"attempt to remove nil object", 0);
|
NSWarnMLog(@"attempt to remove nil object");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
c = [self count];
|
c = [self count];
|
||||||
|
@ -1079,7 +1079,7 @@ static NSString *indentStrings[] = {
|
||||||
|
|
||||||
if (anObject == nil)
|
if (anObject == nil)
|
||||||
{
|
{
|
||||||
NSWarnMLog(@"attempt to remove nil object", 0);
|
NSWarnMLog(@"attempt to remove nil object");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
c = [self count];
|
c = [self count];
|
||||||
|
@ -1116,7 +1116,7 @@ static NSString *indentStrings[] = {
|
||||||
|
|
||||||
if (anObject == nil)
|
if (anObject == nil)
|
||||||
{
|
{
|
||||||
NSWarnMLog(@"attempt to remove nil object", 0);
|
NSWarnMLog(@"attempt to remove nil object");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
i = [self count];
|
i = [self count];
|
||||||
|
@ -1362,7 +1362,7 @@ static NSString *indentStrings[] = {
|
||||||
#ifdef GSWARN
|
#ifdef GSWARN
|
||||||
if (badComparison == YES)
|
if (badComparison == YES)
|
||||||
{
|
{
|
||||||
NSWarnMLog(@"Detected bad return value from comparison", 0);
|
NSWarnMLog(@"Detected bad return value from comparison");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -861,7 +861,7 @@ static NSString *indentStrings[] = {
|
||||||
#ifdef GSWARN
|
#ifdef GSWARN
|
||||||
if (badComparison == YES)
|
if (badComparison == YES)
|
||||||
{
|
{
|
||||||
NSWarnMLog(@"Detected bad return value from comparison", 0);
|
NSWarnMLog(@"Detected bad return value from comparison");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include <Foundation/NSString.h>
|
#include <Foundation/NSString.h>
|
||||||
#include <Foundation/NSException.h>
|
#include <Foundation/NSException.h>
|
||||||
#include <Foundation/NSObjCRuntime.h>
|
#include <Foundation/NSObjCRuntime.h>
|
||||||
|
#include <Foundation/NSDebug.h>
|
||||||
|
|
||||||
@class GSSet;
|
@class GSSet;
|
||||||
@class GSMutableSet;
|
@class GSMutableSet;
|
||||||
|
@ -523,20 +524,6 @@ static Class NSMutableSet_concrete_class;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) unionSet: (NSSet*) other
|
|
||||||
{
|
|
||||||
if (other != self)
|
|
||||||
{
|
|
||||||
id keys = [other objectEnumerator];
|
|
||||||
id key;
|
|
||||||
|
|
||||||
while ((key = [keys nextObject]))
|
|
||||||
{
|
|
||||||
[self addObject: key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) intersectSet: (NSSet*) other
|
- (void) intersectSet: (NSSet*) other
|
||||||
{
|
{
|
||||||
if (other != self)
|
if (other != self)
|
||||||
|
@ -577,4 +564,38 @@ static Class NSMutableSet_concrete_class;
|
||||||
[self subclassResponsibility: _cmd];
|
[self subclassResponsibility: _cmd];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) setSet: (NSSet*)other
|
||||||
|
{
|
||||||
|
if (other == self)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (other == nil)
|
||||||
|
{
|
||||||
|
NSWarnMLog(@"Setting mutable set to nil");
|
||||||
|
[self removeAllObjects];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
RETAIN(other); // In case it's held by us
|
||||||
|
[self removeAllObjects];
|
||||||
|
[self unionSet: other];
|
||||||
|
RELEASE(other);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) unionSet: (NSSet*) other
|
||||||
|
{
|
||||||
|
if (other != self)
|
||||||
|
{
|
||||||
|
id keys = [other objectEnumerator];
|
||||||
|
id key;
|
||||||
|
|
||||||
|
while ((key = [keys nextObject]))
|
||||||
|
{
|
||||||
|
[self addObject: key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue