1995-04-03 22:59:20 +00:00
|
|
|
|
/* NSArray - Array object to hold other objects.
|
1996-02-01 17:04:17 +00:00
|
|
|
|
Copyright (C) 1995, 1996 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
|
|
|
|
|
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>
|
1997-12-11 19:09:56 +00:00
|
|
|
|
#include <gnustep/base/behavior.h>
|
1995-04-17 21:13:20 +00:00
|
|
|
|
#include <Foundation/NSArray.h>
|
|
|
|
|
#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>
|
1997-10-31 16:26:44 +00:00
|
|
|
|
#include <Foundation/NSCharacterSet.h>
|
1995-07-01 18:38:03 +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
|
|
|
|
{
|
1996-03-31 22:23:37 +00:00
|
|
|
|
return NSAllocateObject ([self _concreteClass], 0, z);
|
1995-06-30 13:45:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-31 22:23:37 +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
|
1995-05-05 15:50:26 +00:00
|
|
|
|
{
|
1996-03-31 22:23:37 +00:00
|
|
|
|
[self subclassResponsibility:_cmd];
|
|
|
|
|
return nil;
|
1995-05-05 15:50:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-31 22:23:37 +00:00
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@implementation NSArrayNonCore
|
|
|
|
|
|
(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
|
|
|
|
}
|
|
|
|
|
|
(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
|
|
|
|
}
|
|
|
|
|
|
1996-03-30 19:14:43 +00:00
|
|
|
|
- (NSArray*) arrayByAddingObject: anObject
|
|
|
|
|
{
|
|
|
|
|
id na;
|
|
|
|
|
int i, c;
|
|
|
|
|
id *objects;
|
|
|
|
|
|
|
|
|
|
c = [self count];
|
|
|
|
|
OBJC_MALLOC (objects, id, c+1);
|
|
|
|
|
for (i = 0; i < c; i++)
|
|
|
|
|
objects[i] = [self objectAtIndex: i];
|
|
|
|
|
objects[c] = anObject;
|
|
|
|
|
na = [[NSArray alloc] initWithObjects: objects count: c+1];
|
|
|
|
|
OBJC_FREE (objects);
|
1996-04-16 23:22:08 +00:00
|
|
|
|
return [na autorelease];
|
1996-03-30 19:14:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSArray*) arrayByAddingObjectsFromArray: (NSArray*)anotherArray
|
|
|
|
|
{
|
|
|
|
|
id na;
|
|
|
|
|
int i, c, l;
|
|
|
|
|
id *objects;
|
|
|
|
|
|
|
|
|
|
c = [self count];
|
|
|
|
|
l = [anotherArray count];
|
|
|
|
|
OBJC_MALLOC (objects, id, c+l);
|
|
|
|
|
for (i = 0; i < c; i++)
|
|
|
|
|
objects[i] = [self objectAtIndex: i];
|
|
|
|
|
for (i = c; i < c+l; i++)
|
|
|
|
|
objects[i] = [anotherArray objectAtIndex: i-c];
|
|
|
|
|
na = [[NSArray alloc] initWithObjects: objects count: c+l];
|
|
|
|
|
OBJC_FREE (objects);
|
1996-04-16 23:22:08 +00:00
|
|
|
|
return [na autorelease];
|
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
|
|
|
|
{
|
1997-09-11 01:19:24 +00:00
|
|
|
|
register int i;
|
|
|
|
|
register int curSize;
|
|
|
|
|
auto int prevSize;
|
|
|
|
|
auto int newSize;
|
|
|
|
|
auto id *objsArray;
|
|
|
|
|
auto id tmpId;
|
|
|
|
|
|
|
|
|
|
/* Do initial allocation. */
|
|
|
|
|
prevSize = 1;
|
|
|
|
|
curSize = 2;
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
(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
|
|
|
|
}
|
|
|
|
|
|
(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
|
|
|
|
{
|
1995-04-04 16:01:04 +00:00
|
|
|
|
int i, c;
|
(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 *objects;
|
1995-04-04 16:01:04 +00:00
|
|
|
|
|
|
|
|
|
c = [array 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
|
|
|
|
OBJC_MALLOC(objects, id, c);
|
1995-04-04 16:01:04 +00:00
|
|
|
|
for (i = 0; i < c; i++)
|
(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
|
|
|
|
objects[i] = [array objectAtIndex:i];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
self = [self initWithObjects:objects count:c];
|
|
|
|
|
OBJC_FREE(objects);
|
|
|
|
|
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
|
|
|
|
- (unsigned) indexOfObjectIdenticalTo: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
|
|
|
|
int i, c = [self count];
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
(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
|
|
|
|
{
|
(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
|
|
|
|
int i, c = [self count];
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
(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
|
|
|
|
|
{
|
|
|
|
|
int 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
|
|
|
|
|
{
|
(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
|
|
|
|
int 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
|
|
|
|
}
|
|
|
|
|
|
(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) makeObjectsPerform: (SEL)aSelector
|
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
|
|
|
|
int i, c = [self count];
|
|
|
|
|
for (i = 0; i < c; i++)
|
|
|
|
|
[[self objectAtIndex:i] perform:aSelector];
|
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) makeObjectsPerform: (SEL)aSelector withObject:argument
|
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
|
|
|
|
int i, c = [self count];
|
|
|
|
|
for (i = 0; i < c; i++)
|
|
|
|
|
[[self objectAtIndex:i] perform:aSelector withObject:argument];
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
- (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)
|
|
|
|
|
{
|
|
|
|
|
return (int)[elem1 perform:comparator withObject:elem2];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
1997-01-09 16:24:07 +00:00
|
|
|
|
id sortedArray = [[self mutableCopy] autorelease];
|
|
|
|
|
|
|
|
|
|
[sortedArray sortUsingFunction:comparator context:context];
|
|
|
|
|
return [[sortedArray copy] autorelease];
|
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
|
|
|
|
{
|
1995-04-07 21:01:59 +00:00
|
|
|
|
int i, c = [self count];
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
(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
|
|
|
|
{
|
(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
|
|
|
|
int i, c = [self count];
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
// Copy the ids from the range into a temporary array
|
|
|
|
|
OBJC_MALLOC(objects, id, j-i+1);
|
|
|
|
|
for (k = i; k <= j; k++)
|
|
|
|
|
objects[k-i] = [self objectAtIndex:k];
|
|
|
|
|
|
|
|
|
|
// Create the new array
|
|
|
|
|
na = [[NSArray alloc] initWithObjects:objects count:j-i+1];
|
|
|
|
|
OBJC_FREE(objects);
|
1996-04-16 23:22:08 +00:00
|
|
|
|
return [na autorelease];
|
1996-03-30 19:14:43 +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*) 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
|
|
|
|
{
|
|
|
|
|
return [self descriptionWithIndent: 0];
|
|
|
|
|
}
|
|
|
|
|
|
1997-12-11 19:09:56 +00:00
|
|
|
|
- (NSString*) descriptionWithIndent: (unsigned)level
|
1995-04-03 22:59:20 +00:00
|
|
|
|
{
|
1997-10-31 16:26:44 +00:00
|
|
|
|
id string;
|
1996-05-13 16:42:08 +00:00
|
|
|
|
id desc;
|
1997-10-31 16:26:44 +00:00
|
|
|
|
id object;
|
1996-05-13 16:42:08 +00:00
|
|
|
|
int count = [self count];
|
|
|
|
|
int i;
|
1997-10-31 16:26:44 +00:00
|
|
|
|
NSCharacterSet *quotables;
|
|
|
|
|
|
|
|
|
|
quotables = [[NSCharacterSet alphanumericCharacterSet] invertedSet];
|
1996-05-13 16:42:08 +00:00
|
|
|
|
|
|
|
|
|
desc = [NSMutableString stringWithCapacity: 2];
|
|
|
|
|
[desc appendString: @"("];
|
|
|
|
|
if (count > 0)
|
1997-10-31 16:26:44 +00:00
|
|
|
|
{
|
|
|
|
|
object = [self objectAtIndex: 0];
|
|
|
|
|
if ([object respondsToSelector: @selector(descriptionWithIndent:)])
|
|
|
|
|
{
|
|
|
|
|
/* This a dictionary or array, so don't quote it */
|
|
|
|
|
string = [object descriptionWithIndent: 0];
|
|
|
|
|
[desc appendString: string];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* This should be a string or number, so decide if we need to
|
|
|
|
|
quote it */
|
|
|
|
|
string = [object description];
|
1997-11-07 18:46:30 +00:00
|
|
|
|
if ([string length] == 0
|
|
|
|
|
|| [string rangeOfCharacterFromSet: quotables].length > 0)
|
1997-10-31 16:26:44 +00:00
|
|
|
|
[desc appendFormat: @"%s", [string quotedCString]];
|
|
|
|
|
else
|
|
|
|
|
[desc appendString: string];
|
|
|
|
|
}
|
|
|
|
|
}
|
1996-05-13 16:42:08 +00:00
|
|
|
|
for (i=1; i<count; i++)
|
|
|
|
|
{
|
1997-10-31 16:26:44 +00:00
|
|
|
|
object = [self objectAtIndex: i];
|
|
|
|
|
|
1996-05-13 16:42:08 +00:00
|
|
|
|
[desc appendString: @", "];
|
1997-10-31 16:26:44 +00:00
|
|
|
|
if ([object respondsToSelector: @selector(descriptionWithIndent:)])
|
|
|
|
|
{
|
|
|
|
|
/* This a dictionary or array, so don't quote it */
|
|
|
|
|
string = [object descriptionWithIndent: 0];
|
|
|
|
|
[desc appendString: string];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* This should be a string or number, so decide if we need to
|
|
|
|
|
quote it */
|
|
|
|
|
string = [object description];
|
1997-11-07 18:46:30 +00:00
|
|
|
|
if ([string length] == 0
|
|
|
|
|
|| [string rangeOfCharacterFromSet: quotables].length > 0)
|
1997-10-31 16:26:44 +00:00
|
|
|
|
[desc appendString: [NSString stringWithCString:
|
|
|
|
|
[string quotedCString]]];
|
|
|
|
|
else
|
|
|
|
|
[desc appendString: string];
|
|
|
|
|
}
|
1996-05-13 16:42:08 +00:00
|
|
|
|
}
|
|
|
|
|
[desc appendString: @")"];
|
|
|
|
|
return desc;
|
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
|
|
|
|
/* The NSCopying Protocol */
|
|
|
|
|
|
1997-09-01 21:59:51 +00:00
|
|
|
|
- (id) copy
|
|
|
|
|
{
|
|
|
|
|
return [self copyWithZone:NSDefaultMallocZone()];
|
|
|
|
|
}
|
|
|
|
|
|
(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
|
|
|
|
- copyWithZone: (NSZone*)zone
|
|
|
|
|
{
|
1995-06-30 14:07:44 +00:00
|
|
|
|
/* a deep copy */
|
|
|
|
|
int count = [self count];
|
|
|
|
|
id objects[count];
|
|
|
|
|
int i;
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
|
objects[i] = [[self objectAtIndex:i] copyWithZone:zone];
|
|
|
|
|
return [[[[self class] _concreteClass] allocWithZone:zone]
|
|
|
|
|
initWithObjects:objects count: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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* The NSMutableCopying Protocol */
|
|
|
|
|
|
|
|
|
|
- mutableCopyWithZone: (NSZone*)zone
|
|
|
|
|
{
|
1995-06-30 14:07:44 +00:00
|
|
|
|
/* a shallow copy */
|
|
|
|
|
return [[[[self class] _mutableConcreteClass] allocWithZone:zone]
|
|
|
|
|
initWithArray: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
|
|
|
|
}
|
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
|
|
|
|
{
|
1996-03-31 22:23:37 +00:00
|
|
|
|
return NSAllocateObject ([self _mutableConcreteClass], 0, 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
|
|
|
|
}
|
|
|
|
|
|
(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];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Override our superclass's designated initializer to go our's */
|
|
|
|
|
- initWithObjects: (id*)objects count: (unsigned)count
|
|
|
|
|
{
|
|
|
|
|
/* xxx Could be made more efficient by increasing capacity all at once. */
|
|
|
|
|
int i;
|
|
|
|
|
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
|
|
|
|
{
|
(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
|
|
|
|
int 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
|
|
|
|
{
|
1996-04-30 14:25:22 +00:00
|
|
|
|
unsigned index;
|
|
|
|
|
|
|
|
|
|
/* Retain the object. Yuck, but necessary in case the array holds
|
|
|
|
|
the last reference to anObject. */
|
|
|
|
|
/* xxx Is there an alternative to this expensive retain/release? */
|
|
|
|
|
[anObject retain];
|
|
|
|
|
|
|
|
|
|
for (index = [self indexOfObjectIdenticalTo: anObject];
|
|
|
|
|
index != NO_INDEX;
|
|
|
|
|
index = [self indexOfObjectIdenticalTo: anObject])
|
|
|
|
|
[self removeObjectAtIndex: index];
|
|
|
|
|
|
|
|
|
|
[anObject release];
|
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) removeObject: anObject
|
1994-11-08 16:44:01 +00:00
|
|
|
|
{
|
1996-04-30 14:25:22 +00:00
|
|
|
|
unsigned index;
|
|
|
|
|
|
|
|
|
|
/* Retain the object. Yuck, but necessary in case the array holds
|
|
|
|
|
the last reference to anObject. */
|
|
|
|
|
/* xxx Is there an alternative to this expensive retain/release? */
|
|
|
|
|
[anObject retain];
|
|
|
|
|
|
|
|
|
|
for (index = [self indexOfObject: anObject];
|
|
|
|
|
index != NO_INDEX;
|
|
|
|
|
index = [self indexOfObject: anObject])
|
|
|
|
|
[self removeObjectAtIndex: index];
|
|
|
|
|
|
|
|
|
|
[anObject release];
|
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
|
|
|
|
{
|
(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
|
|
|
|
/* xxx Could be made more efficient by increasing capacity all at once. */
|
|
|
|
|
int i, c = [otherArray count];
|
|
|
|
|
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
|
|
|
|
{
|
(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
|
|
|
|
int compare_unsigned(const void *u1, const void *u2)
|
|
|
|
|
{
|
|
|
|
|
return *((int*)u1) - *((int*)u2);
|
|
|
|
|
}
|
|
|
|
|
/* xxx are we allowed to modify the contents of indices? */
|
|
|
|
|
qsort(indices, count, sizeof(unsigned), compare_unsigned);
|
|
|
|
|
while (count--)
|
|
|
|
|
[self removeObjectAtIndex:indices[count]];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) removeObjectsInArray: (NSArray*)otherArray
|
|
|
|
|
{
|
|
|
|
|
int i, c = [otherArray count];
|
|
|
|
|
for (i = 0; i < c; i++)
|
|
|
|
|
[self removeObject:[otherArray objectAtIndex:i]];
|
1994-11-08 16:44:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
1997-09-01 21:59:51 +00:00
|
|
|
|
- (void) sortUsingSelector: (SEL)comparator
|
|
|
|
|
{
|
|
|
|
|
int compare(id elem1, id elem2, void* context)
|
|
|
|
|
{
|
|
|
|
|
return (int)[elem1 perform:comparator withObject:elem2];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[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)
|
|
|
|
|
int c,d, stride;
|
|
|
|
|
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;
|
|
|
|
|
d = c - stride;
|
|
|
|
|
while ((d >= 0) && !found) {
|
|
|
|
|
// 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];
|
|
|
|
|
[b retain];
|
|
|
|
|
[self replaceObjectAtIndex:d + stride withObject:b];
|
|
|
|
|
[self replaceObjectAtIndex:d withObject:a];
|
|
|
|
|
d -= stride; // jump by stride factor
|
|
|
|
|
[a release];
|
|
|
|
|
[b release];
|
|
|
|
|
}
|
|
|
|
|
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--];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|