From 372030f056b2bffb094d5dbd0c38787f49c35d89 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Sat, 8 Jun 2019 08:41:45 -0400 Subject: [PATCH] Code complete implementation. No tests yet --- Source/GSOrderedSet.m | 125 +++++++++++++++++++++++++----------------- 1 file changed, 75 insertions(+), 50 deletions(-) diff --git a/Source/GSOrderedSet.m b/Source/GSOrderedSet.m index 43721101a..4208543ab 100644 --- a/Source/GSOrderedSet.m +++ b/Source/GSOrderedSet.m @@ -124,27 +124,6 @@ static Class mutableSetClass; return RETAIN(self); } -- (NSUInteger) count -{ - return GSIArrayCount(&array); -} - -- (BOOL) containsObject: (id)anObject -{ - NSUInteger i = 0; - - for (i = 0; i < [self count]; i++) - { - id obj = [self objectAtIndex: i]; - if([anObject isEqual: obj]) - { - return YES; - } - } - - return NO; -} - - (void) dealloc { GSIArrayEmpty(&array); @@ -161,30 +140,6 @@ static Class mutableSetClass; return [self initWithObjects: 0 count: 0]; } -/* Designated initialiser */ -- (id) initWithObjects: (const id*)objs count: (NSUInteger)c -{ - NSUInteger i; - - GSIArrayInitWithZoneAndCapacity(&array, [self zone], c); - for (i = 0; i < c; i++) - { - id obj = objs[i]; - GSIArrayItem item; - - if (objs[i] == nil) - { - DESTROY(self); - [NSException raise: NSInvalidArgumentException - format: @"Tried to init set with nil value"]; - } - - item.obj = obj; - GSIArrayAddItem(&array, item); - } - return self; -} - - (NSEnumerator*) objectEnumerator { return AUTORELEASE([[GSOrderedSetEnumerator alloc] initWithOrderedSet: self]); @@ -220,6 +175,62 @@ static Class mutableSetClass; } // Put required overrides here... +- (NSUInteger) count +{ + return GSIArrayCount(&array); +} + +- (id) objectAtIndex: (NSUInteger)index +{ + GSIArrayItem item = GSIArrayItemAtIndex(&array, index); + return item.obj; +} + +- (id) objectAtIndexedSubscript: (NSUInteger)index +{ + return[self objectAtIndex: index]; +} + +- (BOOL) containsObject: (id)anObject +{ + NSUInteger i = 0; + + for (i = 0; i < [self count]; i++) + { + id obj = [self objectAtIndex: i]; + if([anObject isEqual: obj]) + { + return YES; + } + } + + return NO; +} + +/* Designated initialiser */ +- (id) initWithObjects: (const id*)objs count: (NSUInteger)c +{ + NSUInteger i; + + GSIArrayInitWithZoneAndCapacity(&array, [self zone], c); + for (i = 0; i < c; i++) + { + id obj = objs[i]; + GSIArrayItem item; + + if (objs[i] == nil) + { + DESTROY(self); + [NSException raise: NSInvalidArgumentException + format: @"Tried to init set with nil value"]; + } + + item.obj = obj; + GSIArrayAddItem(&array, item); + } + return self; +} + @end @@ -248,6 +259,25 @@ static Class mutableSetClass; _version++; } +- (void) insertObject: (id)object atIndex: (NSUInteger)index +{ + GSIArrayItem item; + item.obj = object; + GSIArrayInsertItem(&array, item, index); +} + +- (void) removeObjectAtIndex: (NSUInteger)index +{ + GSIArrayRemoveItemAtIndex(&array, index); +} + +- (void) replaceObjectAtIndex: (NSUInteger)index + withObject: (id)obj +{ + [self removeObjectAtIndex: index]; + [self insertObject: obj atIndex: index]; +} + - (id) init { return [self initWithCapacity: 0]; @@ -297,11 +327,6 @@ static Class mutableSetClass; return self; } -- (void)removeObjectAtIndex:(NSUInteger)index // required override -{ - GSIArrayRemoveItemAtIndex(&array, index); -} - - (NSUInteger) countByEnumeratingWithState: (NSFastEnumerationState*)state objects: (id*)stackbuf count: (NSUInteger)len