Differences From Artifact [e0ede1483b]:
- File
src/OFMutableArray.m
— part of check-in
[c86b8f10f0]
at
2022-11-16 01:27:26
on branch trunk
— Add OFAssert()
This uses the same format as OFEnsure(). (user: js, size: 9209) [annotate] [blame] [check-ins using] [more...]
To Artifact [221f6c44e1]:
- File src/OFMutableArray.m — part of check-in [c911523834] at 2022-12-25 18:01:10 on branch trunk — Add -[sortedArrayUsingFunction:context:options:] (user: js, size: 9678) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
83 84 85 86 87 88 89 | if (i > 0) quicksort(array, left, i - 1, selector, options); left = i + 1; } } | < | | | | | | | > | | < | 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | if (i > 0) quicksort(array, left, i - 1, selector, options); left = i + 1; } } static void quicksortWithFunction(OFMutableArray *array, size_t left, size_t right, OFCompareFunction compare, void *context, OFArraySortOptions options) { OFComparisonResult ascending, descending; if (options & OFArraySortDescending) { ascending = OFOrderedDescending; descending = OFOrderedAscending; } else { ascending = OFOrderedAscending; descending = OFOrderedDescending; } while (left < right) { size_t i = left; size_t j = right - 1; id pivot = [array objectAtIndex: right]; do { while (compare([array objectAtIndex: i], pivot, context) != descending && i < right) i++; while (compare([array objectAtIndex: j], pivot, context) != ascending && j > left) j--; if (i < j) [array exchangeObjectAtIndex: i withObjectAtIndex: j]; } while (i < j); if (compare([array objectAtIndex: i], pivot, context) == descending) [array exchangeObjectAtIndex: i withObjectAtIndex: right]; if (i > 0) quicksortWithFunction(array, left, i - 1, compare, context, options); left = i + 1; } } @implementation OFMutableArrayPlaceholder - (instancetype)init { return (id)[[OFMutableAdjacentArray alloc] init]; } |
︙ | ︙ | |||
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 | size_t count = self.count; if (count == 0 || count == 1) return; quicksort(self, 0, count - 1, selector, options); } #ifdef OF_HAVE_BLOCKS - (void)sortUsingComparator: (OFComparator)comparator options: (OFArraySortOptions)options { size_t count = self.count; if (count == 0 || count == 1) return; | > > > > > > > > > > > > > > > > > > > > | > | 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 | size_t count = self.count; if (count == 0 || count == 1) return; quicksort(self, 0, count - 1, selector, options); } - (void)sortUsingFunction: (OFCompareFunction)compare context: (void *)context options: (OFArraySortOptions)options { size_t count = self.count; if (count == 0 || count == 1) return; quicksortWithFunction(self, 0, count - 1, compare, context, options); } #ifdef OF_HAVE_BLOCKS static OFComparisonResult blockCompare(id left, id right, void *context) { OFComparator block = (OFComparator)context; return block(left, right); } - (void)sortUsingComparator: (OFComparator)comparator options: (OFArraySortOptions)options { size_t count = self.count; if (count == 0 || count == 1) return; quicksortWithFunction(self, 0, count - 1, blockCompare, comparator, options); } #endif - (void)reverse { size_t i, j, count = self.count; |
︙ | ︙ |