mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 00:11:26 +00:00
Code complete implementation. No tests yet
This commit is contained in:
parent
c4345dc19a
commit
372030f056
1 changed files with 75 additions and 50 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue