23 + (
CPArray)arrayWithCapacity:(
unsigned)aCapacity
25 return [[
self alloc] initWithCapacity:aCapacity];
42 - (void)addObject:(
id)anObject
44 _CPRaiseInvalidAbstractInvocation(
self, _cmd);
51 - (void)addObjectsFromArray:(
CPArray)anArray
54 count = [anArray
count];
56 for (; index < count; ++index)
57 [
self addObject:[anArray objectAtIndex:index]];
65 - (void)insertObject:(
id)anObject atIndex:(
int)anIndex
67 _CPRaiseInvalidAbstractInvocation(
self, _cmd);
77 var indexesCount = [indexes
count],
78 objectsCount = [objects
count];
80 if (indexesCount !== objectsCount)
81 [
CPException raise:CPRangeException
reason:"the counts of the passed-in array (" + objectsCount + ") and index set (" + indexesCount + ") must be identical."];
85 if (lastIndex >= [
self count] + indexesCount)
86 [
CPException raise:CPRangeException
reason:"the last index (" + lastIndex + ") must be less than the sum of the original count (" + [
self count] + ") and the insertion count (" + indexesCount + ")."];
92 [
self insertObject:[objects objectAtIndex:index] atIndex:currentIndex];
95 - (unsigned)insertObject:(
id)anObject inArraySortedByDescriptors:(
CPArray)descriptors
98 count = [descriptors
count];
103 options:CPBinarySearchingInsertionIndex
107 result = CPOrderedSame;
116 index = [
self count];
128 - (void)replaceObjectAtIndex:(
int)anIndex withObject:(
id)anObject
130 _CPRaiseInvalidAbstractInvocation(
self, _cmd);
159 - (void)replaceObjectsInRange:(CPRange)aRange withObjectsFromArray:(
CPArray)anArray range:(CPRange)otherRange
163 if (otherRange && (otherRange.location !== 0 || otherRange.length !== [anArray count]))
178 - (void)replaceObjectsInRange:(CPRange)aRange withObjectsFromArray:(
CPArray)anArray
189 if (
self === anArray)
200 - (void)removeAllObjects
209 - (void)removeLastObject
211 _CPRaiseInvalidAbstractInvocation(
self, _cmd);
218 - (void)removeObject:(
id)anObject
228 - (void)removeObject:(
id)anObject inRange:(CPRange)aRange
232 while ((index = [
self indexOfObject:anObject inRange:aRange]) !=
CPNotFound)
243 - (void)removeObjectAtIndex:(
int)anIndex
245 _CPRaiseInvalidAbstractInvocation(
self, _cmd);
268 - (void)removeObjectIdenticalTo:(
id)anObject
280 - (void)removeObjectIdenticalTo:(
id)anObject inRange:(CPRange)aRange
283 count = [
self count];
285 while ((index = [
self indexOfObjectIdenticalTo:anObject inRange:aRange]) !==
CPNotFound)
299 count = [anArray
count];
301 for (; index < count; ++index)
302 [
self removeObject:[anArray objectAtIndex:index]];
309 - (void)removeObjectsInRange:(CPRange)aRange
311 var index = aRange.location,
312 count = CPMaxRange(aRange);
314 while (count-- > index)
324 - (void)exchangeObjectAtIndex:(
unsigned)anIndex withObjectAtIndex:(
unsigned)otherIndex
326 if (anIndex === otherIndex)
335 - (void)sortUsingDescriptors:(
CPArray)descriptors
337 var i = [descriptors
count],
344 [jsDescriptors addObject:{ "k": [d key], "a": [d ascending], "s": [d selector]}];
346 sortArrayUsingJSDescriptors(
self, jsDescriptors);
354 - (void)sortUsingFunction:(Function)aFunction context:(
id)aContext
356 sortArrayUsingFunction(
self, aFunction, aContext);
363 - (void)sortUsingSelector:(
SEL)aSelector
375 [r addObjectsFromArray:self];
383 return [object1 performSelector:selector withObject:object2];
386 var sortArrayUsingFunction =
function(array, aFunction, aContext)
400 for (h = 1; h < n; h += h)
402 for (m = n - 1 - h; m >= 0; m -= h + h)
408 for (i = 0, j = l; j <= m; i++, j++)
411 for (i = 0, k = l; k < j && j <= m + h; k++)
414 o = aFunction(A, B[i], aContext);
432 var sortArrayUsingJSDescriptors =
function(a, d)
458 for (h = 1; h < n; h += h)
460 for (m = n - 1 - h; m >= 0; m -= h + h)
467 for (i = 0, j = l; j <= m; i++, j++)
470 for (i = 0, k = l; k < j && j <= m + h; k++)
488 C1[key] = [A valueForKeyPath:key];
509 C2[key] = [B[i] valueForKeyPath:key];
521 o = objj_msgSend(C1[key], dd.s, C2[key]);