1995-04-03 22:59:20 +00:00
|
|
|
|
/* NSArray - Array object to hold other objects.
|
1998-10-08 13:46:53 +00:00
|
|
|
|
Copyright (C) 1995, 1996, 1998 Free Software Foundation, Inc.
|
1995-04-04 16:01:04 +00:00
|
|
|
|
|
1996-04-17 20:17:45 +00:00
|
|
|
|
Written by: Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
From skeleton by: Adam Fedor <fedor@boulder.colorado.edu>
|
1996-04-16 23:22:08 +00:00
|
|
|
|
Created: March 1995
|
1995-04-04 16:01:04 +00:00
|
|
|
|
|
1998-02-03 14:20:00 +00:00
|
|
|
|
Rewrite by: Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
|
|
|
|
January 1998 - new methods and changes as documented for Rhapsody plus
|
|
|
|
|
changes of array indices to type unsigned, plus major efficiency hacks.
|
|
|
|
|
|
1996-05-12 00:56:10 +00:00
|
|
|
|
This file is part of the GNUstep Base Library.
|
1995-04-04 16:01:04 +00:00
|
|
|
|
|
1995-04-03 22:59:20 +00:00
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
Library General Public License for more details.
|
1995-04-04 16:01:04 +00:00
|
|
|
|
|
1995-04-03 22:59:20 +00:00
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
|
License along with this library; if not, write to the Free
|
|
|
|
|
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
1995-04-04 16:01:04 +00:00
|
|
|
|
*/
|
1995-04-03 22:59:20 +00:00
|
|
|
|
|
1997-11-06 00:51:23 +00:00
|
|
|
|
#include <config.h>
|
1998-12-20 21:27:47 +00:00
|
|
|
|
#include <base/behavior.h>
|
1995-04-17 21:13:20 +00:00
|
|
|
|
#include <Foundation/NSArray.h>
|
1998-10-11 06:26:40 +00:00
|
|
|
|
#include <Foundation/NSCoder.h>
|
1995-04-17 21:13:20 +00:00
|
|
|
|
#include <Foundation/NSString.h>
|
|
|
|
|
#include <Foundation/NSGArray.h>
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
#include <limits.h>
|
1995-07-01 18:38:03 +00:00
|
|
|
|
#include <Foundation/NSUtilities.h>
|
1995-10-22 17:59:25 +00:00
|
|
|
|
#include <Foundation/NSException.h>
|
1998-01-19 15:20:15 +00:00
|
|
|
|
#include <Foundation/NSAutoreleasePool.h>
|
1995-07-01 18:38:03 +00:00
|
|
|
|
|
1998-12-20 21:27:47 +00:00
|
|
|
|
#include <base/fast.x>
|
1998-12-18 17:05:44 +00:00
|
|
|
|
|
1996-03-31 22:23:37 +00:00
|
|
|
|
@class NSArrayEnumerator;
|
|
|
|
|
@class NSArrayEnumeratorReverse;
|
1995-07-01 18:38:03 +00:00
|
|
|
|
|
1996-03-31 22:23:37 +00:00
|
|
|
|
@interface NSArrayNonCore : NSArray
|
1995-07-01 18:38:03 +00:00
|
|
|
|
@end
|
1996-03-31 22:23:37 +00:00
|
|
|
|
@interface NSMutableArrayNonCore : NSMutableArray
|
1995-07-01 18:38:03 +00:00
|
|
|
|
@end
|
|
|
|
|
|
1996-03-31 22:23:37 +00:00
|
|
|
|
static Class NSArray_concrete_class;
|
|
|
|
|
static Class NSMutableArray_concrete_class;
|
1995-07-01 18:38:03 +00:00
|
|
|
|
|
1996-03-31 22:23:37 +00:00
|
|
|
|
|
|
|
|
|
@implementation NSArray
|
1995-07-01 18:38:03 +00:00
|
|
|
|
|
1996-03-31 22:23:37 +00:00
|
|
|
|
+ (void) initialize
|
1995-07-01 18:38:03 +00:00
|
|
|
|
{
|
1996-03-31 22:23:37 +00:00
|
|
|
|
if (self == [NSArray class])
|
|
|
|
|
{
|
|
|
|
|
NSArray_concrete_class = [NSGArray class];
|
|
|
|
|
NSMutableArray_concrete_class = [NSGMutableArray class];
|
|
|
|
|
behavior_class_add_class (self, [NSArrayNonCore class]);
|
|
|
|
|
}
|
1995-07-01 18:38:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-06-30 13:45:13 +00:00
|
|
|
|
+ (void) _setConcreteClass: (Class)c
|
|
|
|
|
{
|
|
|
|
|
NSArray_concrete_class = c;
|
|
|
|
|
}
|
|
|
|
|
|
1995-06-30 14:07:44 +00:00
|
|
|
|
+ (void) _setMutableConcreteClass: (Class)c
|
|
|
|
|
{
|
|
|
|
|
NSMutableArray_concrete_class = c;
|
|
|
|
|
}
|
|
|
|
|
|
1995-06-30 13:45:13 +00:00
|
|
|
|
+ (Class) _concreteClass
|
|
|
|
|
{
|
|
|
|
|
return NSArray_concrete_class;
|
|
|
|
|
}
|
|
|
|
|
|
1995-06-30 14:07:44 +00:00
|
|
|
|
+ (Class) _mutableConcreteClass
|
|
|
|
|
{
|
|
|
|
|
return NSMutableArray_concrete_class;
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-31 22:23:37 +00:00
|
|
|
|
+ allocWithZone: (NSZone*)z
|
1995-06-30 13:45:13 +00:00
|
|
|
|
{
|
1999-01-11 17:28:51 +00:00
|
|
|
|
if ([self class] == [NSArray class])
|
|
|
|
|
return NSAllocateObject ([self _concreteClass], 0, z);
|
|
|
|
|
return [super allocWithZone: z];
|
1995-06-30 13:45:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
+ array
|
1995-04-03 22:59:20 +00:00
|
|
|
|
{
|
1995-11-03 22:22:02 +00:00
|
|
|
|
return [[[self alloc] init]
|
1995-06-30 13:45:13 +00:00
|
|
|
|
autorelease];
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-01-19 15:20:15 +00:00
|
|
|
|
+ arrayWithArray: (NSArray*)array
|
|
|
|
|
{
|
|
|
|
|
return [[[self alloc] initWithArray: array] autorelease];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ arrayWithContentsOfFile: (NSString*)file
|
|
|
|
|
{
|
|
|
|
|
return [[[self alloc] initWithContentsOfFile: file] autorelease];
|
|
|
|
|
}
|
|
|
|
|
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
+ arrayWithObject: anObject
|
1995-04-03 22:59:20 +00:00
|
|
|
|
{
|
1995-11-03 22:22:02 +00:00
|
|
|
|
if (anObject == nil)
|
|
|
|
|
[NSException raise:NSInvalidArgumentException
|
|
|
|
|
format:@"Tried to add nil"];
|
|
|
|
|
return [[[self alloc] initWithObjects:&anObject count:1]
|
1995-06-30 13:45:13 +00:00
|
|
|
|
autorelease];
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-03-12 14:21:20 +00:00
|
|
|
|
/* This is the designated initializer for NSArray. */
|
|
|
|
|
- initWithObjects: (id*)objects count: (unsigned)count
|
|
|
|
|
{
|
|
|
|
|
[self subclassResponsibility:_cmd];
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (unsigned) count
|
|
|
|
|
{
|
|
|
|
|
[self subclassResponsibility:_cmd];
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- objectAtIndex: (unsigned)index
|
|
|
|
|
{
|
|
|
|
|
[self subclassResponsibility:_cmd];
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
1998-08-01 21:34:58 +00:00
|
|
|
|
/* The NSCoding Protocol */
|
|
|
|
|
|
|
|
|
|
- (void) encodeWithCoder: (NSCoder*)aCoder
|
|
|
|
|
{
|
1998-10-11 06:26:40 +00:00
|
|
|
|
unsigned count = [self count];
|
|
|
|
|
|
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(unsigned)
|
|
|
|
|
at: &count];
|
|
|
|
|
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
|
[aCoder encodeObject: [self objectAtIndex: i]];
|
|
|
|
|
}
|
|
|
|
|
}
|
1998-08-01 21:34:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) initWithCoder: (NSCoder*)aCoder
|
|
|
|
|
{
|
1998-10-11 06:26:40 +00:00
|
|
|
|
unsigned count;
|
|
|
|
|
|
|
|
|
|
if ([aCoder systemVersion] == 0) {
|
|
|
|
|
unsigned dummy;
|
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(unsigned) at: &dummy];
|
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(unsigned) at: &dummy];
|
|
|
|
|
}
|
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(unsigned) at: &count];
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
id contents[count];
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
|
contents[i] = [aCoder decodeObject];
|
|
|
|
|
}
|
|
|
|
|
return [self initWithObjects: contents count: count];
|
|
|
|
|
}
|
|
|
|
|
return [self initWithObjects: 0 count: 0];
|
1998-08-01 21:34:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* The NSCopying Protocol */
|
|
|
|
|
|
|
|
|
|
- copyWithZone: (NSZone*)zone
|
|
|
|
|
{
|
|
|
|
|
/* a deep copy */
|
|
|
|
|
unsigned count = [self count];
|
|
|
|
|
id oldObjects[count];
|
|
|
|
|
id newObjects[count];
|
|
|
|
|
id newArray;
|
|
|
|
|
unsigned i;
|
|
|
|
|
BOOL needCopy = [self isKindOfClass: [NSMutableArray class]];
|
|
|
|
|
|
|
|
|
|
if (NSShouldRetainWithZone(self, zone) == NO)
|
|
|
|
|
needCopy = YES;
|
|
|
|
|
[self getObjects: oldObjects];
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
|
{
|
|
|
|
|
newObjects[i] = [oldObjects[i] copyWithZone:zone];
|
|
|
|
|
if (newObjects[i] != oldObjects[i])
|
|
|
|
|
needCopy = YES;
|
|
|
|
|
}
|
|
|
|
|
if (needCopy)
|
|
|
|
|
newArray = [[[[self class] _concreteClass] allocWithZone:zone]
|
|
|
|
|
initWithObjects:newObjects count:count];
|
|
|
|
|
else
|
|
|
|
|
newArray = [self retain];
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
|
[newObjects[i] release];
|
|
|
|
|
return newArray;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* The NSMutableCopying Protocol */
|
|
|
|
|
|
|
|
|
|
- mutableCopyWithZone: (NSZone*)zone
|
|
|
|
|
{
|
|
|
|
|
/* a shallow copy */
|
|
|
|
|
return [[[[self class] _mutableConcreteClass] allocWithZone:zone]
|
|
|
|
|
initWithArray:self];
|
|
|
|
|
}
|
|
|
|
|
|
1998-03-12 14:21:20 +00:00
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@implementation NSArrayNonCore
|
|
|
|
|
|
1996-03-30 19:14:43 +00:00
|
|
|
|
- (NSArray*) arrayByAddingObject: anObject
|
|
|
|
|
{
|
|
|
|
|
id na;
|
1998-02-03 14:20:00 +00:00
|
|
|
|
unsigned i, c;
|
1996-03-30 19:14:43 +00:00
|
|
|
|
id *objects;
|
|
|
|
|
|
|
|
|
|
c = [self count];
|
1998-10-08 13:46:53 +00:00
|
|
|
|
{
|
|
|
|
|
id objects[c+1];
|
|
|
|
|
|
|
|
|
|
[self getObjects: objects];
|
|
|
|
|
objects[c] = anObject;
|
|
|
|
|
na = [[NSArray alloc] initWithObjects: objects count: c+1];
|
|
|
|
|
}
|
1996-04-16 23:22:08 +00:00
|
|
|
|
return [na autorelease];
|
1996-03-30 19:14:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSArray*) arrayByAddingObjectsFromArray: (NSArray*)anotherArray
|
|
|
|
|
{
|
1998-10-08 13:46:53 +00:00
|
|
|
|
id na;
|
|
|
|
|
unsigned c, l;
|
1996-03-30 19:14:43 +00:00
|
|
|
|
|
1998-10-08 13:46:53 +00:00
|
|
|
|
c = [self count];
|
|
|
|
|
l = [anotherArray count];
|
|
|
|
|
{
|
|
|
|
|
id objects[c+l];
|
|
|
|
|
|
|
|
|
|
[self getObjects: objects];
|
|
|
|
|
[anotherArray getObjects: &objects[c]];
|
|
|
|
|
na = [NSArray arrayWithObjects: objects count: c+l];
|
|
|
|
|
}
|
|
|
|
|
return na;
|
1996-03-30 19:14:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
1997-09-01 21:59:51 +00:00
|
|
|
|
- initWithObjects: firstObject rest: (va_list) ap
|
1995-04-03 22:59:20 +00:00
|
|
|
|
{
|
1998-02-03 14:20:00 +00:00
|
|
|
|
register unsigned i;
|
|
|
|
|
register unsigned curSize;
|
|
|
|
|
auto unsigned prevSize;
|
|
|
|
|
auto unsigned newSize;
|
1997-09-11 01:19:24 +00:00
|
|
|
|
auto id *objsArray;
|
|
|
|
|
auto id tmpId;
|
|
|
|
|
|
|
|
|
|
/* Do initial allocation. */
|
1998-10-08 13:46:53 +00:00
|
|
|
|
prevSize = 3;
|
|
|
|
|
curSize = 5;
|
1997-09-11 01:19:24 +00:00
|
|
|
|
OBJC_MALLOC(objsArray, id, curSize);
|
|
|
|
|
tmpId = firstObject;
|
|
|
|
|
|
|
|
|
|
/* Loop through adding objects to array until a nil is
|
|
|
|
|
* found.
|
|
|
|
|
*/
|
|
|
|
|
for (i = 0; tmpId != nil; i++)
|
|
|
|
|
{
|
|
|
|
|
/* Put id into array. */
|
|
|
|
|
objsArray[i] = tmpId;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
1997-09-11 01:19:24 +00:00
|
|
|
|
/* If the index equals the current size, increase size. */
|
1997-09-23 14:03:36 +00:00
|
|
|
|
if (i == curSize - 1)
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
1997-09-11 01:19:24 +00:00
|
|
|
|
/* Fibonacci series. Supposedly, for this application,
|
|
|
|
|
* the fibonacci series will be more memory efficient.
|
|
|
|
|
*/
|
|
|
|
|
newSize = prevSize + curSize;
|
|
|
|
|
prevSize = curSize;
|
|
|
|
|
curSize = newSize;
|
|
|
|
|
|
|
|
|
|
/* Reallocate object array. */
|
|
|
|
|
OBJC_REALLOC(objsArray, id, curSize);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
1997-09-11 01:19:24 +00:00
|
|
|
|
tmpId = va_arg(ap, id);
|
|
|
|
|
}
|
|
|
|
|
va_end( ap );
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
1997-09-11 01:19:24 +00:00
|
|
|
|
/* Put object ids into NSArray. */
|
1997-09-22 17:31:34 +00:00
|
|
|
|
self = [self initWithObjects: objsArray count: i];
|
1997-09-11 01:19:24 +00:00
|
|
|
|
OBJC_FREE( objsArray );
|
|
|
|
|
return( self );
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
- initWithObjects: firstObject, ...
|
1995-04-03 22:59:20 +00:00
|
|
|
|
{
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
va_list ap;
|
|
|
|
|
va_start(ap, firstObject);
|
|
|
|
|
self = [self initWithObjects:firstObject rest:ap];
|
|
|
|
|
va_end(ap);
|
1995-04-04 16:01:04 +00:00
|
|
|
|
return self;
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-05-13 19:25:38 +00:00
|
|
|
|
- initWithContentsOfFile: (NSString*)file
|
|
|
|
|
{
|
|
|
|
|
NSString *myString;
|
|
|
|
|
|
1999-02-01 10:36:05 +00:00
|
|
|
|
myString = [[NSString alloc] initWithContentsOfFile: file];
|
1998-05-13 19:25:38 +00:00
|
|
|
|
if (myString)
|
|
|
|
|
{
|
|
|
|
|
id result = [myString propertyList];
|
1999-02-01 10:36:05 +00:00
|
|
|
|
|
1999-02-04 13:51:29 +00:00
|
|
|
|
NS_DURING
|
|
|
|
|
{
|
|
|
|
|
result = [myString propertyList];
|
|
|
|
|
}
|
|
|
|
|
NS_HANDLER
|
|
|
|
|
{
|
|
|
|
|
result = nil;
|
|
|
|
|
}
|
|
|
|
|
NS_ENDHANDLER
|
1999-02-01 10:36:05 +00:00
|
|
|
|
[myString release];
|
|
|
|
|
if ([result isKindOfClass: [NSArray class]])
|
1998-05-13 19:25:38 +00:00
|
|
|
|
{
|
|
|
|
|
[self initWithArray: result];
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
NSLog(@"Contents of file does not contain an array");
|
1999-02-01 10:36:05 +00:00
|
|
|
|
[self release];
|
1998-05-13 19:25:38 +00:00
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
+ arrayWithObjects: firstObject, ...
|
1995-04-03 22:59:20 +00:00
|
|
|
|
{
|
1995-04-04 16:01:04 +00:00
|
|
|
|
va_list ap;
|
|
|
|
|
va_start(ap, firstObject);
|
1995-11-03 22:22:02 +00:00
|
|
|
|
self = [[self alloc] initWithObjects:firstObject rest:ap];
|
1995-04-04 16:01:04 +00:00
|
|
|
|
va_end(ap);
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
return [self autorelease];
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-01-19 15:20:15 +00:00
|
|
|
|
+ arrayWithObjects: (id*)objects count: (unsigned)count
|
|
|
|
|
{
|
|
|
|
|
return [[[self alloc] initWithObjects: objects count: count]
|
|
|
|
|
autorelease];
|
|
|
|
|
}
|
|
|
|
|
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
- initWithArray: (NSArray*)array
|
1995-04-03 22:59:20 +00:00
|
|
|
|
{
|
1998-10-08 13:46:53 +00:00
|
|
|
|
unsigned c;
|
1995-04-04 16:01:04 +00:00
|
|
|
|
|
1998-10-08 13:46:53 +00:00
|
|
|
|
c = [array count];
|
|
|
|
|
{
|
|
|
|
|
id objects[c];
|
|
|
|
|
|
|
|
|
|
[array getObjects: objects];
|
|
|
|
|
self = [self initWithObjects: objects count: c];
|
|
|
|
|
}
|
|
|
|
|
return self;
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-01-19 15:20:15 +00:00
|
|
|
|
- (void) getObjects: (id*)aBuffer
|
|
|
|
|
{
|
1998-02-03 14:20:00 +00:00
|
|
|
|
unsigned i, c = [self count];
|
1998-01-19 15:20:15 +00:00
|
|
|
|
for (i = 0; i < c; i++)
|
|
|
|
|
aBuffer[i] = [self objectAtIndex: i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) getObjects: (id*)aBuffer range: (NSRange)aRange
|
|
|
|
|
{
|
1998-02-03 14:20:00 +00:00
|
|
|
|
unsigned i, j = 0, c = [self count], e = aRange.location + aRange.length;
|
1998-01-19 15:20:15 +00:00
|
|
|
|
if (c < e)
|
|
|
|
|
e = c;
|
|
|
|
|
for (i = aRange.location; i < c; i++)
|
|
|
|
|
aBuffer[j++] = [self objectAtIndex: i];
|
|
|
|
|
}
|
1995-04-03 22:59:20 +00:00
|
|
|
|
|
1998-10-27 08:12:49 +00:00
|
|
|
|
- (unsigned) hash
|
|
|
|
|
{
|
|
|
|
|
return [self count];
|
|
|
|
|
}
|
|
|
|
|
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
- (unsigned) indexOfObjectIdenticalTo:anObject
|
1995-04-03 22:59:20 +00:00
|
|
|
|
{
|
1998-02-03 14:20:00 +00:00
|
|
|
|
unsigned i, c = [self count];
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
for (i = 0; i < c; i++)
|
|
|
|
|
if (anObject == [self objectAtIndex:i])
|
|
|
|
|
return i;
|
1995-09-21 17:42:46 +00:00
|
|
|
|
return NSNotFound;
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-01-19 15:20:15 +00:00
|
|
|
|
- (unsigned) indexOfObjectIdenticalTo:anObject inRange: (NSRange)aRange
|
|
|
|
|
{
|
1998-02-03 14:20:00 +00:00
|
|
|
|
unsigned i, e = aRange.location + aRange.length, c = [self count];
|
1998-01-19 15:20:15 +00:00
|
|
|
|
if (c < e)
|
|
|
|
|
e = c;
|
|
|
|
|
for (i = aRange.location; i < e; i++)
|
|
|
|
|
if (anObject == [self objectAtIndex:i])
|
|
|
|
|
return i;
|
|
|
|
|
return NSNotFound;
|
|
|
|
|
}
|
|
|
|
|
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
/* Inefficient, should be overridden. */
|
|
|
|
|
- (unsigned) indexOfObject: anObject
|
1995-04-03 22:59:20 +00:00
|
|
|
|
{
|
1998-02-03 14:20:00 +00:00
|
|
|
|
unsigned i, c = [self count];
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
for (i = 0; i < c; i++)
|
|
|
|
|
if ([[self objectAtIndex:i] isEqual: anObject])
|
|
|
|
|
return i;
|
1995-09-21 17:42:46 +00:00
|
|
|
|
return NSNotFound;
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-01-19 15:20:15 +00:00
|
|
|
|
/* Inefficient, should be overridden. */
|
|
|
|
|
- (unsigned) indexOfObject: anObject inRange: (NSRange)aRange
|
|
|
|
|
{
|
1998-02-03 14:20:00 +00:00
|
|
|
|
unsigned i, e = aRange.location + aRange.length, c = [self count];
|
1998-01-19 15:20:15 +00:00
|
|
|
|
if (c < e)
|
|
|
|
|
e = c;
|
|
|
|
|
for (i = aRange.location; i < e; i++)
|
|
|
|
|
{
|
|
|
|
|
id o = [self objectAtIndex: i];
|
|
|
|
|
if (anObject == o || [o isEqual: anObject])
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
return NSNotFound;
|
|
|
|
|
}
|
|
|
|
|
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
- (BOOL) containsObject: anObject
|
1995-04-03 22:59:20 +00:00
|
|
|
|
{
|
1995-09-21 17:42:46 +00:00
|
|
|
|
return ([self indexOfObject:anObject] != NSNotFound);
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
- (BOOL) isEqual: anObject
|
1995-04-03 22:59:20 +00:00
|
|
|
|
{
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
if ([anObject isKindOf:[NSArray class]])
|
|
|
|
|
return [self isEqualToArray:anObject];
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL) isEqualToArray: (NSArray*)otherArray
|
|
|
|
|
{
|
1998-02-03 14:20:00 +00:00
|
|
|
|
unsigned i, c = [self count];
|
1995-04-04 16:01:04 +00:00
|
|
|
|
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
if (c != [otherArray count])
|
1995-04-04 16:01:04 +00:00
|
|
|
|
return NO;
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
for (i = 0; i < c; i++)
|
1996-03-30 19:14:43 +00:00
|
|
|
|
if (![[self objectAtIndex: i] isEqual: [otherArray objectAtIndex: i]])
|
1995-04-04 16:01:04 +00:00
|
|
|
|
return NO;
|
|
|
|
|
return YES;
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- lastObject
|
|
|
|
|
{
|
1998-02-03 14:20:00 +00:00
|
|
|
|
unsigned count = [self count];
|
1996-03-30 23:00:27 +00:00
|
|
|
|
if (count == 0)
|
|
|
|
|
return nil;
|
|
|
|
|
return [self objectAtIndex: count-1];
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-11-14 03:48:55 +00:00
|
|
|
|
- (void) makeObjectsPerformSelector: (SEL)aSelector
|
1995-04-03 22:59:20 +00:00
|
|
|
|
{
|
1998-02-03 14:20:00 +00:00
|
|
|
|
unsigned i = [self count];
|
|
|
|
|
while (i-- > 0)
|
1998-09-28 20:38:02 +00:00
|
|
|
|
[[self objectAtIndex:i] performSelector:aSelector];
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-11-14 03:48:55 +00:00
|
|
|
|
- (void) makeObjectsPerform: (SEL)aSelector
|
1998-01-19 15:20:15 +00:00
|
|
|
|
{
|
1998-11-14 03:48:55 +00:00
|
|
|
|
[self makeObjectsPerformSelector: aSelector];
|
1998-01-19 15:20:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-11-14 03:48:55 +00:00
|
|
|
|
- (void) makeObjectsPerformSelector: (SEL)aSelector withObject:argument
|
1995-04-03 22:59:20 +00:00
|
|
|
|
{
|
1998-02-03 14:20:00 +00:00
|
|
|
|
unsigned i = [self count];
|
|
|
|
|
while (i-- > 0)
|
1998-09-28 20:38:02 +00:00
|
|
|
|
[[self objectAtIndex:i] performSelector:aSelector withObject:argument];
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-11-14 03:48:55 +00:00
|
|
|
|
- (void) makeObjectsPerform: (SEL)aSelector withObject:argument
|
1998-01-19 15:20:15 +00:00
|
|
|
|
{
|
1998-11-14 03:48:55 +00:00
|
|
|
|
[self makeObjectsPerformSelector: aSelector withObject:argument];
|
1998-01-19 15:20:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
- (NSArray*) sortedArrayUsingSelector: (SEL)comparator
|
1995-04-03 22:59:20 +00:00
|
|
|
|
{
|
1997-01-09 16:24:07 +00:00
|
|
|
|
int compare(id elem1, id elem2, void* context)
|
|
|
|
|
{
|
1998-09-28 20:38:02 +00:00
|
|
|
|
return (int)[elem1 performSelector:comparator withObject:elem2];
|
1997-01-09 16:24:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return [self sortedArrayUsingFunction:compare context:NULL];
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
- (NSArray*) sortedArrayUsingFunction: (int(*)(id,id,void*))comparator
|
|
|
|
|
context: (void*)context
|
1995-04-03 22:59:20 +00:00
|
|
|
|
{
|
1998-01-19 15:20:15 +00:00
|
|
|
|
return [self sortedArrayUsingFunction: comparator context: context hint: nil];
|
|
|
|
|
}
|
1997-01-09 16:24:07 +00:00
|
|
|
|
|
1998-01-19 15:20:15 +00:00
|
|
|
|
- (NSData*) sortedArrayHint
|
|
|
|
|
{
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSArray*) sortedArrayUsingFunction: (int(*)(id,id,void*))comparator
|
|
|
|
|
context: (void*)context
|
|
|
|
|
hint: (NSData*)hint
|
|
|
|
|
{
|
|
|
|
|
NSMutableArray *sortedArray;
|
|
|
|
|
NSArray *result;
|
|
|
|
|
|
|
|
|
|
sortedArray = [[NSMutableArray alloc] initWithArray: self];
|
1997-01-09 16:24:07 +00:00
|
|
|
|
[sortedArray sortUsingFunction:comparator context:context];
|
1998-01-19 15:20:15 +00:00
|
|
|
|
result = [NSArray arrayWithArray: sortedArray];
|
|
|
|
|
[sortedArray release];
|
|
|
|
|
return result;
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
- (NSString*) componentsJoinedByString: (NSString*)separator
|
1995-04-03 22:59:20 +00:00
|
|
|
|
{
|
1998-02-03 14:20:00 +00:00
|
|
|
|
unsigned i, c = [self count];
|
1995-04-07 21:01:59 +00:00
|
|
|
|
id s = [NSMutableString stringWithCapacity:2]; /* arbitrary capacity */
|
|
|
|
|
|
|
|
|
|
if (!c)
|
|
|
|
|
return s;
|
|
|
|
|
[s appendString:[[self objectAtIndex:0] description]];
|
|
|
|
|
for (i = 1; i < c; i++)
|
|
|
|
|
{
|
|
|
|
|
[s appendString:separator];
|
|
|
|
|
[s appendString:[[self objectAtIndex:i] description]];
|
|
|
|
|
}
|
|
|
|
|
return s;
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-01-19 15:20:15 +00:00
|
|
|
|
- (NSArray*) pathsMatchingExtensions: (NSArray*)extensions
|
|
|
|
|
{
|
1998-02-03 14:20:00 +00:00
|
|
|
|
unsigned i, c = [self count];
|
1998-01-19 15:20:15 +00:00
|
|
|
|
NSMutableArray *a = [NSMutableArray arrayWithCapacity: 1];
|
|
|
|
|
for (i = 0; i < c; i++)
|
|
|
|
|
{
|
|
|
|
|
id o = [self objectAtIndex: i];
|
|
|
|
|
if ([o isKindOfClass: [NSString class]])
|
|
|
|
|
if ([extensions containsObject: [o pathExtension]])
|
|
|
|
|
[a addObject: o];
|
|
|
|
|
}
|
|
|
|
|
return a;
|
|
|
|
|
}
|
1995-04-03 22:59:20 +00:00
|
|
|
|
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
- firstObjectCommonWithArray: (NSArray*)otherArray
|
1995-04-03 22:59:20 +00:00
|
|
|
|
{
|
1998-02-03 14:20:00 +00:00
|
|
|
|
unsigned i, c = [self count];
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
id o;
|
|
|
|
|
for (i = 0; i < c; i++)
|
|
|
|
|
if ([otherArray containsObject:(o = [self objectAtIndex:i])])
|
|
|
|
|
return o;
|
|
|
|
|
return nil;
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-30 19:14:43 +00:00
|
|
|
|
- (NSArray*) subarrayWithRange: (NSRange)range
|
1995-04-03 22:59:20 +00:00
|
|
|
|
{
|
1996-03-30 19:14:43 +00:00
|
|
|
|
id na;
|
|
|
|
|
id *objects;
|
|
|
|
|
unsigned c = [self count];
|
|
|
|
|
unsigned i, j, k;
|
|
|
|
|
|
|
|
|
|
// If array is empty or start is beyond end of array
|
|
|
|
|
// then return an empty array
|
|
|
|
|
if (([self count] == 0) || (range.location > (c-1)))
|
|
|
|
|
return [NSArray array];
|
|
|
|
|
|
|
|
|
|
// Obtain bounds
|
|
|
|
|
i = range.location;
|
|
|
|
|
// Check if length extends beyond end of array
|
|
|
|
|
if ((range.location + range.length) > (c-1))
|
|
|
|
|
j = c-1;
|
|
|
|
|
else
|
|
|
|
|
j = range.location + range.length - 1;
|
|
|
|
|
|
1998-10-08 13:46:53 +00:00
|
|
|
|
{
|
|
|
|
|
id objects[j-i+1];
|
1996-03-30 19:14:43 +00:00
|
|
|
|
|
1998-10-08 13:46:53 +00:00
|
|
|
|
[self getObjects: objects range: NSMakeRange(i, j-i+1)];
|
|
|
|
|
na = [NSArray arrayWithObjects: objects count: j-i+1];
|
|
|
|
|
}
|
|
|
|
|
return na;
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
- (NSEnumerator*) objectEnumerator
|
|
|
|
|
{
|
1995-10-30 01:05:15 +00:00
|
|
|
|
return [[[NSArrayEnumerator alloc] initWithArray:self]
|
|
|
|
|
autorelease];
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
}
|
1995-04-03 22:59:20 +00:00
|
|
|
|
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
- (NSEnumerator*) reverseObjectEnumerator
|
|
|
|
|
{
|
1995-10-30 01:05:15 +00:00
|
|
|
|
return [[[NSArrayEnumeratorReverse alloc] initWithArray:self]
|
|
|
|
|
autorelease];
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
}
|
1995-04-03 22:59:20 +00:00
|
|
|
|
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
- (NSString*) description
|
1997-11-07 18:46:30 +00:00
|
|
|
|
{
|
1998-01-19 15:20:15 +00:00
|
|
|
|
return [self descriptionWithLocale: nil];
|
1997-11-07 18:46:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-01-19 15:20:15 +00:00
|
|
|
|
- (NSString*) descriptionWithLocale: (NSDictionary*)locale
|
1995-04-03 22:59:20 +00:00
|
|
|
|
{
|
1998-01-19 15:20:15 +00:00
|
|
|
|
return [self descriptionWithLocale: locale indent: 0];
|
|
|
|
|
}
|
1998-01-21 14:56:24 +00:00
|
|
|
|
|
1998-01-19 15:20:15 +00:00
|
|
|
|
- (NSString*) descriptionWithLocale: (NSDictionary*)locale
|
|
|
|
|
indent: (unsigned int)level
|
|
|
|
|
{
|
1998-12-18 17:05:44 +00:00
|
|
|
|
NSMutableString *result;
|
1997-10-31 16:26:44 +00:00
|
|
|
|
|
1998-12-18 17:05:44 +00:00
|
|
|
|
result = [NSMutableString stringWithCapacity: 20*[self count]];
|
|
|
|
|
[self descriptionWithLocale: locale
|
|
|
|
|
indent: level
|
|
|
|
|
to: (id<GNUDescriptionDestination>)result];
|
|
|
|
|
return result;
|
|
|
|
|
}
|
1996-05-13 16:42:08 +00:00
|
|
|
|
|
1998-12-18 17:05:44 +00:00
|
|
|
|
static NSString *indentStrings[] = {
|
|
|
|
|
@"",
|
|
|
|
|
@" ",
|
|
|
|
|
@"\t",
|
|
|
|
|
@"\t ",
|
|
|
|
|
@"\t\t",
|
|
|
|
|
@"\t\t ",
|
|
|
|
|
@"\t\t\t",
|
|
|
|
|
@"\t\t\t ",
|
|
|
|
|
@"\t\t\t\t",
|
|
|
|
|
@"\t\t\t\t ",
|
|
|
|
|
@"\t\t\t\t\t",
|
|
|
|
|
@"\t\t\t\t\t ",
|
|
|
|
|
@"\t\t\t\t\t\t"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
- (void) descriptionWithLocale: (NSDictionary*)locale
|
|
|
|
|
indent: (unsigned int)level
|
|
|
|
|
to: (id<GNUDescriptionDestination>)result
|
|
|
|
|
{
|
|
|
|
|
NSString *iBaseString;
|
|
|
|
|
NSString *iSizeString;
|
|
|
|
|
unsigned count = [self count];
|
|
|
|
|
NSString *plists[count];
|
|
|
|
|
unsigned i;
|
|
|
|
|
SEL appSel;
|
|
|
|
|
IMP appImp;
|
|
|
|
|
|
|
|
|
|
appSel = @selector(appendString:);
|
|
|
|
|
appImp = [(NSObject*)result methodForSelector: appSel];
|
|
|
|
|
|
|
|
|
|
if (level < sizeof(indentStrings)/sizeof(NSString*))
|
|
|
|
|
iBaseString = indentStrings[level];
|
|
|
|
|
else
|
|
|
|
|
iBaseString = indentStrings[sizeof(indentStrings)/sizeof(NSString*)-1];
|
|
|
|
|
level++;
|
|
|
|
|
if (level < sizeof(indentStrings)/sizeof(NSString*))
|
|
|
|
|
iSizeString = indentStrings[level];
|
|
|
|
|
else
|
|
|
|
|
iSizeString = indentStrings[sizeof(indentStrings)/sizeof(NSString*)-1];
|
1998-01-19 15:20:15 +00:00
|
|
|
|
|
1998-12-18 17:05:44 +00:00
|
|
|
|
(*appImp)(result, appSel, @"(\n");
|
1998-01-19 15:20:15 +00:00
|
|
|
|
|
1998-12-18 17:05:44 +00:00
|
|
|
|
[self getObjects: plists];
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
|
{
|
|
|
|
|
id item = plists[i];
|
1998-01-19 15:20:15 +00:00
|
|
|
|
|
1998-12-18 17:05:44 +00:00
|
|
|
|
(*appImp)(result, appSel, iSizeString);
|
|
|
|
|
|
|
|
|
|
if ([item respondsToSelector:
|
|
|
|
|
@selector(descriptionWithLocale:indent:)])
|
|
|
|
|
{
|
|
|
|
|
[item descriptionWithLocale: locale indent: level to: result];
|
1998-01-19 15:20:15 +00:00
|
|
|
|
}
|
1998-12-18 17:05:44 +00:00
|
|
|
|
else if ([item respondsToSelector:
|
|
|
|
|
@selector(descriptionWithLocale:)])
|
|
|
|
|
{
|
|
|
|
|
[item descriptionWithLocale: locale to: result];
|
1998-01-19 15:20:15 +00:00
|
|
|
|
}
|
1998-12-18 17:05:44 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
[item descriptionTo: result];
|
1998-01-19 15:20:15 +00:00
|
|
|
|
}
|
1998-12-18 17:05:44 +00:00
|
|
|
|
if (i == count - 1)
|
|
|
|
|
{
|
|
|
|
|
(*appImp)(result, appSel, @"\n");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
(*appImp)(result, appSel, @",\n");
|
1998-01-19 15:20:15 +00:00
|
|
|
|
}
|
1996-05-13 16:42:08 +00:00
|
|
|
|
}
|
1998-12-18 17:05:44 +00:00
|
|
|
|
(*appImp)(result, appSel, iBaseString);
|
|
|
|
|
(*appImp)(result, appSel, @")");
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
1996-03-31 22:23:37 +00:00
|
|
|
|
|
|
|
|
|
@implementation NSMutableArray
|
1995-04-03 22:59:20 +00:00
|
|
|
|
|
1996-03-31 22:23:37 +00:00
|
|
|
|
+ (void) initialize
|
1995-05-05 15:50:26 +00:00
|
|
|
|
{
|
1996-03-31 22:23:37 +00:00
|
|
|
|
if (self == [NSMutableArray class])
|
1996-05-06 19:57:29 +00:00
|
|
|
|
{
|
|
|
|
|
behavior_class_add_class (self, [NSMutableArrayNonCore class]);
|
|
|
|
|
behavior_class_add_class (self, [NSArrayNonCore class]);
|
|
|
|
|
}
|
1995-05-05 15:50:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-31 22:23:37 +00:00
|
|
|
|
+ allocWithZone: (NSZone*)z
|
1995-04-03 22:59:20 +00:00
|
|
|
|
{
|
1999-01-11 17:28:51 +00:00
|
|
|
|
if ([self class] == [NSMutableArray class])
|
|
|
|
|
return NSAllocateObject ([self _mutableConcreteClass], 0, z);
|
|
|
|
|
return [super allocWithZone: z];
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
/* This is the desgnated initializer for NSMutableArray */
|
|
|
|
|
- initWithCapacity: (unsigned)numItems
|
1995-04-03 22:59:20 +00:00
|
|
|
|
{
|
1996-02-01 17:04:17 +00:00
|
|
|
|
[self subclassResponsibility:_cmd];
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
return nil;
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
- (void) addObject: anObject
|
1995-04-03 22:59:20 +00:00
|
|
|
|
{
|
1997-09-01 21:59:51 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
- (void) replaceObjectAtIndex: (unsigned)index withObject: anObject
|
1995-04-03 22:59:20 +00:00
|
|
|
|
{
|
1995-11-24 20:09:18 +00:00
|
|
|
|
[self subclassResponsibility:_cmd];
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-01-19 15:20:15 +00:00
|
|
|
|
- (void) replaceObjectsInRange: (NSRange)aRange
|
|
|
|
|
withObjectsFromArray: (NSArray*)anArray
|
|
|
|
|
{
|
1998-04-06 02:09:44 +00:00
|
|
|
|
id e, o;
|
1998-01-19 15:20:15 +00:00
|
|
|
|
|
1998-04-06 02:09:44 +00:00
|
|
|
|
if ([self count] < (aRange.location + aRange.length))
|
1998-01-19 15:20:15 +00:00
|
|
|
|
[NSException raise: NSRangeException
|
|
|
|
|
format: @"Replacing objects beyond end of array."];
|
|
|
|
|
[self removeObjectsInRange: aRange];
|
1998-04-06 02:09:44 +00:00
|
|
|
|
e = [anArray reverseObjectEnumerator];
|
|
|
|
|
while ((o = [e nextObject]))
|
|
|
|
|
[self insertObject: o atIndex: aRange.location];
|
1998-01-19 15:20:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) replaceObjectsInRange: (NSRange)aRange
|
|
|
|
|
withObjectsFromArray: (NSArray*)anArray
|
|
|
|
|
range: (NSRange)anotherRange
|
|
|
|
|
{
|
|
|
|
|
[self replaceObjectsInRange: aRange
|
|
|
|
|
withObjectsFromArray: [anArray subarrayWithRange: anotherRange]];
|
|
|
|
|
}
|
|
|
|
|
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
- (void) insertObject: anObject atIndex: (unsigned)index
|
1995-04-03 22:59:20 +00:00
|
|
|
|
{
|
1995-11-24 20:09:18 +00:00
|
|
|
|
[self subclassResponsibility:_cmd];
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
- (void) removeObjectAtIndex: (unsigned)index
|
1995-04-03 22:59:20 +00:00
|
|
|
|
{
|
1995-11-24 20:09:18 +00:00
|
|
|
|
[self subclassResponsibility:_cmd];
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-31 22:23:37 +00:00
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@implementation NSMutableArrayNonCore
|
|
|
|
|
|
|
|
|
|
+ arrayWithCapacity: (unsigned)numItems
|
|
|
|
|
{
|
|
|
|
|
return [[[self alloc] initWithCapacity:numItems]
|
|
|
|
|
autorelease];
|
|
|
|
|
}
|
|
|
|
|
|
1998-01-19 15:20:15 +00:00
|
|
|
|
- (BOOL)writeToFile:(NSString *)path atomically:(BOOL)useAuxiliaryFile
|
|
|
|
|
{
|
|
|
|
|
return [[self description] writeToFile:path atomically:useAuxiliaryFile];
|
|
|
|
|
}
|
|
|
|
|
|
1996-03-31 22:23:37 +00:00
|
|
|
|
/* Override our superclass's designated initializer to go our's */
|
|
|
|
|
- initWithObjects: (id*)objects count: (unsigned)count
|
|
|
|
|
{
|
1998-02-03 14:20:00 +00:00
|
|
|
|
unsigned i;
|
1996-03-31 22:23:37 +00:00
|
|
|
|
self = [self initWithCapacity: count];
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
|
[self addObject:objects[i]];
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
- (void) removeLastObject
|
1994-11-08 16:44:01 +00:00
|
|
|
|
{
|
1998-02-03 14:20:00 +00:00
|
|
|
|
unsigned count = [self count];
|
1996-03-30 23:00:27 +00:00
|
|
|
|
if (count == 0)
|
|
|
|
|
[NSException raise: NSRangeException
|
|
|
|
|
format: @"Trying to remove from an empty array."];
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
[self removeObjectAtIndex:count-1];
|
1994-11-08 16:44:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
- (void) removeObjectIdenticalTo: anObject
|
1994-11-08 16:44:01 +00:00
|
|
|
|
{
|
1998-02-03 14:20:00 +00:00
|
|
|
|
unsigned pos = NSNotFound;
|
|
|
|
|
unsigned i = [self count];
|
1996-04-30 14:25:22 +00:00
|
|
|
|
|
1998-02-03 14:20:00 +00:00
|
|
|
|
while (i-- > 0)
|
|
|
|
|
{
|
|
|
|
|
id o = [self objectAtIndex: i];
|
|
|
|
|
if (o == anObject)
|
|
|
|
|
{
|
|
|
|
|
if (pos != NSNotFound)
|
|
|
|
|
[self removeObjectAtIndex: pos];
|
|
|
|
|
pos = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (pos != NSNotFound)
|
|
|
|
|
[self removeObjectAtIndex: pos];
|
1994-11-08 16:44:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-01-19 15:20:15 +00:00
|
|
|
|
- (void) removeObject: anObject inRange:(NSRange)aRange
|
|
|
|
|
{
|
1998-02-03 14:20:00 +00:00
|
|
|
|
unsigned c = [self count], s = aRange.location;
|
|
|
|
|
unsigned i = aRange.location + aRange.length;
|
|
|
|
|
unsigned pos = NSNotFound;
|
1998-01-19 15:20:15 +00:00
|
|
|
|
if (i > c)
|
|
|
|
|
i = c;
|
1998-02-03 14:20:00 +00:00
|
|
|
|
while (i-- > s)
|
1998-01-19 15:20:15 +00:00
|
|
|
|
{
|
|
|
|
|
id o = [self objectAtIndex: i];
|
|
|
|
|
if (o == anObject || [o isEqual: anObject])
|
1998-02-03 14:20:00 +00:00
|
|
|
|
{
|
|
|
|
|
if (pos != NSNotFound)
|
|
|
|
|
[self removeObjectAtIndex: pos];
|
|
|
|
|
pos = i;
|
|
|
|
|
}
|
1998-01-19 15:20:15 +00:00
|
|
|
|
}
|
1998-02-03 14:20:00 +00:00
|
|
|
|
if (pos != NSNotFound)
|
|
|
|
|
[self removeObjectAtIndex: pos];
|
1998-01-19 15:20:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) removeObjectIdenticalTo: anObject inRange:(NSRange)aRange
|
|
|
|
|
{
|
1998-02-03 14:20:00 +00:00
|
|
|
|
unsigned c = [self count], s = aRange.location;
|
|
|
|
|
unsigned i = aRange.location + aRange.length;
|
|
|
|
|
unsigned pos = NSNotFound;
|
1998-01-19 15:20:15 +00:00
|
|
|
|
if (i > c)
|
|
|
|
|
i = c;
|
1998-02-03 14:20:00 +00:00
|
|
|
|
while (i-- > s)
|
1998-01-19 15:20:15 +00:00
|
|
|
|
{
|
|
|
|
|
id o = [self objectAtIndex: i];
|
|
|
|
|
if (o == anObject)
|
1998-02-03 14:20:00 +00:00
|
|
|
|
{
|
|
|
|
|
if (pos != NSNotFound)
|
|
|
|
|
[self removeObjectAtIndex: pos];
|
|
|
|
|
pos = i;
|
|
|
|
|
}
|
1998-01-19 15:20:15 +00:00
|
|
|
|
}
|
1998-02-03 14:20:00 +00:00
|
|
|
|
if (pos != NSNotFound)
|
|
|
|
|
[self removeObjectAtIndex: pos];
|
1998-01-19 15:20:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
- (void) removeObject: anObject
|
1994-11-08 16:44:01 +00:00
|
|
|
|
{
|
1998-02-03 14:20:00 +00:00
|
|
|
|
unsigned pos = NSNotFound;
|
|
|
|
|
unsigned i = [self count];
|
1996-04-30 14:25:22 +00:00
|
|
|
|
|
1998-02-03 14:20:00 +00:00
|
|
|
|
while (i-- > 0)
|
|
|
|
|
{
|
|
|
|
|
id o = [self objectAtIndex: i];
|
|
|
|
|
if (o == anObject || [o isEqual: anObject])
|
|
|
|
|
{
|
|
|
|
|
if (pos != NSNotFound)
|
|
|
|
|
[self removeObjectAtIndex: pos];
|
|
|
|
|
pos = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (pos != NSNotFound)
|
|
|
|
|
[self removeObjectAtIndex: pos];
|
1994-11-08 16:44:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
- (void) removeAllObjects
|
1994-11-08 16:44:01 +00:00
|
|
|
|
{
|
1996-03-30 19:14:43 +00:00
|
|
|
|
while ([self count])
|
|
|
|
|
[self removeLastObject];
|
1994-11-08 16:44:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
- (void) addObjectsFromArray: (NSArray*)otherArray
|
1994-11-08 16:44:01 +00:00
|
|
|
|
{
|
1998-02-03 14:20:00 +00:00
|
|
|
|
unsigned i, c = [otherArray count];
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
for (i = 0; i < c; i++)
|
1996-03-31 22:23:37 +00:00
|
|
|
|
[self addObject: [otherArray objectAtIndex: i]];
|
1994-11-08 16:44:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-30 19:14:43 +00:00
|
|
|
|
- (void) setArray:(NSArray *)otherArray
|
|
|
|
|
{
|
|
|
|
|
[self removeAllObjects];
|
1996-03-31 22:23:37 +00:00
|
|
|
|
[self addObjectsFromArray: otherArray];
|
1996-03-30 19:14:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
- (void) removeObjectsFromIndices: (unsigned*)indices
|
1996-03-31 22:23:37 +00:00
|
|
|
|
numIndices: (unsigned)count
|
1994-11-08 16:44:01 +00:00
|
|
|
|
{
|
1999-02-16 16:08:59 +00:00
|
|
|
|
if (count > 0)
|
|
|
|
|
{
|
|
|
|
|
unsigned sorted[count];
|
|
|
|
|
unsigned to = 0;
|
|
|
|
|
unsigned from = 0;
|
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
|
|
while (from < count)
|
|
|
|
|
{
|
|
|
|
|
unsigned val = indices[from++];
|
|
|
|
|
|
|
|
|
|
i = to;
|
|
|
|
|
while (i > 0 && sorted[i] > val)
|
|
|
|
|
{
|
|
|
|
|
i--;
|
|
|
|
|
}
|
|
|
|
|
if (i == to)
|
|
|
|
|
{
|
|
|
|
|
sorted[to++] = val;
|
|
|
|
|
}
|
|
|
|
|
else if (sorted[i] < val)
|
|
|
|
|
{
|
|
|
|
|
unsigned j = to++;
|
|
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
while (j > i)
|
|
|
|
|
{
|
|
|
|
|
sorted[j] = sorted[j-1];
|
|
|
|
|
j--;
|
|
|
|
|
}
|
|
|
|
|
sorted[i] = val;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (to--)
|
|
|
|
|
{
|
|
|
|
|
[self removeObjectAtIndex: indices[to]];
|
|
|
|
|
}
|
|
|
|
|
}
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) removeObjectsInArray: (NSArray*)otherArray
|
|
|
|
|
{
|
1998-02-03 14:20:00 +00:00
|
|
|
|
unsigned i, c = [otherArray count];
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
for (i = 0; i < c; i++)
|
|
|
|
|
[self removeObject:[otherArray objectAtIndex:i]];
|
1994-11-08 16:44:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-01-19 15:20:15 +00:00
|
|
|
|
- (void) removeObjectsInRange: (NSRange)aRange
|
|
|
|
|
{
|
1998-02-03 14:20:00 +00:00
|
|
|
|
unsigned i, s = aRange.location, c = [self count];
|
1998-01-19 15:20:15 +00:00
|
|
|
|
i = aRange.location + aRange.length;
|
|
|
|
|
if (c < i)
|
|
|
|
|
i = c;
|
1998-02-03 14:20:00 +00:00
|
|
|
|
while (i-- > s)
|
1998-01-19 15:20:15 +00:00
|
|
|
|
[self removeObjectAtIndex: i];
|
|
|
|
|
}
|
|
|
|
|
|
1997-09-01 21:59:51 +00:00
|
|
|
|
- (void) sortUsingSelector: (SEL)comparator
|
|
|
|
|
{
|
|
|
|
|
int compare(id elem1, id elem2, void* context)
|
|
|
|
|
{
|
1998-09-28 20:38:02 +00:00
|
|
|
|
return (int)[elem1 performSelector:comparator withObject:elem2];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[self sortUsingFunction:compare context:NULL];
|
|
|
|
|
}
|
|
|
|
|
|
(allocWithZone): Removed method.
(arrayWithObjects:, initWithObjects:, initWithArray:, count,
indexOfObjectIdenticalTo:, indexOfObject:, isEqualToArray:,
makeObjectsPerform:, makeObjectsPerform:withObject:, lastObject,
firstObjectCommonWithArray:, arrayWithCapacity:, addObject:,
replaceObjectAtIndex:, removeLastObject, insertObject:atIndex:,
removeObjectAtIndex:, removeObjectIdenticalTo:, removeObject:,
removeAllObjects, addObjectsFromArray:,
removeObjectsFromIndices:numIndices:, removeObjectsInArray:,
copyWithZone:, mutableCopyWithZone:): Newly implemented or majorly
overhauled.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@285 72102866-910b-0410-8b05-ffd578937521
1995-04-05 20:23:03 +00:00
|
|
|
|
- (void) sortUsingFunction: (int(*)(id,id,void*))compare
|
|
|
|
|
context: (void*)context
|
1995-04-03 03:18:43 +00:00
|
|
|
|
{
|
1997-01-09 16:24:07 +00:00
|
|
|
|
/* Shell sort algorithm taken from SortingInAction - a NeXT example */
|
|
|
|
|
#define STRIDE_FACTOR 3 // good value for stride factor is not well-understood
|
|
|
|
|
// 3 is a fairly good choice (Sedgewick)
|
1998-02-03 14:20:00 +00:00
|
|
|
|
unsigned c,d, stride;
|
1997-01-09 16:24:07 +00:00
|
|
|
|
BOOL found;
|
|
|
|
|
int count = [self count];
|
|
|
|
|
|
|
|
|
|
stride = 1;
|
|
|
|
|
while (stride <= count)
|
|
|
|
|
stride = stride * STRIDE_FACTOR + 1;
|
|
|
|
|
|
|
|
|
|
while(stride > (STRIDE_FACTOR - 1)) {
|
|
|
|
|
// loop to sort for each value of stride
|
|
|
|
|
stride = stride / STRIDE_FACTOR;
|
|
|
|
|
for (c = stride; c < count; c++) {
|
|
|
|
|
found = NO;
|
1998-02-03 14:20:00 +00:00
|
|
|
|
if (stride > c)
|
|
|
|
|
break;
|
1997-01-09 16:24:07 +00:00
|
|
|
|
d = c - stride;
|
1998-02-03 14:20:00 +00:00
|
|
|
|
while (!found) {
|
1997-01-09 16:24:07 +00:00
|
|
|
|
// move to left until correct place
|
|
|
|
|
id a = [self objectAtIndex:d + stride];
|
|
|
|
|
id b = [self objectAtIndex:d];
|
|
|
|
|
if ((*compare)(a, b, context) == NSOrderedAscending) {
|
|
|
|
|
[a retain];
|
|
|
|
|
[self replaceObjectAtIndex:d + stride withObject:b];
|
|
|
|
|
[self replaceObjectAtIndex:d withObject:a];
|
|
|
|
|
[a release];
|
1998-02-03 14:20:00 +00:00
|
|
|
|
if (stride > d)
|
|
|
|
|
break;
|
|
|
|
|
d -= stride; // jump by stride factor
|
1997-01-09 16:24:07 +00:00
|
|
|
|
}
|
|
|
|
|
else found = YES;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
1995-04-03 03:18:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
1994-11-08 16:44:01 +00:00
|
|
|
|
@end
|
1996-03-31 22:23:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@interface NSArrayEnumerator : NSEnumerator
|
|
|
|
|
{
|
|
|
|
|
id array;
|
|
|
|
|
int next_index;
|
|
|
|
|
}
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation NSArrayEnumerator
|
|
|
|
|
|
|
|
|
|
- initWithArray: (NSArray*)anArray
|
|
|
|
|
{
|
|
|
|
|
[super init];
|
|
|
|
|
array = anArray;
|
|
|
|
|
[array retain];
|
|
|
|
|
next_index = 0;
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) nextObject
|
|
|
|
|
{
|
|
|
|
|
if (next_index >= [array count])
|
|
|
|
|
return nil;
|
|
|
|
|
return [array objectAtIndex:next_index++];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
|
{
|
|
|
|
|
[array release];
|
|
|
|
|
[super dealloc];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@interface NSArrayEnumeratorReverse : NSArrayEnumerator
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation NSArrayEnumeratorReverse
|
|
|
|
|
|
|
|
|
|
- initWithArray: (NSArray*)anArray
|
|
|
|
|
{
|
|
|
|
|
[super init];
|
|
|
|
|
array = anArray;
|
|
|
|
|
[array retain];
|
|
|
|
|
next_index = [array count]-1;
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) nextObject
|
|
|
|
|
{
|
|
|
|
|
if (next_index < 0)
|
|
|
|
|
return nil;
|
|
|
|
|
return [array objectAtIndex:next_index--];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|