22 + (CPArray)arrayWithCapacity:(CPUInteger)aCapacity
24 return [[
self alloc] initWithCapacity:aCapacity];
41 - (void)addObject:(
id)anObject
43 _CPRaiseInvalidAbstractInvocation(
self, _cmd);
50 - (void)addObjectsFromArray:(CPArray)anArray
53 count = [anArray count];
55 for (; index < count; ++index)
56 [
self addObject:[anArray objectAtIndex:index]];
64 - (void)insertObject:(
id)anObject atIndex:(CPUInteger)anIndex
66 _CPRaiseInvalidAbstractInvocation(
self, _cmd);
74 - (void)insertObjects:(CPArray)objects atIndexes:(
CPIndexSet)indexes
76 var indexesCount = [indexes
count],
77 objectsCount = [objects count];
79 if (indexesCount !== objectsCount)
80 [
CPException raise:CPRangeException
reason:"the counts of the passed-in array (" + objectsCount + ") and index set (" + indexesCount + ") must be identical."];
84 if (lastIndex >= [
self count] + indexesCount)
85 [
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 + ")."];
91 [
self insertObject:[objects objectAtIndex:index] atIndex:currentIndex];
94 - (CPUInteger)insertObject:(
id)anObject inArraySortedByDescriptors:(CPArray)descriptors
97 count = [descriptors count];
100 index = [
self indexOfObject:anObject
102 options:CPBinarySearchingInsertionIndex
103 usingComparator:function(lhs, rhs)
106 result = CPOrderedSame;
108 while (index < count && ((result = [[descriptors objectAtIndex:index] compareObject:lhs withObject:rhs]) === CPOrderedSame))
115 index = [
self count];
127 - (void)replaceObjectAtIndex:(CPUInteger)anIndex withObject:(
id)anObject
129 _CPRaiseInvalidAbstractInvocation(
self, _cmd);
138 - (void)replaceObjectsAtIndexes:(
CPIndexSet)indexes withObjects:(CPArray)objects
158 - (void)replaceObjectsInRange:(CPRange)aRange withObjectsFromArray:(CPArray)anArray range:(CPRange)otherRange
162 if (otherRange && (otherRange.location !== 0 || otherRange.length !== [anArray count]))
163 anArray = [anArray subarrayWithRange:otherRange];
177 - (void)replaceObjectsInRange:(CPRange)aRange withObjectsFromArray:(CPArray)anArray
186 - (void)setArray:(CPArray)anArray
188 if (
self === anArray)
199 - (void)removeAllObjects
208 - (void)removeLastObject
210 _CPRaiseInvalidAbstractInvocation(
self, _cmd);
217 - (void)removeObject:(
id)anObject
227 - (void)removeObject:(
id)anObject inRange:(CPRange)aRange
231 while ((index = [
self indexOfObject:anObject inRange:aRange]) !=
CPNotFound)
242 - (void)removeObjectAtIndex:(CPUInteger)anIndex
244 _CPRaiseInvalidAbstractInvocation(
self, _cmd);
267 - (void)removeObjectIdenticalTo:(
id)anObject
279 - (void)removeObjectIdenticalTo:(
id)anObject inRange:(CPRange)aRange
282 count = [
self count];
284 while ((index = [
self indexOfObjectIdenticalTo:anObject inRange:aRange]) !==
CPNotFound)
295 - (void)removeObjectsInArray:(CPArray)anArray
298 count = [anArray count];
300 for (; index < count; ++index)
301 [
self removeObject:[anArray objectAtIndex:index]];
308 - (void)removeObjectsInRange:(CPRange)aRange
310 var index = aRange.location,
313 while (count-- > index)
323 - (void)exchangeObjectAtIndex:(CPUInteger)anIndex withObjectAtIndex:(CPUInteger)otherIndex
325 if (anIndex === otherIndex)
328 var temporary = [
self objectAtIndex:anIndex];
334 - (void)sortUsingDescriptors:(CPArray)descriptors
336 var i = [descriptors count],
342 var d = [descriptors objectAtIndex:i];
343 [jsDescriptors addObject:{ "k": [d key], "a": [d ascending], "s": [d selector]}];
345 sortArrayUsingJSDescriptors(
self, jsDescriptors);
353 - (void)sortUsingFunction:(Function)aFunction context:(
id)aContext
362 - (void)sortUsingSelector:(
SEL)aSelector
374 [r addObjectsFromArray:self];
382 return [object1 performSelector:selector withObject:object2];
399 for (h = 1; h < n; h += h)
401 for (m = n - 1 - h; m >= 0; m -= h + h)
407 for (i = 0, j = l; j <= m; i++, j++)
410 for (i = 0, k = l; k < j && j <= m + h; k++)
413 o = aFunction(A, B[i], aContext);
434 var sortArrayUsingJSDescriptors =
function(a, d)
458 cpNull = CPMutableArrayNull;
463 for (h = 1; h < n; h += h)
465 for (m = n - 1 - h; m >= 0; m -= h + h)
472 for (i = 0, j = l; j <= m; i++, j++)
475 for (i = 0, k = l; k < j && j <= m + h; k++)
493 C1[key] = [A valueForKeyPath:key];
514 C2[key] = [B[i] valueForKeyPath:key];
528 if (value1 === nil || value1 === cpNull)
531 o = value2 === nil || value2 === cpNull ?
CPOrderedDescending : value1.isa.objj_msgSend1(value1, dd.s, value2);
void addObjectsFromArray:(CPArray anArray)
Used to implement exception handling (creating & raising).
void insertObjects:atIndexes:(CPArray objects, [atIndexes] CPIndexSet indexes)
An object representation of nil.
void removeObjectIdenticalTo:inRange:(id anObject, [inRange] CPRange aRange)
void raise:reason:(CPString aName, [reason] CPString aReason)
A collection of unique integers.
void removeObjectsInRange:(CPRange aRange)
function CPMaxRange(aRange)
CPInteger indexGreaterThanIndex:(CPInteger anIndex)
void replaceObjectAtIndex:withObject:(CPUInteger anIndex, [withObject] id anObject)
var sortArrayUsingFunction
function CPIntersectionRange(lhsRange, rhsRange)
void removeObject:inRange:(id anObject, [inRange] CPRange aRange)
void replaceObjectsInRange:withObjectsFromArray:range:(CPRange aRange, [withObjectsFromArray] CPArray anArray, [range] CPRange otherRange)
void insertObject:atIndex:(id anObject, [atIndex] CPUInteger anIndex)
void removeObjectAtIndex:(CPUInteger anIndex)
CPInteger indexLessThanIndex:(CPInteger anIndex)
id indexSetWithIndexesInRange:(CPRange aRange)
CPRange function CPMakeRange(location, length)