mirror of
https://github.com/gnustep/libs-base.git
synced 2025-06-01 09:02:01 +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);
|
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
|
- (void) dealloc
|
||||||
{
|
{
|
||||||
GSIArrayEmpty(&array);
|
GSIArrayEmpty(&array);
|
||||||
|
@ -161,30 +140,6 @@ static Class mutableSetClass;
|
||||||
return [self initWithObjects: 0 count: 0];
|
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
|
- (NSEnumerator*) objectEnumerator
|
||||||
{
|
{
|
||||||
return AUTORELEASE([[GSOrderedSetEnumerator alloc] initWithOrderedSet: self]);
|
return AUTORELEASE([[GSOrderedSetEnumerator alloc] initWithOrderedSet: self]);
|
||||||
|
@ -220,6 +175,62 @@ static Class mutableSetClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Put required overrides here...
|
// 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
|
@end
|
||||||
|
|
||||||
|
@ -248,6 +259,25 @@ static Class mutableSetClass;
|
||||||
_version++;
|
_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
|
- (id) init
|
||||||
{
|
{
|
||||||
return [self initWithCapacity: 0];
|
return [self initWithCapacity: 0];
|
||||||
|
@ -297,11 +327,6 @@ static Class mutableSetClass;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)removeObjectAtIndex:(NSUInteger)index // required override
|
|
||||||
{
|
|
||||||
GSIArrayRemoveItemAtIndex(&array, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSUInteger) countByEnumeratingWithState: (NSFastEnumerationState*)state
|
- (NSUInteger) countByEnumeratingWithState: (NSFastEnumerationState*)state
|
||||||
objects: (id*)stackbuf
|
objects: (id*)stackbuf
|
||||||
count: (NSUInteger)len
|
count: (NSUInteger)len
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue