mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 09:04:13 +00:00
Further implementation
This commit is contained in:
parent
5287a62909
commit
2a511cca12
2 changed files with 81 additions and 56 deletions
|
@ -72,7 +72,7 @@ static SEL privateCountOfSel;
|
|||
|
||||
@implementation GSOrderedSetEnumerator
|
||||
|
||||
- (id) initWithSet: (NSOrderedSet*)d
|
||||
- (id) initWithOrderedSet: (NSOrderedSet*)d
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil)
|
||||
|
@ -122,50 +122,6 @@ static Class mutableSetClass;
|
|||
}
|
||||
}
|
||||
|
||||
- (NSArray*) allObjects
|
||||
{
|
||||
GSIMapEnumerator_t enumerator = GSIMapEnumeratorForMap(&map);
|
||||
GSIMapNode node = GSIMapEnumeratorNextNode(&enumerator);
|
||||
NSUInteger i = 0;
|
||||
NSArray *result;
|
||||
GS_BEGINIDBUF(objects, map.nodeCount);
|
||||
|
||||
while (node != 0)
|
||||
{
|
||||
objects[i++] = node->key.obj;
|
||||
node = GSIMapEnumeratorNextNode(&enumerator);
|
||||
}
|
||||
GSIMapEndEnumerator(&enumerator);
|
||||
result = AUTORELEASE([[arrayClass allocWithZone: NSDefaultMallocZone()]
|
||||
initWithObjects: objects count: i]);
|
||||
GS_ENDIDBUF();
|
||||
return result;
|
||||
}
|
||||
|
||||
- (id) anyObject
|
||||
{
|
||||
if (map.nodeCount > 0)
|
||||
{
|
||||
GSIMapBucket bucket = map.buckets;
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (bucket->firstNode)
|
||||
{
|
||||
return bucket->firstNode->key.obj;
|
||||
}
|
||||
else
|
||||
{
|
||||
bucket++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (id) copyWithZone: (NSZone*)z
|
||||
{
|
||||
return RETAIN(self);
|
||||
|
|
|
@ -254,7 +254,6 @@ static Class NSMutableOrderedSet_concrete_class;
|
|||
+ (instancetype) orderedSetWithObjects:(id)firstObject, ...
|
||||
{
|
||||
id set;
|
||||
|
||||
GS_USEIDLIST(firstObject,
|
||||
set = [[self allocWithZone: NSDefaultMallocZone()]
|
||||
initWithObjects: __objects count: __count]);
|
||||
|
@ -264,34 +263,69 @@ static Class NSMutableOrderedSet_concrete_class;
|
|||
+ (instancetype) orderedSetWithObjects:(const id [])objects
|
||||
count:(NSUInteger) count
|
||||
{
|
||||
return nil;
|
||||
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
|
||||
initWithObjects: objects count: count]);
|
||||
}
|
||||
|
||||
+ (instancetype) orderedSetWithOrderedSet:(NSOrderedSet *)aSet
|
||||
{
|
||||
return nil;
|
||||
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
|
||||
initWithSet: aSet]);
|
||||
}
|
||||
|
||||
+ (instancetype) orderedSetWithOrderedSet:(NSOrderedSet *)aSet
|
||||
count:(NSUInteger) count
|
||||
{
|
||||
return nil;
|
||||
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
|
||||
initWithSet: aSet
|
||||
count: count]);
|
||||
}
|
||||
|
||||
+ (instancetype) orderedSetWithSet:(NSSet *)aSet
|
||||
{
|
||||
return nil;
|
||||
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
|
||||
initWithSet: aSet]);
|
||||
}
|
||||
|
||||
+ (instancetype) orderedSetWithSet:(NSSet *)aSet
|
||||
copyItems:(BOOL)flag
|
||||
{
|
||||
return nil;
|
||||
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
|
||||
initWithOrderedSet: aSet
|
||||
copyItems: flag]);
|
||||
}
|
||||
|
||||
// instance methods
|
||||
- (instancetype) initWithArray:(NSArray *)other
|
||||
{
|
||||
unsigned count = [other count];
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
return [self init];
|
||||
}
|
||||
else
|
||||
{
|
||||
GS_BEGINIDBUF(objs, count);
|
||||
|
||||
if ([other isProxy])
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
objs[i] = [other objectAtIndex: i];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
[other getObjects: objs];
|
||||
}
|
||||
self = [self initWithObjects: objs count: count];
|
||||
GS_ENDIDBUF();
|
||||
return self;
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
@ -314,24 +348,59 @@ static Class NSMutableOrderedSet_concrete_class;
|
|||
|
||||
- (instancetype) initWithObjects:(id)firstObject, ...
|
||||
{
|
||||
return nil;
|
||||
id set;
|
||||
|
||||
GS_USEIDLIST(firstObject,
|
||||
set = [[self allocWithZone: NSDefaultMallocZone()]
|
||||
initWithObjects: __objects count: __count]);
|
||||
return AUTORELEASE(set);
|
||||
}
|
||||
|
||||
- (instancetype) initWithObjects:(const id [])objects
|
||||
count:(NSUInteger)count
|
||||
{
|
||||
return nil;
|
||||
self = [self initWithCapacity: count];
|
||||
if (self != nil)
|
||||
{
|
||||
while (count--)
|
||||
{
|
||||
[self addObject: objects[count]];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype) initWithOrderedSet:(NSOrderedSet *)aSet
|
||||
{
|
||||
return nil;
|
||||
return [self initWithOrderedSet: aSet copyItems: NO];
|
||||
}
|
||||
|
||||
- (instancetype) initWithOrderedSet:(NSOrderedSet *)objects
|
||||
- (instancetype) initWithOrderedSet:(NSOrderedSet *)other
|
||||
copyItems:(BOOL)flag
|
||||
{
|
||||
return nil;
|
||||
unsigned c = [other count];
|
||||
id o, e = [other objectEnumerator];
|
||||
unsigned i = 0;
|
||||
GS_BEGINIDBUF(os, c);
|
||||
|
||||
while ((o = [e nextObject]))
|
||||
{
|
||||
if (flag)
|
||||
os[i] = [o copy];
|
||||
else
|
||||
os[i] = o;
|
||||
i++;
|
||||
}
|
||||
self = [self initWithObjects: os count: c];
|
||||
if (flag)
|
||||
{
|
||||
while (i--)
|
||||
{
|
||||
[os[i] release];
|
||||
}
|
||||
}
|
||||
GS_ENDIDBUF();
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype) initWithOrderedSet:(NSOrderedSet *)objects
|
||||
|
|
Loading…
Reference in a new issue