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
|
1999-09-09 02:56:20 +00:00
|
|
|
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 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>
|
1999-06-21 08:30:26 +00:00
|
|
|
|
#include <Foundation/NSRange.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>
|
1999-11-07 14:50:30 +00:00
|
|
|
|
#include <Foundation/NSDebug.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
|
|
|
|
|
1999-05-26 17:09:21 +00:00
|
|
|
|
@class NSGMutableCString;
|
|
|
|
|
|
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
|
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
static Class NSArray_abstract_class;
|
1996-03-31 22:23:37 +00:00
|
|
|
|
static Class NSArray_concrete_class;
|
1999-09-14 19:24:58 +00:00
|
|
|
|
static Class NSMutableArray_abstract_class;
|
1996-03-31 22:23:37 +00:00
|
|
|
|
static Class NSMutableArray_concrete_class;
|
1995-07-01 18:38:03 +00:00
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
static SEL addSel = @selector(addObject:);
|
|
|
|
|
static SEL appSel = @selector(appendString:);
|
|
|
|
|
static SEL countSel = @selector(count);
|
|
|
|
|
static SEL eqSel = @selector(isEqual:);
|
|
|
|
|
static SEL oaiSel = @selector(objectAtIndex:);
|
|
|
|
|
static SEL remSel = @selector(removeObjectAtIndex:);
|
|
|
|
|
static SEL rlSel = @selector(removeLastObject);
|
|
|
|
|
|
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])
|
|
|
|
|
{
|
1999-09-14 19:24:58 +00:00
|
|
|
|
NSArray_abstract_class = [NSArray class];
|
|
|
|
|
NSMutableArray_abstract_class = [NSMutableArray class];
|
1996-03-31 22:23:37 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
+ (id) allocWithZone: (NSZone*)z
|
1995-06-30 13:45:13 +00:00
|
|
|
|
{
|
1999-09-28 08:48:27 +00:00
|
|
|
|
if (self == NSArray_abstract_class)
|
1999-09-14 19:24:58 +00:00
|
|
|
|
return NSAllocateObject(NSArray_concrete_class, 0, z);
|
1999-01-11 17:28:51 +00:00
|
|
|
|
return [super allocWithZone: z];
|
1995-06-30 13:45:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
+ (id) array
|
1995-04-03 22:59:20 +00:00
|
|
|
|
{
|
1999-06-30 21:13:19 +00:00
|
|
|
|
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()] init]);
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
+ (id) arrayWithArray: (NSArray*)array
|
1998-01-19 15:20:15 +00:00
|
|
|
|
{
|
1999-06-30 21:13:19 +00:00
|
|
|
|
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
|
|
|
|
|
initWithArray: array]);
|
1998-01-19 15:20:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
+ (id) arrayWithContentsOfFile: (NSString*)file
|
1998-01-19 15:20:15 +00:00
|
|
|
|
{
|
1999-06-30 21:13:19 +00:00
|
|
|
|
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
|
|
|
|
|
initWithContentsOfFile: file]);
|
1998-01-19 15:20:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
+ (id) arrayWithObject: anObject
|
1995-04-03 22:59:20 +00:00
|
|
|
|
{
|
1995-11-03 22:22:02 +00:00
|
|
|
|
if (anObject == nil)
|
1999-04-08 12:17:15 +00:00
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
|
format: @"Tried to add nil"];
|
1999-06-30 21:13:19 +00:00
|
|
|
|
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
|
|
|
|
|
initWithObjects: &anObject count: 1]);
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-03-12 14:21:20 +00:00
|
|
|
|
/* This is the designated initializer for NSArray. */
|
1999-09-14 19:24:58 +00:00
|
|
|
|
- (id) initWithObjects: (id*)objects count: (unsigned)count
|
1998-03-12 14:21:20 +00:00
|
|
|
|
{
|
1999-04-08 12:17:15 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
1998-03-12 14:21:20 +00:00
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (unsigned) count
|
|
|
|
|
{
|
1999-04-08 12:17:15 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
1998-03-12 14:21:20 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
- (id) objectAtIndex: (unsigned)index
|
1998-03-12 14:21:20 +00:00
|
|
|
|
{
|
1999-04-08 12:17:15 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
1998-03-12 14:21:20 +00:00
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
1998-08-01 21:34:58 +00:00
|
|
|
|
/* The NSCoding Protocol */
|
|
|
|
|
|
|
|
|
|
- (void) encodeWithCoder: (NSCoder*)aCoder
|
|
|
|
|
{
|
1999-09-14 19:24:58 +00:00
|
|
|
|
unsigned count = [self count];
|
1998-10-11 06:26:40 +00:00
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(unsigned)
|
|
|
|
|
at: &count];
|
1998-10-11 06:26:40 +00:00
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
if (count > 0)
|
|
|
|
|
{
|
|
|
|
|
id a[count];
|
1998-10-11 06:26:40 +00:00
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
[self getObjects: a];
|
|
|
|
|
[aCoder encodeArrayOfObjCType: @encode(id)
|
|
|
|
|
count: count
|
|
|
|
|
at: a];
|
1998-10-11 06:26:40 +00:00
|
|
|
|
}
|
1998-08-01 21:34:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) initWithCoder: (NSCoder*)aCoder
|
|
|
|
|
{
|
1999-09-14 19:24:58 +00:00
|
|
|
|
unsigned count;
|
1998-10-11 06:26:40 +00:00
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(unsigned)
|
|
|
|
|
at: &count];
|
|
|
|
|
if (count > 0)
|
|
|
|
|
{
|
|
|
|
|
id contents[count];
|
1998-10-11 06:26:40 +00:00
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
[aCoder decodeArrayOfObjCType: @encode(id)
|
|
|
|
|
count: count
|
|
|
|
|
at: contents];
|
|
|
|
|
return [self initWithObjects: contents count: count];
|
1998-10-11 06:26:40 +00:00
|
|
|
|
}
|
1999-09-14 19:24:58 +00:00
|
|
|
|
else
|
1998-10-11 06:26:40 +00:00
|
|
|
|
return [self initWithObjects: 0 count: 0];
|
1998-08-01 21:34:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* The NSCopying Protocol */
|
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
- (id) copyWithZone: (NSZone*)zone
|
1998-08-01 21:34:58 +00:00
|
|
|
|
{
|
1999-06-30 21:13:19 +00:00
|
|
|
|
return RETAIN(self);
|
1998-08-01 21:34:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* The NSMutableCopying Protocol */
|
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
- (id) mutableCopyWithZone: (NSZone*)zone
|
1998-08-01 21:34:58 +00:00
|
|
|
|
{
|
1999-09-14 19:24:58 +00:00
|
|
|
|
return [[NSMutableArray_concrete_class allocWithZone: zone]
|
|
|
|
|
initWithArray: self];
|
1998-08-01 21:34:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-03-12 14:21:20 +00:00
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@implementation NSArrayNonCore
|
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
- (NSArray*) arrayByAddingObject: (id)anObject
|
1996-03-30 19:14:43 +00:00
|
|
|
|
{
|
|
|
|
|
id na;
|
1999-09-14 19:24:58 +00:00
|
|
|
|
unsigned c = [self count];
|
1996-03-30 19:14:43 +00:00
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
if (anObject == nil)
|
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
|
format: @"Attempt to add nil to an array"];
|
|
|
|
|
if (c == 0)
|
|
|
|
|
na = [[NSArray_concrete_class allocWithZone: NSDefaultMallocZone()]
|
|
|
|
|
initWithObjects: &anObject count: 1];
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
id objects[c+1];
|
1998-10-08 13:46:53 +00:00
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
[self getObjects: objects];
|
|
|
|
|
objects[c] = anObject;
|
|
|
|
|
na = [[NSArray_concrete_class allocWithZone: NSDefaultMallocZone()]
|
|
|
|
|
initWithObjects: objects count: c+1];
|
|
|
|
|
}
|
1999-06-30 21:13:19 +00:00
|
|
|
|
return AUTORELEASE(na);
|
1996-03-30 19:14:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSArray*) arrayByAddingObjectsFromArray: (NSArray*)anotherArray
|
|
|
|
|
{
|
1999-06-04 16:05:45 +00:00
|
|
|
|
id na;
|
|
|
|
|
unsigned c, l;
|
1998-10-08 13:46:53 +00:00
|
|
|
|
|
1999-06-04 16:05:45 +00:00
|
|
|
|
c = [self count];
|
|
|
|
|
l = [anotherArray count];
|
|
|
|
|
{
|
|
|
|
|
id objects[c+l];
|
|
|
|
|
|
|
|
|
|
[self getObjects: objects];
|
|
|
|
|
[anotherArray getObjects: &objects[c]];
|
1999-09-14 19:24:58 +00:00
|
|
|
|
na = [NSArray_abstract_class arrayWithObjects: objects count: c+l];
|
1999-06-04 16:05:45 +00:00
|
|
|
|
}
|
|
|
|
|
return na;
|
1996-03-30 19:14:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
- (id) 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;
|
1999-09-28 11:10:34 +00:00
|
|
|
|
objsArray = (id*)NSZoneMalloc(NSDefaultMallocZone(), sizeof(id) * curSize);
|
1997-09-11 01:19:24 +00:00
|
|
|
|
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. */
|
1999-09-28 11:10:34 +00:00
|
|
|
|
objsArray = (id*)NSZoneRealloc(NSDefaultMallocZone(), objsArray,
|
|
|
|
|
sizeof(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];
|
1999-09-28 11:10:34 +00:00
|
|
|
|
NSZoneFree(NSDefaultMallocZone(), objsArray);
|
1997-09-11 01:19:24 +00:00
|
|
|
|
return( self );
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
- (id) 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);
|
1999-04-08 12:17:15 +00:00
|
|
|
|
self = [self initWithObjects: firstObject rest: 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
|
|
|
|
va_end(ap);
|
1995-04-04 16:01:04 +00:00
|
|
|
|
return self;
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
- (id) initWithContentsOfFile: (NSString*)file
|
1998-05-13 19:25:38 +00:00
|
|
|
|
{
|
|
|
|
|
NSString *myString;
|
|
|
|
|
|
1999-05-06 14:42:26 +00:00
|
|
|
|
myString = [[NSString allocWithZone: NSDefaultMallocZone()]
|
|
|
|
|
initWithContentsOfFile: file];
|
1998-05-13 19:25:38 +00:00
|
|
|
|
if (myString)
|
|
|
|
|
{
|
1999-09-14 19:24:58 +00:00
|
|
|
|
id result;
|
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-06-30 21:13:19 +00:00
|
|
|
|
RELEASE(myString);
|
1999-09-14 19:24:58 +00:00
|
|
|
|
if ([result isKindOfClass: NSArray_abstract_class])
|
1998-05-13 19:25:38 +00:00
|
|
|
|
{
|
|
|
|
|
[self initWithArray: result];
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
}
|
1999-11-07 14:50:30 +00:00
|
|
|
|
NSWarnMLog(@"Contents of file does not contain an array", 0);
|
1999-06-30 21:13:19 +00:00
|
|
|
|
RELEASE(self);
|
1998-05-13 19:25:38 +00:00
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
+ (id) 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);
|
1999-05-06 14:42:26 +00:00
|
|
|
|
self = [[self allocWithZone: NSDefaultMallocZone()]
|
|
|
|
|
initWithObjects: firstObject rest: ap];
|
1995-04-04 16:01:04 +00:00
|
|
|
|
va_end(ap);
|
1999-06-30 21:13:19 +00:00
|
|
|
|
return AUTORELEASE(self);
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
+ (id) arrayWithObjects: (id*)objects count: (unsigned)count
|
1998-01-19 15:20:15 +00:00
|
|
|
|
{
|
1999-06-30 21:13:19 +00:00
|
|
|
|
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
|
|
|
|
|
initWithObjects: objects count: count]);
|
1998-01-19 15:20:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
- (id) initWithArray: (NSArray*)array
|
1995-04-03 22:59:20 +00:00
|
|
|
|
{
|
1999-06-04 16:05:45 +00:00
|
|
|
|
unsigned c;
|
1998-10-08 13:46:53 +00:00
|
|
|
|
|
1999-06-04 16:05:45 +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];
|
1999-09-14 19:24:58 +00:00
|
|
|
|
IMP get = [self methodForSelector: oaiSel];
|
1999-06-04 16:05:45 +00:00
|
|
|
|
|
1998-01-19 15:20:15 +00:00
|
|
|
|
for (i = 0; i < c; i++)
|
1999-09-14 19:24:58 +00:00
|
|
|
|
aBuffer[i] = (*get)(self, oaiSel, i);
|
1998-01-19 15:20:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (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;
|
1999-09-14 19:24:58 +00:00
|
|
|
|
IMP get = [self methodForSelector: oaiSel];
|
1999-06-04 16:05:45 +00:00
|
|
|
|
|
1999-06-21 08:30:26 +00:00
|
|
|
|
GS_RANGE_CHECK(aRange, c);
|
1999-06-04 16:05:45 +00:00
|
|
|
|
|
1999-05-11 13:05:24 +00:00
|
|
|
|
for (i = aRange.location; i < e; i++)
|
1999-09-14 19:24:58 +00:00
|
|
|
|
aBuffer[j++] = (*get)(self, oaiSel, i);
|
1998-01-19 15:20:15 +00:00
|
|
|
|
}
|
1995-04-03 22:59:20 +00:00
|
|
|
|
|
1998-10-27 08:12:49 +00:00
|
|
|
|
- (unsigned) hash
|
|
|
|
|
{
|
1999-06-04 16:05:45 +00:00
|
|
|
|
return [self count];
|
1998-10-27 08:12:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-04-08 12:17:15 +00:00
|
|
|
|
- (unsigned) indexOfObjectIdenticalTo: anObject
|
1995-04-03 22:59:20 +00:00
|
|
|
|
{
|
1999-09-14 19:24:58 +00:00
|
|
|
|
unsigned c = [self count];
|
|
|
|
|
|
|
|
|
|
if (c > 0)
|
|
|
|
|
{
|
|
|
|
|
IMP get = [self methodForSelector: oaiSel];
|
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < c; i++)
|
|
|
|
|
if (anObject == (*get)(self, oaiSel, i))
|
|
|
|
|
return i;
|
|
|
|
|
}
|
1995-09-21 17:42:46 +00:00
|
|
|
|
return NSNotFound;
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-04-08 12:17:15 +00:00
|
|
|
|
- (unsigned) indexOfObjectIdenticalTo: anObject inRange: (NSRange)aRange
|
1998-01-19 15:20:15 +00:00
|
|
|
|
{
|
1998-02-03 14:20:00 +00:00
|
|
|
|
unsigned i, e = aRange.location + aRange.length, c = [self count];
|
1999-09-14 19:24:58 +00:00
|
|
|
|
IMP get = [self methodForSelector: oaiSel];
|
1999-06-04 16:05:45 +00:00
|
|
|
|
|
1999-06-21 08:30:26 +00:00
|
|
|
|
GS_RANGE_CHECK(aRange, c);
|
1999-06-04 16:05:45 +00:00
|
|
|
|
|
1998-01-19 15:20:15 +00:00
|
|
|
|
for (i = aRange.location; i < e; i++)
|
1999-09-14 19:24:58 +00:00
|
|
|
|
if (anObject == (*get)(self, oaiSel, i))
|
1998-01-19 15:20:15 +00:00
|
|
|
|
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. */
|
1999-09-14 19:24:58 +00:00
|
|
|
|
- (unsigned) indexOfObject: (id)anObject
|
1995-04-03 22:59:20 +00:00
|
|
|
|
{
|
1999-09-14 19:24:58 +00:00
|
|
|
|
unsigned c = [self count];
|
|
|
|
|
|
|
|
|
|
if (c > 0 && anObject != nil)
|
|
|
|
|
{
|
|
|
|
|
unsigned i;
|
|
|
|
|
IMP get = [self methodForSelector: oaiSel];
|
|
|
|
|
BOOL (*eq)(id, SEL, id)
|
|
|
|
|
= (BOOL (*)(id, SEL, id))[anObject methodForSelector: eqSel];
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < c; i++)
|
|
|
|
|
if ((*eq)(anObject, eqSel, (*get)(self, oaiSel, i)) == YES)
|
|
|
|
|
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. */
|
1999-09-14 19:24:58 +00:00
|
|
|
|
- (unsigned) indexOfObject: (id)anObject inRange: (NSRange)aRange
|
1998-01-19 15:20:15 +00:00
|
|
|
|
{
|
1998-02-03 14:20:00 +00:00
|
|
|
|
unsigned i, e = aRange.location + aRange.length, c = [self count];
|
1999-09-14 19:24:58 +00:00
|
|
|
|
IMP get = [self methodForSelector: oaiSel];
|
|
|
|
|
BOOL (*eq)(id, SEL, id)
|
|
|
|
|
= (BOOL (*)(id, SEL, id))[anObject methodForSelector: eqSel];
|
1999-06-04 16:05:45 +00:00
|
|
|
|
|
1999-06-21 08:30:26 +00:00
|
|
|
|
GS_RANGE_CHECK(aRange, c);
|
1999-06-04 16:05:45 +00:00
|
|
|
|
|
1998-01-19 15:20:15 +00:00
|
|
|
|
for (i = aRange.location; i < e; i++)
|
|
|
|
|
{
|
1999-09-14 19:24:58 +00:00
|
|
|
|
if ((*eq)(anObject, eqSel, (*get)(self, oaiSel, i)) == YES)
|
1998-01-19 15:20:15 +00:00
|
|
|
|
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
|
|
|
|
{
|
1999-04-08 12:17:15 +00:00
|
|
|
|
return ([self indexOfObject: anObject] != NSNotFound);
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
- (BOOL) isEqual: (id)anObject
|
1995-04-03 22:59:20 +00:00
|
|
|
|
{
|
1999-09-14 19:24:58 +00:00
|
|
|
|
if (self == anObject)
|
|
|
|
|
return YES;
|
|
|
|
|
if ([anObject isKindOfClass: NSArray_abstract_class])
|
1999-04-08 12:17:15 +00:00
|
|
|
|
return [self isEqualToArray: anObject];
|
(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 NO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL) isEqualToArray: (NSArray*)otherArray
|
|
|
|
|
{
|
1999-09-14 19:24:58 +00:00
|
|
|
|
unsigned i, c;
|
1995-04-04 16:01:04 +00:00
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
if (self == (id)otherArray)
|
|
|
|
|
return YES;
|
|
|
|
|
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
|
|
|
|
if (c != [otherArray count])
|
1995-04-04 16:01:04 +00:00
|
|
|
|
return NO;
|
1999-09-14 19:24:58 +00:00
|
|
|
|
if (c > 0)
|
|
|
|
|
{
|
|
|
|
|
IMP get0 = [self methodForSelector: oaiSel];
|
|
|
|
|
IMP get1 = [otherArray methodForSelector: oaiSel];
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < c; i++)
|
|
|
|
|
if (![(*get0)(self, oaiSel, i) isEqual: (*get1)(otherArray, oaiSel, i)])
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
1995-04-04 16:01:04 +00:00
|
|
|
|
return YES;
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
- (id) lastObject
|
1995-04-03 22:59:20 +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)
|
|
|
|
|
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];
|
1999-09-14 19:24:58 +00:00
|
|
|
|
|
|
|
|
|
if (i > 0)
|
|
|
|
|
{
|
|
|
|
|
IMP get = [self methodForSelector: oaiSel];
|
|
|
|
|
|
|
|
|
|
while (i-- > 0)
|
|
|
|
|
[(*get)(self, oaiSel, 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
|
|
|
|
}
|
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
- (void) makeObjectsPerformSelector: (SEL)aSelector withObject: (id) arg
|
1995-04-03 22:59:20 +00:00
|
|
|
|
{
|
1998-02-03 14:20:00 +00:00
|
|
|
|
unsigned i = [self count];
|
1999-09-14 19:24:58 +00:00
|
|
|
|
|
|
|
|
|
if (i > 0)
|
|
|
|
|
{
|
|
|
|
|
IMP get = [self methodForSelector: oaiSel];
|
|
|
|
|
|
|
|
|
|
while (i-- > 0)
|
|
|
|
|
[(*get)(self, oaiSel, i) performSelector: aSelector withObject: arg];
|
|
|
|
|
}
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
- (void) makeObjectsPerform: (SEL)aSelector withObject: (id)argument
|
1998-01-19 15:20:15 +00:00
|
|
|
|
{
|
1999-04-08 12:17:15 +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)
|
|
|
|
|
{
|
1999-04-08 12:17:15 +00:00
|
|
|
|
return (int)[elem1 performSelector: comparator withObject: elem2];
|
1997-01-09 16:24:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-14 19:24:58 +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
|
|
|
|
|
{
|
1999-09-14 19:24:58 +00:00
|
|
|
|
return nil;
|
1998-01-19 15:20:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSArray*) sortedArrayUsingFunction: (int(*)(id,id,void*))comparator
|
|
|
|
|
context: (void*)context
|
|
|
|
|
hint: (NSData*)hint
|
|
|
|
|
{
|
|
|
|
|
NSMutableArray *sortedArray;
|
|
|
|
|
NSArray *result;
|
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
sortedArray = [[NSMutableArray_abstract_class allocWithZone:
|
|
|
|
|
NSDefaultMallocZone()] initWithArray: self];
|
1999-04-08 12:17:15 +00:00
|
|
|
|
[sortedArray sortUsingFunction: comparator context: context];
|
1999-09-14 19:24:58 +00:00
|
|
|
|
result = [NSArray_abstract_class arrayWithArray: sortedArray];
|
1999-06-30 21:13:19 +00:00
|
|
|
|
RELEASE(sortedArray);
|
1998-01-19 15:20:15 +00:00
|
|
|
|
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];
|
1999-04-08 12:17:15 +00:00
|
|
|
|
id s = [NSMutableString stringWithCapacity: 2]; /* arbitrary capacity */
|
1995-04-07 21:01:59 +00:00
|
|
|
|
|
|
|
|
|
if (!c)
|
|
|
|
|
return s;
|
1999-04-08 12:17:15 +00:00
|
|
|
|
[s appendString: [[self objectAtIndex: 0] description]];
|
1995-04-07 21:01:59 +00:00
|
|
|
|
for (i = 1; i < c; i++)
|
|
|
|
|
{
|
1999-04-08 12:17:15 +00:00
|
|
|
|
[s appendString: separator];
|
|
|
|
|
[s appendString: [[self objectAtIndex: i] description]];
|
1995-04-07 21:01:59 +00:00
|
|
|
|
}
|
|
|
|
|
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];
|
1999-09-14 19:24:58 +00:00
|
|
|
|
Class cls = [NSString class];
|
|
|
|
|
IMP get = [self methodForSelector: oaiSel];
|
|
|
|
|
IMP add = [a methodForSelector: addSel];
|
|
|
|
|
|
1998-01-19 15:20:15 +00:00
|
|
|
|
for (i = 0; i < c; i++)
|
|
|
|
|
{
|
1999-09-14 19:24:58 +00:00
|
|
|
|
id o = (*get)(self, oaiSel, i);
|
|
|
|
|
|
|
|
|
|
if ([o isKindOfClass: cls])
|
1998-01-19 15:20:15 +00:00
|
|
|
|
if ([extensions containsObject: [o pathExtension]])
|
1999-09-14 19:24:58 +00:00
|
|
|
|
(*add)(a, addSel, o);
|
1998-01-19 15:20:15 +00:00
|
|
|
|
}
|
|
|
|
|
return a;
|
|
|
|
|
}
|
1995-04-03 22:59:20 +00:00
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
- (id) 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++)
|
1999-04-08 12:17:15 +00:00
|
|
|
|
if ([otherArray containsObject: (o = [self objectAtIndex: 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
|
|
|
|
return o;
|
|
|
|
|
return nil;
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-06-04 16:05:45 +00:00
|
|
|
|
- (NSArray*) subarrayWithRange: (NSRange)aRange
|
1995-04-03 22:59:20 +00:00
|
|
|
|
{
|
1996-03-30 19:14:43 +00:00
|
|
|
|
id na;
|
|
|
|
|
unsigned c = [self count];
|
|
|
|
|
|
1999-06-21 08:30:26 +00:00
|
|
|
|
GS_RANGE_CHECK(aRange, c);
|
1996-03-30 19:14:43 +00:00
|
|
|
|
|
1999-06-04 16:05:45 +00:00
|
|
|
|
if (aRange.length == 0)
|
|
|
|
|
return [NSArray array];
|
1996-03-30 19:14:43 +00:00
|
|
|
|
|
1998-10-08 13:46:53 +00:00
|
|
|
|
{
|
1999-06-04 16:05:45 +00:00
|
|
|
|
id objects[aRange.length];
|
1996-03-30 19:14:43 +00:00
|
|
|
|
|
1999-06-04 16:05:45 +00:00
|
|
|
|
[self getObjects: objects range: aRange];
|
|
|
|
|
na = [NSArray arrayWithObjects: objects count: aRange.length];
|
1998-10-08 13:46:53 +00:00
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
{
|
1999-06-30 21:13:19 +00:00
|
|
|
|
return AUTORELEASE([[NSArrayEnumerator allocWithZone: NSDefaultMallocZone()]
|
|
|
|
|
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
|
|
|
|
|
(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
|
|
|
|
|
{
|
1999-06-30 21:13:19 +00:00
|
|
|
|
return AUTORELEASE([[NSArrayEnumeratorReverse allocWithZone: NSDefaultMallocZone()] 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
|
|
|
|
|
(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
|
|
|
|
|
1999-06-30 21:13:19 +00:00
|
|
|
|
result = AUTORELEASE([[NSGMutableCString alloc] initWithCapacity: 20*[self count]]);
|
1998-12-18 17:05:44 +00:00
|
|
|
|
[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;
|
|
|
|
|
IMP appImp;
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
1999-04-08 12:17:15 +00:00
|
|
|
|
if ([item respondsToSelector:
|
1998-12-18 17:05:44 +00:00
|
|
|
|
@selector(descriptionWithLocale:indent:)])
|
|
|
|
|
{
|
|
|
|
|
[item descriptionWithLocale: locale indent: level to: result];
|
1998-01-19 15:20:15 +00:00
|
|
|
|
}
|
1999-04-08 12:17:15 +00:00
|
|
|
|
else if ([item respondsToSelector:
|
1998-12-18 17:05:44 +00:00
|
|
|
|
@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
|
|
|
|
}
|
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
+ (id) allocWithZone: (NSZone*)z
|
1995-04-03 22:59:20 +00:00
|
|
|
|
{
|
1999-09-14 19:24:58 +00:00
|
|
|
|
if (self == NSMutableArray_abstract_class)
|
|
|
|
|
return NSAllocateObject(NSMutableArray_concrete_class, 0, z);
|
1999-01-11 17:28:51 +00:00
|
|
|
|
return [super allocWithZone: z];
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-04-08 12:17:15 +00:00
|
|
|
|
/* The NSCopying Protocol */
|
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
- (id) copyWithZone: (NSZone*)zone
|
1999-04-08 12:17:15 +00:00
|
|
|
|
{
|
|
|
|
|
/* a deep copy */
|
|
|
|
|
unsigned count = [self count];
|
|
|
|
|
id objects[count];
|
|
|
|
|
NSArray *newArray;
|
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
|
|
[self getObjects: objects];
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
|
objects[i] = [objects[i] copyWithZone: zone];
|
1999-09-14 19:24:58 +00:00
|
|
|
|
newArray = [[NSArray_concrete_class allocWithZone: zone]
|
|
|
|
|
initWithObjects: objects count: count];
|
1999-04-08 12:17:15 +00:00
|
|
|
|
while (i > 0)
|
1999-06-30 21:13:19 +00:00
|
|
|
|
RELEASE(objects[--i]);
|
1999-04-08 12:17:15 +00:00
|
|
|
|
return newArray;
|
|
|
|
|
}
|
|
|
|
|
|
(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 */
|
1999-09-14 19:24:58 +00:00
|
|
|
|
- (id) initWithCapacity: (unsigned)numItems
|
1995-04-03 22:59:20 +00:00
|
|
|
|
{
|
1999-04-08 12:17:15 +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
|
|
|
|
{
|
1999-04-08 12:17:15 +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
|
|
|
|
{
|
1999-04-08 12:17:15 +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
|
|
|
|
{
|
1999-04-08 12:17:15 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
1995-04-03 22:59:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-31 22:23:37 +00:00
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@implementation NSMutableArrayNonCore
|
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
+ (id) arrayWithCapacity: (unsigned)numItems
|
1996-03-31 22:23:37 +00:00
|
|
|
|
{
|
1999-06-30 21:13:19 +00:00
|
|
|
|
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
|
|
|
|
|
initWithCapacity: numItems]);
|
1996-03-31 22:23:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
- (BOOL) writeToFile: (NSString *)path atomically: (BOOL)useAuxiliaryFile
|
1998-01-19 15:20:15 +00:00
|
|
|
|
{
|
1999-04-08 12:17:15 +00:00
|
|
|
|
return [[self description] writeToFile: path atomically: useAuxiliaryFile];
|
1998-01-19 15:20:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-31 22:23:37 +00:00
|
|
|
|
/* Override our superclass's designated initializer to go our's */
|
1999-09-14 19:24:58 +00:00
|
|
|
|
- (id) initWithObjects: (id*)objects count: (unsigned)count
|
1996-03-31 22:23:37 +00:00
|
|
|
|
{
|
|
|
|
|
self = [self initWithCapacity: count];
|
1999-09-14 19:24:58 +00:00
|
|
|
|
if (count > 0)
|
|
|
|
|
{
|
|
|
|
|
unsigned i;
|
|
|
|
|
IMP add = [self methodForSelector: addSel];
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
|
(*add)(self, addSel, objects[i]);
|
|
|
|
|
}
|
1996-03-31 22:23:37 +00:00
|
|
|
|
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
|
|
|
|
{
|
1999-09-14 19:24:58 +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."];
|
1999-04-08 12:17:15 +00:00
|
|
|
|
[self removeObjectAtIndex: count-1];
|
1994-11-08 16:44:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
- (void) removeObjectIdenticalTo: (id)anObject
|
1994-11-08 16:44:01 +00:00
|
|
|
|
{
|
1999-11-04 10:42:20 +00:00
|
|
|
|
unsigned i;
|
1996-04-30 14:25:22 +00:00
|
|
|
|
|
1999-11-04 10:42:20 +00:00
|
|
|
|
if (anObject == nil)
|
|
|
|
|
{
|
1999-11-07 14:50:30 +00:00
|
|
|
|
NSWarnMLog(@"attempt to remove nil object", 0);
|
1999-11-04 10:42:20 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
i = [self count];
|
1999-09-14 19:24:58 +00:00
|
|
|
|
if (i > 0)
|
1998-02-03 14:20:00 +00:00
|
|
|
|
{
|
1999-09-14 19:24:58 +00:00
|
|
|
|
IMP rem = 0;
|
|
|
|
|
IMP get = [self methodForSelector: oaiSel];
|
|
|
|
|
|
|
|
|
|
while (i-- > 0)
|
1998-02-03 14:20:00 +00:00
|
|
|
|
{
|
1999-09-14 19:24:58 +00:00
|
|
|
|
id o = (*get)(self, oaiSel, i);
|
|
|
|
|
|
|
|
|
|
if (o == anObject)
|
|
|
|
|
{
|
|
|
|
|
if (rem == 0)
|
|
|
|
|
rem = [self methodForSelector: remSel];
|
|
|
|
|
(*rem)(self, remSel, i);
|
|
|
|
|
}
|
1998-02-03 14:20:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1994-11-08 16:44:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
- (void) removeObject: (id)anObject inRange: (NSRange)aRange
|
1998-01-19 15:20:15 +00:00
|
|
|
|
{
|
1999-11-04 10:42:20 +00:00
|
|
|
|
unsigned c;
|
|
|
|
|
unsigned s;
|
|
|
|
|
unsigned i;
|
1999-09-14 19:24:58 +00:00
|
|
|
|
|
1999-11-04 10:42:20 +00:00
|
|
|
|
if (anObject == nil)
|
|
|
|
|
{
|
1999-11-07 14:50:30 +00:00
|
|
|
|
NSWarnMLog(@"attempt to remove nil object", 0);
|
1999-11-04 10:42:20 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
c = [self count];
|
|
|
|
|
s = aRange.location;
|
|
|
|
|
i = aRange.location + aRange.length;
|
1998-01-19 15:20:15 +00:00
|
|
|
|
if (i > c)
|
1999-11-04 10:42:20 +00:00
|
|
|
|
{
|
|
|
|
|
i = c;
|
|
|
|
|
}
|
1999-09-14 19:24:58 +00:00
|
|
|
|
if (i > s)
|
1998-01-19 15:20:15 +00:00
|
|
|
|
{
|
1999-09-14 19:24:58 +00:00
|
|
|
|
IMP rem = 0;
|
|
|
|
|
IMP get = [self methodForSelector: oaiSel];
|
|
|
|
|
BOOL (*eq)(id, SEL, id)
|
|
|
|
|
= (BOOL (*)(id, SEL, id))[anObject methodForSelector: eqSel];
|
|
|
|
|
|
|
|
|
|
while (i-- > s)
|
1998-02-03 14:20:00 +00:00
|
|
|
|
{
|
1999-09-14 19:24:58 +00:00
|
|
|
|
id o = (*get)(self, oaiSel, i);
|
|
|
|
|
|
|
|
|
|
if (o == anObject || (*eq)(anObject, eqSel, o) == YES)
|
|
|
|
|
{
|
|
|
|
|
if (rem == 0)
|
|
|
|
|
rem = [self methodForSelector: remSel];
|
|
|
|
|
(*rem)(self, remSel, i);
|
|
|
|
|
}
|
1998-02-03 14:20:00 +00:00
|
|
|
|
}
|
1998-01-19 15:20:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
- (void) removeObjectIdenticalTo: (id)anObject inRange: (NSRange)aRange
|
1998-01-19 15:20:15 +00:00
|
|
|
|
{
|
1999-11-04 10:42:20 +00:00
|
|
|
|
unsigned c;
|
|
|
|
|
unsigned s;
|
|
|
|
|
unsigned i;
|
1999-09-14 19:24:58 +00:00
|
|
|
|
|
1999-11-04 10:42:20 +00:00
|
|
|
|
if (anObject == nil)
|
|
|
|
|
{
|
1999-11-07 14:50:30 +00:00
|
|
|
|
NSWarnMLog(@"attempt to remove nil object", 0);
|
1999-11-04 10:42:20 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
c = [self count];
|
|
|
|
|
s = aRange.location;
|
|
|
|
|
i = aRange.location + aRange.length;
|
1998-01-19 15:20:15 +00:00
|
|
|
|
if (i > c)
|
1999-11-04 10:42:20 +00:00
|
|
|
|
{
|
|
|
|
|
i = c;
|
|
|
|
|
}
|
1999-09-14 19:24:58 +00:00
|
|
|
|
if (i > s)
|
1998-01-19 15:20:15 +00:00
|
|
|
|
{
|
1999-09-14 19:24:58 +00:00
|
|
|
|
IMP rem = 0;
|
|
|
|
|
IMP get = [self methodForSelector: oaiSel];
|
|
|
|
|
|
|
|
|
|
while (i-- > s)
|
1998-02-03 14:20:00 +00:00
|
|
|
|
{
|
1999-09-14 19:24:58 +00:00
|
|
|
|
id o = (*get)(self, oaiSel, i);
|
|
|
|
|
|
|
|
|
|
if (o == anObject)
|
|
|
|
|
{
|
|
|
|
|
if (rem == 0)
|
|
|
|
|
rem = [self methodForSelector: remSel];
|
|
|
|
|
(*rem)(self, remSel, i);
|
|
|
|
|
}
|
1998-02-03 14:20:00 +00:00
|
|
|
|
}
|
1998-01-19 15:20:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
- (void) removeObject: (id)anObject
|
1994-11-08 16:44:01 +00:00
|
|
|
|
{
|
1999-11-04 10:42:20 +00:00
|
|
|
|
unsigned i;
|
1996-04-30 14:25:22 +00:00
|
|
|
|
|
1999-11-04 10:42:20 +00:00
|
|
|
|
if (anObject == nil)
|
|
|
|
|
{
|
1999-11-07 14:50:30 +00:00
|
|
|
|
NSWarnMLog(@"attempt to remove nil object", 0);
|
1999-11-04 10:42:20 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
i = [self count];
|
1999-09-14 19:24:58 +00:00
|
|
|
|
if (i > 0)
|
1998-02-03 14:20:00 +00:00
|
|
|
|
{
|
1999-09-14 19:24:58 +00:00
|
|
|
|
IMP rem = 0;
|
|
|
|
|
IMP get = [self methodForSelector: oaiSel];
|
|
|
|
|
BOOL (*eq)(id, SEL, id)
|
|
|
|
|
= (BOOL (*)(id, SEL, id))[anObject methodForSelector: eqSel];
|
|
|
|
|
|
|
|
|
|
while (i-- > 0)
|
1998-02-03 14:20:00 +00:00
|
|
|
|
{
|
1999-09-14 19:24:58 +00:00
|
|
|
|
id o = (*get)(self, oaiSel, i);
|
|
|
|
|
|
|
|
|
|
if (o == anObject || (*eq)(anObject, eqSel, o) == YES)
|
|
|
|
|
{
|
|
|
|
|
if (rem == 0)
|
|
|
|
|
rem = [self methodForSelector: remSel];
|
|
|
|
|
(*rem)(self, remSel, i);
|
|
|
|
|
}
|
1998-02-03 14:20:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
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
|
|
|
|
{
|
1999-09-14 19:24:58 +00:00
|
|
|
|
unsigned c = [self count];
|
|
|
|
|
|
|
|
|
|
if (c > 0)
|
|
|
|
|
{
|
|
|
|
|
IMP remLast = [self methodForSelector: rlSel];
|
|
|
|
|
|
|
|
|
|
while (c--)
|
|
|
|
|
(*remLast)(self, rlSel);
|
|
|
|
|
}
|
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
|
|
|
|
{
|
1999-09-14 19:24:58 +00:00
|
|
|
|
unsigned c = [otherArray count];
|
|
|
|
|
|
|
|
|
|
if (c > 0)
|
|
|
|
|
{
|
|
|
|
|
unsigned i;
|
|
|
|
|
IMP get = [otherArray methodForSelector: oaiSel];
|
|
|
|
|
IMP add = [self methodForSelector: addSel];
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < c; i++)
|
|
|
|
|
(*add)(self, addSel, (*get)(otherArray, oaiSel, i));
|
|
|
|
|
}
|
1994-11-08 16:44:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-04-08 12:17:15 +00:00
|
|
|
|
- (void) setArray: (NSArray *)otherArray
|
1996-03-30 19:14:43 +00:00
|
|
|
|
{
|
|
|
|
|
[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;
|
|
|
|
|
}
|
1999-02-16 16:18:26 +00:00
|
|
|
|
else if (sorted[i] != val)
|
1999-02-16 16:08:59 +00:00
|
|
|
|
{
|
|
|
|
|
unsigned j = to++;
|
|
|
|
|
|
1999-02-16 16:18:26 +00:00
|
|
|
|
if (sorted[i] < val)
|
|
|
|
|
{
|
|
|
|
|
i++;
|
|
|
|
|
}
|
1999-02-16 16:08:59 +00:00
|
|
|
|
while (j > i)
|
|
|
|
|
{
|
|
|
|
|
sorted[j] = sorted[j-1];
|
|
|
|
|
j--;
|
|
|
|
|
}
|
|
|
|
|
sorted[i] = val;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
if (to > 0)
|
1999-02-16 16:08:59 +00:00
|
|
|
|
{
|
1999-09-14 19:24:58 +00:00
|
|
|
|
IMP rem = [self methodForSelector: remSel];
|
|
|
|
|
|
|
|
|
|
while (to--)
|
|
|
|
|
{
|
|
|
|
|
(*rem)(self, remSel, sorted[to]);
|
|
|
|
|
}
|
1999-02-16 16:08:59 +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) removeObjectsInArray: (NSArray*)otherArray
|
|
|
|
|
{
|
1999-09-14 19:24:58 +00:00
|
|
|
|
unsigned c = [otherArray count];
|
|
|
|
|
|
|
|
|
|
if (c > 0)
|
|
|
|
|
{
|
|
|
|
|
unsigned i;
|
|
|
|
|
IMP get = [otherArray methodForSelector: oaiSel];
|
|
|
|
|
IMP rem = [self methodForSelector: @selector(removeObject:)];
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < c; i++)
|
|
|
|
|
(*rem)(self, @selector(removeObject:), (*get)(otherArray, oaiSel, i));
|
|
|
|
|
}
|
1994-11-08 16:44:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-01-19 15:20:15 +00:00
|
|
|
|
- (void) removeObjectsInRange: (NSRange)aRange
|
|
|
|
|
{
|
1999-09-14 19:24:58 +00:00
|
|
|
|
unsigned i;
|
|
|
|
|
unsigned s = aRange.location;
|
|
|
|
|
unsigned c = [self count];
|
|
|
|
|
|
1998-01-19 15:20:15 +00:00
|
|
|
|
i = aRange.location + aRange.length;
|
1999-09-14 19:24:58 +00:00
|
|
|
|
|
1998-01-19 15:20:15 +00:00
|
|
|
|
if (c < i)
|
|
|
|
|
i = c;
|
1999-09-14 19:24:58 +00:00
|
|
|
|
|
|
|
|
|
if (i > s)
|
|
|
|
|
{
|
|
|
|
|
IMP rem = [self methodForSelector: remSel];
|
|
|
|
|
|
|
|
|
|
while (i-- > s)
|
|
|
|
|
(*rem)(self, remSel, i);
|
|
|
|
|
}
|
1998-01-19 15:20:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
1997-09-01 21:59:51 +00:00
|
|
|
|
- (void) sortUsingSelector: (SEL)comparator
|
|
|
|
|
{
|
|
|
|
|
int compare(id elem1, id elem2, void* context)
|
|
|
|
|
{
|
1999-04-08 12:17:15 +00:00
|
|
|
|
return (int)[elem1 performSelector: comparator withObject: elem2];
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
[self sortUsingFunction: compare context: NULL];
|
1997-09-01 21:59:51 +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) 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;
|
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
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;
|
|
|
|
|
if (stride > c)
|
1998-02-03 14:20:00 +00:00
|
|
|
|
break;
|
1999-09-14 19:24:58 +00:00
|
|
|
|
d = c - stride;
|
|
|
|
|
while (!found)
|
|
|
|
|
{
|
|
|
|
|
// move to left until correct place
|
|
|
|
|
id a = [self objectAtIndex: d + stride];
|
|
|
|
|
id b = [self objectAtIndex: d];
|
|
|
|
|
if ((*compare)(a, b, context) == NSOrderedAscending)
|
|
|
|
|
{
|
1999-09-28 19:35:09 +00:00
|
|
|
|
IF_NO_GC(RETAIN(a));
|
1999-09-14 19:24:58 +00:00
|
|
|
|
[self replaceObjectAtIndex: d + stride withObject: b];
|
|
|
|
|
[self replaceObjectAtIndex: d withObject: a];
|
|
|
|
|
RELEASE(a);
|
|
|
|
|
if (stride > d)
|
|
|
|
|
break;
|
|
|
|
|
d -= stride; // jump by stride factor
|
|
|
|
|
}
|
|
|
|
|
else found = YES;
|
|
|
|
|
}
|
1997-01-09 16:24:07 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
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
|
|
|
|
|
{
|
1999-09-14 19:24:58 +00:00
|
|
|
|
NSArray *array;
|
|
|
|
|
unsigned pos;
|
|
|
|
|
IMP get;
|
|
|
|
|
unsigned (*cnt)(NSArray*, SEL);
|
1996-03-31 22:23:37 +00:00
|
|
|
|
}
|
1999-09-14 19:24:58 +00:00
|
|
|
|
- (id) initWithArray: (NSArray*)anArray;
|
1996-03-31 22:23:37 +00:00
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation NSArrayEnumerator
|
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
- (id) initWithArray: (NSArray*)anArray
|
1996-03-31 22:23:37 +00:00
|
|
|
|
{
|
|
|
|
|
[super init];
|
|
|
|
|
array = anArray;
|
1999-09-28 19:35:09 +00:00
|
|
|
|
IF_NO_GC(RETAIN(array));
|
1999-09-14 19:24:58 +00:00
|
|
|
|
pos = 0;
|
|
|
|
|
get = [array methodForSelector: oaiSel];
|
|
|
|
|
cnt = (unsigned (*)(NSArray*, SEL))[array methodForSelector: countSel];
|
1996-03-31 22:23:37 +00:00
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) nextObject
|
|
|
|
|
{
|
1999-09-14 19:24:58 +00:00
|
|
|
|
if (pos >= (*cnt)(array, countSel))
|
1996-03-31 22:23:37 +00:00
|
|
|
|
return nil;
|
1999-09-14 19:24:58 +00:00
|
|
|
|
return (*get)(array, oaiSel, pos++);
|
1996-03-31 22:23:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
|
{
|
1999-06-30 21:13:19 +00:00
|
|
|
|
RELEASE(array);
|
1996-03-31 22:23:37 +00:00
|
|
|
|
[super dealloc];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@interface NSArrayEnumeratorReverse : NSArrayEnumerator
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation NSArrayEnumeratorReverse
|
|
|
|
|
|
1999-09-14 19:24:58 +00:00
|
|
|
|
- (id) initWithArray: (NSArray*)anArray
|
1996-03-31 22:23:37 +00:00
|
|
|
|
{
|
1999-09-14 19:24:58 +00:00
|
|
|
|
[super initWithArray: anArray];
|
|
|
|
|
pos = (*cnt)(array, countSel);
|
1996-03-31 22:23:37 +00:00
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) nextObject
|
|
|
|
|
{
|
1999-09-14 19:24:58 +00:00
|
|
|
|
if (pos == 0)
|
1996-03-31 22:23:37 +00:00
|
|
|
|
return nil;
|
1999-09-14 19:24:58 +00:00
|
|
|
|
return (*get)(array, oaiSel, --pos);
|
1996-03-31 22:23:37 +00:00
|
|
|
|
}
|
1999-02-20 19:59:45 +00:00
|
|
|
|
@end
|