@@ -32,32 +32,32 @@ } placeholder; @interface OFMutableArrayPlaceholder: OFMutableArray @end -static of_comparison_result_t +static OFComparisonResult compare(id left, id right, SEL selector) { - of_comparison_result_t (*comparator)(id, SEL, id) = - (of_comparison_result_t (*)(id, SEL, id)) + OFComparisonResult (*comparator)(id, SEL, id) = + (OFComparisonResult (*)(id, SEL, id)) [left methodForSelector: selector]; return comparator(left, selector, right); } static void quicksort(OFMutableArray *array, size_t left, size_t right, SEL selector, - int options) + OFArraySortOptions options) { - of_comparison_result_t ascending, descending; + OFComparisonResult ascending, descending; - if (options & OF_ARRAY_SORT_DESCENDING) { - ascending = OF_ORDERED_DESCENDING; - descending = OF_ORDERED_ASCENDING; + if (options & OFArraySortDescending) { + ascending = OFOrderedDescending; + descending = OFOrderedAscending; } else { - ascending = OF_ORDERED_ASCENDING; - descending = OF_ORDERED_DESCENDING; + ascending = OFOrderedAscending; + descending = OFOrderedDescending; } while (left < right) { size_t i = left; size_t j = right - 1; @@ -90,20 +90,20 @@ } #ifdef OF_HAVE_BLOCKS static void quicksortWithBlock(OFMutableArray *array, size_t left, size_t right, - of_comparator_t comparator, int options) + OFComparator comparator, OFArraySortOptions options) { - of_comparison_result_t ascending, descending; + OFComparisonResult ascending, descending; - if (options & OF_ARRAY_SORT_DESCENDING) { - ascending = OF_ORDERED_DESCENDING; - descending = OF_ORDERED_ASCENDING; + if (options & OFArraySortDescending) { + ascending = OFOrderedDescending; + descending = OFOrderedAscending; } else { - ascending = OF_ORDERED_ASCENDING; - descending = OF_ORDERED_DESCENDING; + ascending = OFOrderedAscending; + descending = OFOrderedDescending; } while (left < right) { size_t i = left; size_t j = right - 1; @@ -163,12 +163,11 @@ va_end(arguments); return ret; } -- (instancetype)initWithObject: (id)firstObject - arguments: (va_list)arguments +- (instancetype)initWithObject: (id)firstObject arguments: (va_list)arguments { return (id)[[OFMutableAdjacentArray alloc] initWithObject: firstObject arguments: arguments]; } @@ -175,12 +174,11 @@ - (instancetype)initWithArray: (OFArray *)array { return (id)[[OFMutableAdjacentArray alloc] initWithArray: array]; } -- (instancetype)initWithObjects: (id const *)objects - count: (size_t)count +- (instancetype)initWithObjects: (id const *)objects count: (size_t)count { return (id)[[OFMutableAdjacentArray alloc] initWithObjects: objects count: count]; } @@ -255,51 +253,42 @@ return [[OFArray alloc] initWithArray: self]; } - (void)addObject: (id)object { - [self insertObject: object - atIndex: self.count]; + [self insertObject: object atIndex: self.count]; } - (void)addObjectsFromArray: (OFArray *)array { - [self insertObjectsFromArray: array - atIndex: self.count]; + [self insertObjectsFromArray: array atIndex: self.count]; } -- (void)insertObject: (id)object - atIndex: (size_t)idx +- (void)insertObject: (id)object atIndex: (size_t)idx { OF_UNRECOGNIZED_SELECTOR } -- (void)insertObjectsFromArray: (OFArray *)array - atIndex: (size_t)idx +- (void)insertObjectsFromArray: (OFArray *)array atIndex: (size_t)idx { size_t i = 0; for (id object in array) - [self insertObject: object - atIndex: idx + i++]; + [self insertObject: object atIndex: idx + i++]; } -- (void)replaceObjectAtIndex: (size_t)idx - withObject: (id)object +- (void)replaceObjectAtIndex: (size_t)idx withObject: (id)object { OF_UNRECOGNIZED_SELECTOR } -- (void)setObject: (id)object - atIndexedSubscript: (size_t)idx +- (void)setObject: (id)object atIndexedSubscript: (size_t)idx { - [self replaceObjectAtIndex: idx - withObject: object]; + [self replaceObjectAtIndex: idx withObject: object]; } -- (void)replaceObject: (id)oldObject - withObject: (id)newObject +- (void)replaceObject: (id)oldObject withObject: (id)newObject { size_t count; if (oldObject == nil || newObject == nil) @throw [OFInvalidArgumentException exception]; @@ -306,19 +295,17 @@ count = self.count; for (size_t i = 0; i < count; i++) { if ([[self objectAtIndex: i] isEqual: oldObject]) { - [self replaceObjectAtIndex: i - withObject: newObject]; + [self replaceObjectAtIndex: i withObject: newObject]; return; } } } -- (void)replaceObjectIdenticalTo: (id)oldObject - withObject: (id)newObject +- (void)replaceObjectIdenticalTo: (id)oldObject withObject: (id)newObject { size_t count; if (oldObject == nil || newObject == nil) @throw [OFInvalidArgumentException exception]; @@ -325,12 +312,11 @@ count = self.count; for (size_t i = 0; i < count; i++) { if ([self objectAtIndex: i] == oldObject) { - [self replaceObjectAtIndex: i - withObject: newObject]; + [self replaceObjectAtIndex: i withObject: newObject]; return; } } } @@ -374,11 +360,11 @@ return; } } } -- (void)removeObjectsInRange: (of_range_t)range +- (void)removeObjectsInRange: (OFRange)range { for (size_t i = 0; i < range.length; i++) [self removeObjectAtIndex: range.location]; } @@ -392,52 +378,47 @@ [self removeObjectAtIndex: count - 1]; } - (void)removeAllObjects { - [self removeObjectsInRange: of_range(0, self.count)]; + [self removeObjectsInRange: OFRangeMake(0, self.count)]; } #ifdef OF_HAVE_BLOCKS -- (void)replaceObjectsUsingBlock: (of_array_replace_block_t)block +- (void)replaceObjectsUsingBlock: (OFArrayReplaceBlock)block { [self enumerateObjectsUsingBlock: ^ (id object, size_t idx, bool *stop) { id new = block(object, idx); if (new != object) - [self replaceObjectAtIndex: idx - withObject: new]; + [self replaceObjectAtIndex: idx withObject: new]; }]; } #endif -- (void)exchangeObjectAtIndex: (size_t)idx1 - withObjectAtIndex: (size_t)idx2 +- (void)exchangeObjectAtIndex: (size_t)idx1 withObjectAtIndex: (size_t)idx2 { id object1 = [self objectAtIndex: idx1]; id object2 = [self objectAtIndex: idx2]; [object1 retain]; @try { - [self replaceObjectAtIndex: idx1 - withObject: object2]; - [self replaceObjectAtIndex: idx2 - withObject: object1]; + [self replaceObjectAtIndex: idx1 withObject: object2]; + [self replaceObjectAtIndex: idx2 withObject: object1]; } @finally { [object1 release]; } } - (void)sort { - [self sortUsingSelector: @selector(compare:) - options: 0]; + [self sortUsingSelector: @selector(compare:) options: 0]; } - (void)sortUsingSelector: (SEL)selector - options: (int)options + options: (OFArraySortOptions)options { size_t count = self.count; if (count == 0 || count == 1) return; @@ -444,12 +425,12 @@ quicksort(self, 0, count - 1, selector, options); } #ifdef OF_HAVE_BLOCKS -- (void)sortUsingComparator: (of_comparator_t)comparator - options: (int)options +- (void)sortUsingComparator: (OFComparator)comparator + options: (OFArraySortOptions)options { size_t count = self.count; if (count == 0 || count == 1) return; @@ -464,13 +445,12 @@ if (count == 0 || count == 1) return; for (i = 0, j = count - 1; i < j; i++, j--) - [self exchangeObjectAtIndex: i - withObjectAtIndex: j]; + [self exchangeObjectAtIndex: i withObjectAtIndex: j]; } - (void)makeImmutable { } @end