mirror of
https://github.com/gnustep/libs-base.git
synced 2025-06-04 18:40:47 +00:00
Merged changes from other author
This commit is contained in:
commit
80843a9e4b
3 changed files with 424 additions and 501 deletions
|
@ -40,14 +40,8 @@
|
||||||
#import "GSDispatch.h"
|
#import "GSDispatch.h"
|
||||||
#import "GSSorting.h"
|
#import "GSSorting.h"
|
||||||
|
|
||||||
#define GSI_ARRAY_TYPE NSRange
|
|
||||||
#define GSI_ARRAY_NO_RELEASE 0
|
|
||||||
#define GSI_ARRAY_NO_RETAIN 0
|
|
||||||
#define GSI_ARRAY_TYPES GSUNION_OBJ
|
#define GSI_ARRAY_TYPES GSUNION_OBJ
|
||||||
|
|
||||||
#define GSI_ARRAY_RELEASE(A, X) [(X).obj release]
|
|
||||||
#define GSI_ARRAY_RETAIN(A, X) [(X).obj retain]
|
|
||||||
|
|
||||||
#import "GNUstepBase/GSIArray.h"
|
#import "GNUstepBase/GSIArray.h"
|
||||||
|
|
||||||
@interface GSOrderedSet : NSOrderedSet
|
@interface GSOrderedSet : NSOrderedSet
|
||||||
|
@ -125,7 +119,9 @@
|
||||||
GSIArrayItem item;
|
GSIArrayItem item;
|
||||||
|
|
||||||
if (current == 0)
|
if (current == 0)
|
||||||
|
{
|
||||||
return nil;
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
item = GSIArrayItemAtIndex(&set->array, --current);
|
item = GSIArrayItemAtIndex(&set->array, --current);
|
||||||
return (id)(item.obj);
|
return (id)(item.obj);
|
||||||
|
@ -230,7 +226,6 @@ static Class mutableSetClass;
|
||||||
if (![self containsObject: obj])
|
if (![self containsObject: obj])
|
||||||
{
|
{
|
||||||
GSIArrayAddItem(&array, item);
|
GSIArrayAddItem(&array, item);
|
||||||
RETAIN(obj);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
|
@ -248,11 +243,6 @@ static Class mutableSetClass;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) addObject: (id)anObject
|
|
||||||
{
|
|
||||||
[self insertObject: anObject atIndex: [self count]];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) insertObject: (id)object atIndex: (NSUInteger)index
|
- (void) insertObject: (id)object atIndex: (NSUInteger)index
|
||||||
{
|
{
|
||||||
GSIArrayItem item;
|
GSIArrayItem item;
|
||||||
|
@ -267,7 +257,6 @@ static Class mutableSetClass;
|
||||||
{
|
{
|
||||||
item.obj = object;
|
item.obj = object;
|
||||||
GSIArrayInsertItem(&array, item, index);
|
GSIArrayInsertItem(&array, item, index);
|
||||||
RETAIN(object);
|
|
||||||
_version++;
|
_version++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -279,13 +268,6 @@ static Class mutableSetClass;
|
||||||
GSIArrayRemoveItemAtIndex(&array, index);
|
GSIArrayRemoveItemAtIndex(&array, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) replaceObjectAtIndex: (NSUInteger)index
|
|
||||||
withObject: (id)obj
|
|
||||||
{
|
|
||||||
[self removeObjectAtIndex: index];
|
|
||||||
[self insertObject: obj atIndex: index];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (id) init
|
- (id) init
|
||||||
{
|
{
|
||||||
return [self initWithCapacity: 0];
|
return [self initWithCapacity: 0];
|
||||||
|
@ -329,4 +311,3 @@ static Class mutableSetClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -62,12 +62,9 @@ static Class NSMutableOrderedSet_abstract_class;
|
||||||
static Class NSOrderedSet_concrete_class;
|
static Class NSOrderedSet_concrete_class;
|
||||||
static Class NSMutableOrderedSet_concrete_class;
|
static Class NSMutableOrderedSet_concrete_class;
|
||||||
|
|
||||||
static SEL addSel;
|
|
||||||
static SEL countSel;
|
|
||||||
static SEL eqSel;
|
static SEL eqSel;
|
||||||
static SEL oaiSel;
|
static SEL oaiSel;
|
||||||
static SEL remSel;
|
static SEL remSel;
|
||||||
static SEL rlSel;
|
|
||||||
|
|
||||||
+ (id) allocWithZone: (NSZone*)z
|
+ (id) allocWithZone: (NSZone*)z
|
||||||
{
|
{
|
||||||
|
@ -87,12 +84,9 @@ static SEL rlSel;
|
||||||
{
|
{
|
||||||
[self setVersion: 1];
|
[self setVersion: 1];
|
||||||
|
|
||||||
addSel = @selector(addObject:);
|
|
||||||
countSel = @selector(count);
|
|
||||||
eqSel = @selector(isEqual:);
|
eqSel = @selector(isEqual:);
|
||||||
oaiSel = @selector(objectAtIndex:);
|
oaiSel = @selector(objectAtIndex:);
|
||||||
remSel = @selector(removeObjectAtIndex:);
|
remSel = @selector(removeObjectAtIndex:);
|
||||||
rlSel = @selector(removeLastObject);
|
|
||||||
|
|
||||||
NSOrderedSet_abstract_class = self;
|
NSOrderedSet_abstract_class = self;
|
||||||
NSOrderedSet_concrete_class = [GSOrderedSet class];
|
NSOrderedSet_concrete_class = [GSOrderedSet class];
|
||||||
|
@ -100,6 +94,29 @@ static SEL rlSel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void) _raiseRangeExceptionWithIndex: (NSUInteger)index from: (SEL)sel
|
||||||
|
{
|
||||||
|
NSDictionary *info;
|
||||||
|
NSException *exception;
|
||||||
|
NSString *reason;
|
||||||
|
NSUInteger count = [self count];
|
||||||
|
|
||||||
|
info = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||||
|
[NSNumber numberWithUnsignedInteger: index], @"Index",
|
||||||
|
[NSNumber numberWithUnsignedInteger: count], @"Count",
|
||||||
|
self, @"GSMutableSet", nil, nil];
|
||||||
|
|
||||||
|
reason = [NSString stringWithFormat:
|
||||||
|
@"Index %"PRIuPTR" is out of range %d (in '%@')",
|
||||||
|
index, count, NSStringFromSelector(sel)];
|
||||||
|
|
||||||
|
exception = [NSException exceptionWithName: NSRangeException
|
||||||
|
reason: reason
|
||||||
|
userInfo: info];
|
||||||
|
[exception raise];
|
||||||
|
}
|
||||||
|
|
||||||
- (Class) classForCoder
|
- (Class) classForCoder
|
||||||
{
|
{
|
||||||
return NSOrderedSet_abstract_class;
|
return NSOrderedSet_abstract_class;
|
||||||
|
@ -108,23 +125,6 @@ static SEL rlSel;
|
||||||
// NSCoding
|
// NSCoding
|
||||||
- (instancetype) initWithCoder: (NSCoder *)coder
|
- (instancetype) initWithCoder: (NSCoder *)coder
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
Class c;
|
|
||||||
|
|
||||||
c = object_getClass(self);
|
|
||||||
if (c == NSOrderedSet_abstract_class)
|
|
||||||
{
|
|
||||||
DESTROY(self);
|
|
||||||
self = [NSOrderedSet_concrete_class allocWithZone: NSDefaultMallocZone()];
|
|
||||||
return [self initWithCoder: coder];
|
|
||||||
}
|
|
||||||
else if (c == NSMutableOrderedSet_abstract_class)
|
|
||||||
{
|
|
||||||
DESTROY(self);
|
|
||||||
self = [NSMutableOrderedSet_concrete_class allocWithZone: NSDefaultMallocZone()];
|
|
||||||
return [self initWithCoder: coder];
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
if ([coder allowsKeyedCoding])
|
if ([coder allowsKeyedCoding])
|
||||||
{
|
{
|
||||||
id array;
|
id array;
|
||||||
|
@ -265,16 +265,7 @@ static SEL rlSel;
|
||||||
*/
|
*/
|
||||||
if (count > 0)
|
if (count > 0)
|
||||||
{
|
{
|
||||||
// IMP imp = [self methodForSelector: @selector(objectAtIndex:)];
|
|
||||||
// int i;
|
|
||||||
// int p = state->state;
|
|
||||||
|
|
||||||
|
|
||||||
[self getObjects: stackbuf range: NSMakeRange(state->state, count)];
|
[self getObjects: stackbuf range: NSMakeRange(state->state, count)];
|
||||||
/*for (i = 0; i < count; i++, p++)
|
|
||||||
{
|
|
||||||
stackbuf[i] = (*imp)(self, @selector(objectAtIndex:), p);
|
|
||||||
}*/
|
|
||||||
state->state += count;
|
state->state += count;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -520,9 +511,13 @@ static SEL rlSel;
|
||||||
while ((o = [e nextObject]))
|
while ((o = [e nextObject]))
|
||||||
{
|
{
|
||||||
if (flag)
|
if (flag)
|
||||||
|
{
|
||||||
os[i] = [o copy];
|
os[i] = [o copy];
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
os[i] = o;
|
os[i] = o;
|
||||||
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
self = [self initWithObjects: os count: c];
|
self = [self initWithObjects: os count: c];
|
||||||
|
@ -553,9 +548,13 @@ static SEL rlSel;
|
||||||
if (i >= loc && j < len)
|
if (i >= loc && j < len)
|
||||||
{
|
{
|
||||||
if (flag)
|
if (flag)
|
||||||
|
{
|
||||||
os[i] = [o copy];
|
os[i] = [o copy];
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
os[i] = o;
|
os[i] = o;
|
||||||
|
}
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
|
@ -593,9 +592,13 @@ static SEL rlSel;
|
||||||
while ((o = [e nextObject]))
|
while ((o = [e nextObject]))
|
||||||
{
|
{
|
||||||
if (flag)
|
if (flag)
|
||||||
|
{
|
||||||
os[i] = [o copy];
|
os[i] = [o copy];
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
os[i] = o;
|
os[i] = o;
|
||||||
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
self = [self initWithObjects: os count: c];
|
self = [self initWithObjects: os count: c];
|
||||||
|
@ -686,7 +689,9 @@ static SEL rlSel;
|
||||||
{
|
{
|
||||||
NSUInteger count = [self count];
|
NSUInteger count = [self count];
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
|
{
|
||||||
return nil;
|
return nil;
|
||||||
|
}
|
||||||
return [self objectAtIndex: 0];
|
return [self objectAtIndex: 0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -694,7 +699,9 @@ static SEL rlSel;
|
||||||
{
|
{
|
||||||
NSUInteger count = [self count];
|
NSUInteger count = [self count];
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
|
{
|
||||||
return nil;
|
return nil;
|
||||||
|
}
|
||||||
return [self objectAtIndex: count - 1];
|
return [self objectAtIndex: count - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1003,14 +1010,18 @@ static SEL rlSel;
|
||||||
|
|
||||||
- (void) getObjects: (__unsafe_unretained id[])aBuffer range: (NSRange)aRange
|
- (void) getObjects: (__unsafe_unretained id[])aBuffer range: (NSRange)aRange
|
||||||
{
|
{
|
||||||
NSUInteger i, j = 0, c = [self count], e = aRange.location + aRange.length;
|
NSUInteger i, j = 0;
|
||||||
|
NSUInteger c = [self count];
|
||||||
|
NSUInteger e = aRange.location + aRange.length;
|
||||||
IMP get = [self methodForSelector: oaiSel];
|
IMP get = [self methodForSelector: oaiSel];
|
||||||
|
|
||||||
GS_RANGE_CHECK(aRange, c);
|
GS_RANGE_CHECK(aRange, c);
|
||||||
|
|
||||||
for (i = aRange.location; i < e; i++)
|
for (i = aRange.location; i < e; i++)
|
||||||
|
{
|
||||||
aBuffer[j++] = (*get)(self, oaiSel, i);
|
aBuffer[j++] = (*get)(self, oaiSel, i);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Key-Value Observing Support
|
// Key-Value Observing Support
|
||||||
|
|
||||||
|
@ -1019,41 +1030,32 @@ static SEL rlSel;
|
||||||
options: (NSKeyValueObservingOptions)options
|
options: (NSKeyValueObservingOptions)options
|
||||||
context: (void *)context
|
context: (void *)context
|
||||||
{
|
{
|
||||||
NSException *exception = nil;
|
[[NSException exceptionWithName: NSGenericException
|
||||||
NSString *reason = @"NSOrderedSet does not support KVO";
|
reason: @"NSOrderedSet does not support KVO"
|
||||||
exception = [NSException exceptionWithName: NSGenericException
|
userInfo: nil] raise];
|
||||||
reason: reason
|
|
||||||
userInfo: nil];
|
|
||||||
[exception raise];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) removeObserver: (NSObject *)observer
|
- (void) removeObserver: (NSObject *)observer
|
||||||
forKeyPath: (NSString *)keyPath
|
forKeyPath: (NSString *)keyPath
|
||||||
{
|
{
|
||||||
NSException *exception = nil;
|
[[NSException exceptionWithName: NSGenericException
|
||||||
NSString *reason = @"NSOrderedSet does not support KVO";
|
reason: @"NSOrderedSet does not support KVO"
|
||||||
exception = [NSException exceptionWithName: NSGenericException
|
userInfo: nil] raise];
|
||||||
reason: reason
|
|
||||||
userInfo: nil];
|
|
||||||
[exception raise];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) removeObserver: (NSObject *)observer
|
- (void) removeObserver: (NSObject *)observer
|
||||||
forKeyPath: (NSString *)keyPath
|
forKeyPath: (NSString *)keyPath
|
||||||
context: (void *)context
|
context: (void *)context
|
||||||
{
|
{
|
||||||
NSException *exception = nil;
|
[[NSException exceptionWithName: NSGenericException
|
||||||
NSString *reason = @"NSOrderedSet does not support KVO";
|
reason: @"NSOrderedSet does not support KVO"
|
||||||
exception = [NSException exceptionWithName: NSGenericException
|
userInfo: nil] raise];
|
||||||
reason: reason
|
|
||||||
userInfo: nil];
|
|
||||||
[exception raise];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Key value coding support
|
// Key value coding support
|
||||||
- (void) setValue: (id)value forKey: (NSString*)key
|
- (void) setValue: (id)value forKey: (NSString*)key
|
||||||
{
|
{
|
||||||
volatile id object = nil;
|
id object;
|
||||||
NSEnumerator *e = [self objectEnumerator];
|
NSEnumerator *e = [self objectEnumerator];
|
||||||
|
|
||||||
while ((object = [e nextObject]) != nil)
|
while ((object = [e nextObject]) != nil)
|
||||||
|
@ -1066,7 +1068,7 @@ static SEL rlSel;
|
||||||
- (id) valueForKey: (NSString*)key
|
- (id) valueForKey: (NSString*)key
|
||||||
{
|
{
|
||||||
NSEnumerator *e = [self objectEnumerator];
|
NSEnumerator *e = [self objectEnumerator];
|
||||||
id object = nil;
|
id object;
|
||||||
NSMutableSet *results = [NSMutableSet setWithCapacity: [self count]];
|
NSMutableSet *results = [NSMutableSet setWithCapacity: [self count]];
|
||||||
|
|
||||||
while ((object = [e nextObject]) != nil)
|
while ((object = [e nextObject]) != nil)
|
||||||
|
@ -1074,7 +1076,9 @@ static SEL rlSel;
|
||||||
id result = [object valueForKey: key];
|
id result = [object valueForKey: key];
|
||||||
|
|
||||||
if (result == nil)
|
if (result == nil)
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
[results addObject: result];
|
[results addObject: result];
|
||||||
}
|
}
|
||||||
|
@ -1101,15 +1105,18 @@ static SEL rlSel;
|
||||||
- (BOOL) isEqual: (id)other
|
- (BOOL) isEqual: (id)other
|
||||||
{
|
{
|
||||||
if ([other isKindOfClass: [NSOrderedSet class]])
|
if ([other isKindOfClass: [NSOrderedSet class]])
|
||||||
|
{
|
||||||
return [self isEqualToOrderedSet: other];
|
return [self isEqualToOrderedSet: other];
|
||||||
|
}
|
||||||
|
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set operations
|
// Set operations
|
||||||
- (BOOL) intersectsOrderedSet: (NSOrderedSet *)otherSet
|
- (BOOL) intersectsOrderedSet: (NSOrderedSet *)otherSet
|
||||||
{
|
{
|
||||||
id o = nil;
|
id o;
|
||||||
NSEnumerator *e = nil;
|
NSEnumerator *e;
|
||||||
|
|
||||||
// -1. If this set is empty, this method should return NO.
|
// -1. If this set is empty, this method should return NO.
|
||||||
if ([self count] == 0)
|
if ([self count] == 0)
|
||||||
|
@ -1146,7 +1153,7 @@ static SEL rlSel;
|
||||||
|
|
||||||
- (BOOL) isSubsetOfOrderedSet: (NSOrderedSet *)otherSet
|
- (BOOL) isSubsetOfOrderedSet: (NSOrderedSet *)otherSet
|
||||||
{
|
{
|
||||||
id so = nil, oo = nil;
|
id so, oo;
|
||||||
NSEnumerator *selfEnum = [self objectEnumerator];
|
NSEnumerator *selfEnum = [self objectEnumerator];
|
||||||
NSEnumerator *otherEnum = [otherSet objectEnumerator];
|
NSEnumerator *otherEnum = [otherSet objectEnumerator];
|
||||||
NSUInteger l = [self count];
|
NSUInteger l = [self count];
|
||||||
|
@ -1181,19 +1188,30 @@ static SEL rlSel;
|
||||||
|
|
||||||
- (BOOL) isSubsetOfSet: (NSSet *)otherSet
|
- (BOOL) isSubsetOfSet: (NSSet *)otherSet
|
||||||
{
|
{
|
||||||
id o = nil, e = nil;
|
id o, e;
|
||||||
|
NSUInteger l = [self count];
|
||||||
|
|
||||||
// -1. If this set is empty, this method should return NO.
|
// -1. If this set is empty, this method should return YES.
|
||||||
if ([self count] == 0)
|
if (l == 0)
|
||||||
return NO;
|
{
|
||||||
|
return YES;
|
||||||
// 0. Loop for all members in otherSet
|
}
|
||||||
e = [otherSet objectEnumerator];
|
|
||||||
while ((o = [e nextObject])) // 1. pick a member from otherSet.
|
// If count of set is more than otherSet it's not a subset
|
||||||
|
if (l > [otherSet count])
|
||||||
{
|
{
|
||||||
if ([self containsObject: o] == NO) // 2. check the member is in this set(self).
|
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 0. Loop for all members in self
|
||||||
|
e = [self objectEnumerator];
|
||||||
|
while ((o = [e nextObject])) // 1. pick a member from self.
|
||||||
|
{
|
||||||
|
if ([otherSet containsObject: o] == NO) // 2. check the member is in otherset.
|
||||||
|
{
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
}
|
||||||
return YES; // if all members are in set.
|
return YES; // if all members are in set.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1319,28 +1337,6 @@ static SEL rlSel;
|
||||||
return NSMutableOrderedSet_abstract_class;
|
return NSMutableOrderedSet_abstract_class;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) _raiseRangeExceptionWithIndex: (NSUInteger)index from: (SEL)sel
|
|
||||||
{
|
|
||||||
NSDictionary *info;
|
|
||||||
NSException *exception;
|
|
||||||
NSString *reason;
|
|
||||||
NSUInteger count = [self count];
|
|
||||||
|
|
||||||
info = [NSDictionary dictionaryWithObjectsAndKeys:
|
|
||||||
[NSNumber numberWithUnsignedInteger: index], @"Index",
|
|
||||||
[NSNumber numberWithUnsignedInteger: count], @"Count",
|
|
||||||
self, @"GSMutableSet", nil, nil];
|
|
||||||
|
|
||||||
reason = [NSString stringWithFormat:
|
|
||||||
@"Index %"PRIuPTR" is out of range %d (in '%@')",
|
|
||||||
index, count, NSStringFromSelector(sel)];
|
|
||||||
|
|
||||||
exception = [NSException exceptionWithName: NSRangeException
|
|
||||||
reason: reason
|
|
||||||
userInfo: info];
|
|
||||||
[exception raise];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (instancetype) initWithCapacity: (NSUInteger)capacity
|
- (instancetype) initWithCapacity: (NSUInteger)capacity
|
||||||
{
|
{
|
||||||
self = [self init];
|
self = [self init];
|
||||||
|
@ -1359,7 +1355,7 @@ static SEL rlSel;
|
||||||
|
|
||||||
- (void) addObject: (id)anObject
|
- (void) addObject: (id)anObject
|
||||||
{
|
{
|
||||||
[self subclassResponsibility: _cmd];
|
[self insertObject: anObject atIndex: [self count]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) addObjects: (const id[])objects count: (NSUInteger)count
|
- (void) addObjects: (const id[])objects count: (NSUInteger)count
|
||||||
|
@ -1415,45 +1411,18 @@ static SEL rlSel;
|
||||||
|
|
||||||
- (void) removeObject: (id)anObject
|
- (void) removeObject: (id)anObject
|
||||||
{
|
{
|
||||||
NSUInteger i;
|
NSUInteger index;
|
||||||
|
|
||||||
if (anObject == nil)
|
if (anObject == nil)
|
||||||
{
|
{
|
||||||
NSWarnMLog(@"attempt to remove nil object");
|
NSWarnMLog(@"attempt to remove nil object");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
i = [self count];
|
|
||||||
if (i > 0)
|
|
||||||
{
|
|
||||||
IMP rem = 0;
|
|
||||||
IMP get = [self methodForSelector: oaiSel];
|
|
||||||
BOOL (*eq)(id, SEL, id)
|
|
||||||
= (BOOL (*)(id, SEL, id))[anObject methodForSelector: eqSel];
|
|
||||||
|
|
||||||
while (i-- > 0)
|
index = [self indexOfObject: anObject];
|
||||||
|
if (NSNotFound != index)
|
||||||
{
|
{
|
||||||
id o = (*get)(self, oaiSel, i);
|
[self removeObjectAtIndex: index];
|
||||||
|
|
||||||
if (o == anObject || (*eq)(anObject, eqSel, o) == YES)
|
|
||||||
{
|
|
||||||
if (rem == 0)
|
|
||||||
{
|
|
||||||
rem = [self methodForSelector: remSel];
|
|
||||||
/*
|
|
||||||
* We need to retain the object so that when we remove the
|
|
||||||
* first equal object we don't get left with a bad object
|
|
||||||
* pointer for later comparisons.
|
|
||||||
*/
|
|
||||||
// RETAIN(anObject);
|
|
||||||
}
|
|
||||||
(*rem)(self, remSel, i);
|
|
||||||
break; // since this is a set we should only have one copy...
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//if (rem != 0)
|
|
||||||
// {
|
|
||||||
// RELEASE(anObject);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1462,61 +1431,6 @@ static SEL rlSel;
|
||||||
[self subclassResponsibility: _cmd];
|
[self subclassResponsibility: _cmd];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
- (void) _removeObjectsFromIndices: (NSUInteger*)indices
|
|
||||||
numIndices: (NSUInteger)count
|
|
||||||
{
|
|
||||||
if (count > 0)
|
|
||||||
{
|
|
||||||
NSUInteger to = 0;
|
|
||||||
NSUInteger from = 0;
|
|
||||||
NSUInteger i;
|
|
||||||
GS_BEGINITEMBUF(sorted, count, NSUInteger);
|
|
||||||
|
|
||||||
while (from < count)
|
|
||||||
{
|
|
||||||
NSUInteger val = indices[from++];
|
|
||||||
|
|
||||||
i = to;
|
|
||||||
while (i > 0 && sorted[i-1] > val)
|
|
||||||
{
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
if (i == to)
|
|
||||||
{
|
|
||||||
sorted[to++] = val;
|
|
||||||
}
|
|
||||||
else if (sorted[i] != val)
|
|
||||||
{
|
|
||||||
NSUInteger j = to++;
|
|
||||||
|
|
||||||
if (sorted[i] < val)
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
while (j > i)
|
|
||||||
{
|
|
||||||
sorted[j] = sorted[j-1];
|
|
||||||
j--;
|
|
||||||
}
|
|
||||||
sorted[i] = val;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (to > 0)
|
|
||||||
{
|
|
||||||
IMP rem = [self methodForSelector: remSel];
|
|
||||||
|
|
||||||
while (to--)
|
|
||||||
{
|
|
||||||
(*rem)(self, remSel, sorted[to]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
GS_ENDITEMBUF();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
- (void) _removeObjectsFromIndices: (NSUInteger*)indices
|
- (void) _removeObjectsFromIndices: (NSUInteger*)indices
|
||||||
numIndices: (NSUInteger)count
|
numIndices: (NSUInteger)count
|
||||||
{
|
{
|
||||||
|
@ -1542,8 +1456,15 @@ static SEL rlSel;
|
||||||
maxCount: count
|
maxCount: count
|
||||||
inIndexRange: NULL];
|
inIndexRange: NULL];
|
||||||
|
|
||||||
[self _removeObjectsFromIndices: indexArray
|
if (count > 0)
|
||||||
numIndices: count];
|
{
|
||||||
|
IMP rem = [self methodForSelector: remSel];
|
||||||
|
|
||||||
|
while (count--)
|
||||||
|
{
|
||||||
|
(*rem)(self, remSel, indexArray[count]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) removeObjectsInArray: (NSArray *)otherArray
|
- (void) removeObjectsInArray: (NSArray *)otherArray
|
||||||
|
@ -1570,7 +1491,9 @@ static SEL rlSel;
|
||||||
i = aRange.location + aRange.length;
|
i = aRange.location + aRange.length;
|
||||||
|
|
||||||
if (c < i)
|
if (c < i)
|
||||||
|
{
|
||||||
i = c;
|
i = c;
|
||||||
|
}
|
||||||
|
|
||||||
if (i > s)
|
if (i > s)
|
||||||
{
|
{
|
||||||
|
@ -1596,10 +1519,11 @@ static SEL rlSel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)replaceObjectAtIndex:(NSUInteger)index // required override...
|
- (void) replaceObjectAtIndex: (NSUInteger)index
|
||||||
withObject: (id)object
|
withObject: (id)object
|
||||||
{
|
{
|
||||||
[self subclassResponsibility: _cmd];
|
[self removeObjectAtIndex: index];
|
||||||
|
[self insertObject: object atIndex: index];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) replaceObjectsAtIndexes: (NSIndexSet *)indexes
|
- (void) replaceObjectsAtIndexes: (NSIndexSet *)indexes
|
||||||
|
@ -1633,8 +1557,11 @@ static SEL rlSel;
|
||||||
NSUInteger i = count;
|
NSUInteger i = count;
|
||||||
|
|
||||||
if (count < (aRange.location + aRange.length))
|
if (count < (aRange.location + aRange.length))
|
||||||
|
{
|
||||||
[NSException raise: NSRangeException
|
[NSException raise: NSRangeException
|
||||||
format: @"Replacing objects beyond end of const[] id."];
|
format: @"Replacing objects beyond end of const[] id."];
|
||||||
|
}
|
||||||
|
|
||||||
[self removeObjectsInRange: aRange];
|
[self removeObjectsInRange: aRange];
|
||||||
|
|
||||||
while (i-- > 0)
|
while (i-- > 0)
|
||||||
|
@ -1696,7 +1623,6 @@ static SEL rlSel;
|
||||||
withObjectAtIndex: (NSUInteger)otherIndex
|
withObjectAtIndex: (NSUInteger)otherIndex
|
||||||
{
|
{
|
||||||
NSUInteger count = [self count];
|
NSUInteger count = [self count];
|
||||||
|
|
||||||
if (index >= count)
|
if (index >= count)
|
||||||
{
|
{
|
||||||
[self _raiseRangeExceptionWithIndex: index from: _cmd];
|
[self _raiseRangeExceptionWithIndex: index from: _cmd];
|
||||||
|
@ -1707,28 +1633,26 @@ static SEL rlSel;
|
||||||
}
|
}
|
||||||
if (index != otherIndex)
|
if (index != otherIndex)
|
||||||
{
|
{
|
||||||
NSUInteger min = 0, max = 0;
|
NSUInteger low, high;
|
||||||
id tmpMax = nil, tmpMin = nil;
|
id obj1, obj2;
|
||||||
|
|
||||||
if (index > otherIndex)
|
if (index > otherIndex)
|
||||||
{
|
{
|
||||||
min = otherIndex;
|
high = index;
|
||||||
max = index;
|
low = otherIndex;
|
||||||
}
|
}
|
||||||
else // since we know they are not equal
|
else
|
||||||
{
|
{
|
||||||
min = index;
|
high = otherIndex;
|
||||||
max = otherIndex;
|
low = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpMax = [self objectAtIndex: max];
|
obj1 = [self objectAtIndex: low];
|
||||||
[self removeObjectAtIndex: max];
|
obj2 = [self objectAtIndex: high];
|
||||||
tmpMin = [self objectAtIndex: min];
|
[self removeObjectAtIndex: high];
|
||||||
[self removeObjectAtIndex: min];
|
[self removeObjectAtIndex: low];
|
||||||
|
[self insertObject: obj2 atIndex: low];
|
||||||
// Exchange objects...
|
[self insertObject: obj1 atIndex: high];
|
||||||
[self insertObject: tmpMax atIndex: min];
|
|
||||||
[self insertObject: tmpMin atIndex: max];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1806,7 +1730,7 @@ static SEL rlSel;
|
||||||
[self removeAllObjects];
|
[self removeAllObjects];
|
||||||
[self addObjectsFromArray: res];
|
[self addObjectsFromArray: res];
|
||||||
|
|
||||||
// RELEASE(res);
|
RELEASE(res);
|
||||||
GS_ENDIDBUF();
|
GS_ENDIDBUF();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1815,6 +1739,7 @@ static SEL rlSel;
|
||||||
options: (NSSortOptions)options
|
options: (NSSortOptions)options
|
||||||
usingComparator: (NSComparator)comparator
|
usingComparator: (NSComparator)comparator
|
||||||
{
|
{
|
||||||
|
// FIXME: Implementation missing
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) intersectOrderedSet: (NSOrderedSet *)other
|
- (void) intersectOrderedSet: (NSOrderedSet *)other
|
||||||
|
|
|
@ -122,6 +122,7 @@ int main()
|
||||||
NSMutableOrderedSet *mutableTest1, *mutableTest2;
|
NSMutableOrderedSet *mutableTest1, *mutableTest2;
|
||||||
NSMutableArray *testObjs = [NSMutableArray new];
|
NSMutableArray *testObjs = [NSMutableArray new];
|
||||||
NSData *data = [stringData dataUsingEncoding: NSUTF8StringEncoding];
|
NSData *data = [stringData dataUsingEncoding: NSUTF8StringEncoding];
|
||||||
|
NSMutableSet *testSet;
|
||||||
|
|
||||||
testObj = [NSOrderedSet new];
|
testObj = [NSOrderedSet new];
|
||||||
[testObjs addObject: testObj];
|
[testObjs addObject: testObj];
|
||||||
|
@ -145,12 +146,6 @@ int main()
|
||||||
PASS(testObj != nil && [testObj count] == 1,
|
PASS(testObj != nil && [testObj count] == 1,
|
||||||
"cannot create an ordered set with multiple like elements");
|
"cannot create an ordered set with multiple like elements");
|
||||||
|
|
||||||
id objs2[] = {@"Hello"};
|
|
||||||
testObj = [NSOrderedSet orderedSetWithObjects: objs2 count: 2];
|
|
||||||
[testObjs addObject: testObj];
|
|
||||||
PASS(testObj != nil && [testObj count] == 1,
|
|
||||||
"Does not throw exception when count != to number of elements");
|
|
||||||
|
|
||||||
NSMutableArray *arr = [NSMutableArray array];
|
NSMutableArray *arr = [NSMutableArray array];
|
||||||
[arr addObject: @"Hello"];
|
[arr addObject: @"Hello"];
|
||||||
[arr addObject: @"World"];
|
[arr addObject: @"World"];
|
||||||
|
@ -228,6 +223,13 @@ int main()
|
||||||
PASS(isSubset,
|
PASS(isSubset,
|
||||||
"mutableTest2 is subset of mutableTest1");
|
"mutableTest2 is subset of mutableTest1");
|
||||||
|
|
||||||
|
testSet = [NSMutableSet set];
|
||||||
|
[testSet addObject: o7];
|
||||||
|
[testSet addObject: o8];
|
||||||
|
isSubset = [mutableTest2 isSubsetOfSet: testSet];
|
||||||
|
PASS(isSubset,
|
||||||
|
"mutableTest2 is subset of testSet");
|
||||||
|
|
||||||
id o9 = @"Hello";
|
id o9 = @"Hello";
|
||||||
id o10 = @"World";
|
id o10 = @"World";
|
||||||
id o11 = @"Ready";
|
id o11 = @"Ready";
|
||||||
|
@ -242,6 +244,12 @@ int main()
|
||||||
PASS(isSubset == NO,
|
PASS(isSubset == NO,
|
||||||
"mutableTest2 is not subset of mutableTest1");
|
"mutableTest2 is not subset of mutableTest1");
|
||||||
|
|
||||||
|
testSet = [NSMutableSet set];
|
||||||
|
[testSet addObject: o9];
|
||||||
|
isSubset = [mutableTest2 isSubsetOfSet: testSet];
|
||||||
|
PASS(isSubset == NO,
|
||||||
|
"mutableTest2 is not subset of testSet");
|
||||||
|
|
||||||
o9 = @"Hello";
|
o9 = @"Hello";
|
||||||
o10 = @"World";
|
o10 = @"World";
|
||||||
o11 = @"Ready";
|
o11 = @"Ready";
|
||||||
|
@ -260,6 +268,15 @@ int main()
|
||||||
PASS(isSubset,
|
PASS(isSubset,
|
||||||
"mutableTest2 is subset of mutableTest1");
|
"mutableTest2 is subset of mutableTest1");
|
||||||
|
|
||||||
|
testSet = [NSMutableSet set];
|
||||||
|
[testSet addObject: o9];
|
||||||
|
[testSet addObject: o10];
|
||||||
|
[testSet addObject: o12];
|
||||||
|
[testSet addObject: o11];
|
||||||
|
isSubset = [mutableTest2 isSubsetOfSet: testSet];
|
||||||
|
PASS(isSubset,
|
||||||
|
"mutableTest2 is subset of testSet");
|
||||||
|
|
||||||
o9 = @"Hello";
|
o9 = @"Hello";
|
||||||
o10 = @"World";
|
o10 = @"World";
|
||||||
o11 = @"Ready";
|
o11 = @"Ready";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue