+ return lhs;
+}
+
+void CYRadixSortUsingFunction(id *self, size_t count, MenesRadixSortFunction function, void *argument) {
+ struct RadixItem_ *swap(new RadixItem_[count * 2]);
+
+ for (size_t i(0); i != count; ++i) {
+ RadixItem_ &item(swap[i]);
+ item.index = i;
+ item.key = function(self[i], argument);
+ }
+
+ auto lhs(CYRadixSort(swap, count));
+
+ const void **values(new const void *[count]);
+ for (size_t i(0); i != count; ++i)
+ values[i] = self[lhs[i].index];
+ memcpy(self, values, count * sizeof(id));
+ delete [] values;
+
+ delete [] swap;
+}
+
+@implementation NSMutableArray (MenesRadixSortWithSelector)
+
+- (void) radixSortUsingFunction:(MenesRadixSortFunction)function withContext:(void *)argument {
+ size_t count([self count]);
+ struct RadixItem_ *swap(new RadixItem_[count * 2]);
+
+ for (size_t i(0); i != count; ++i) {
+ RadixItem_ &item(swap[i]);
+ item.index = i;
+ item.key = function([self objectAtIndex:i], argument);
+ }
+
+ auto lhs(CYRadixSort(swap, count));