diff options
author | rowanbeentje <rowan@beent.je> | 2009-07-28 01:02:40 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2009-07-28 01:02:40 +0000 |
commit | 9c06d1219c66acc043b5f13ab29379f60eb00350 (patch) | |
tree | 57f6a57ad8a10552eb22a372fdbf297522d39d65 /Source/NSMutableArray-MultipleSort.m | |
parent | 9b827edbb16a50f3e0c42e0f1c21a9bca3e7a77b (diff) | |
download | sequelpro-9c06d1219c66acc043b5f13ab29379f60eb00350.tar.gz sequelpro-9c06d1219c66acc043b5f13ab29379f60eb00350.tar.bz2 sequelpro-9c06d1219c66acc043b5f13ab29379f60eb00350.zip |
Improve TablesList significantly:
- If there are twenty or more tables, show a table quicksearch/filter at the top of the list, and update the rest of the code to match. This addresses issue #178.
- Select tables and views alphabetically by user's current locale (instead of default MySQL "A B C a b c")
- When adding or duplicating tables, insert them at the correct point
- Fix a number of minor display bugs caused by incorrect interaction with the tables list caches
Diffstat (limited to 'Source/NSMutableArray-MultipleSort.m')
-rw-r--r-- | Source/NSMutableArray-MultipleSort.m | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/Source/NSMutableArray-MultipleSort.m b/Source/NSMutableArray-MultipleSort.m new file mode 100644 index 00000000..f98732b7 --- /dev/null +++ b/Source/NSMutableArray-MultipleSort.m @@ -0,0 +1,77 @@ +// +// NSMutableArray-MultipleSort.m +// iContractor +// +// Created by Jeff LaMarche on 1/16/09. +// Copyright 2009 Jeff LaMarche Consulting. All rights reserved. +// +// This source may be used, free of charge, for any purposes. commercial or non- +// commercial. There is no attribution requirement, nor any need to distribute +// your source code. If you do redistribute the source code, you must +// leave the original header comments, but you may add additional ones. + +#import "NSMutableArray-MultipleSort.h" + +@implementation NSMutableArray(MultipleSort) +- (void)sortArrayUsingSelector:(SEL)comparator withPairedMutableArrays:(NSMutableArray *)array1, ... +{ + unsigned int stride = 1; + BOOL found = NO; + unsigned int count = [self count]; + unsigned int d; + + while (stride <= count) + stride = stride * STRIDE_FACTOR + 1; + + while (stride > (STRIDE_FACTOR - 1)) { + stride = stride / STRIDE_FACTOR; + for (unsigned int c = stride; c < count; c++) { + found = NO; + if (stride > c) break; + + d = c - stride; + while (!found) { + id a = [self objectAtIndex: d + stride]; + id b = [self objectAtIndex: d]; + + NSComparisonResult result = (*compare)(a, b, (void *)comparator); + + if (result < 0) { + [a retain]; + [self replaceObjectAtIndex: d + stride withObject: b]; + [self replaceObjectAtIndex: d withObject: a]; + + id eachObject; + va_list argumentList; + if (array1) { + id a1 = [array1 objectAtIndex:d+stride]; + id b1 = [array1 objectAtIndex:d]; + [a1 retain]; + [array1 replaceObjectAtIndex: d + stride withObject:b1]; + [array1 replaceObjectAtIndex: d withObject: a1]; + [a1 release]; + va_start(argumentList, array1); + while (eachObject = va_arg(argumentList, id)) { + id ax = [eachObject objectAtIndex:d+stride]; + id bx = [eachObject objectAtIndex:d]; + [ax retain]; + [eachObject replaceObjectAtIndex: d + stride withObject:bx]; + [eachObject replaceObjectAtIndex: d withObject: ax]; + [ax release]; + } + va_end(argumentList); + } + + [a release]; + + if (stride > d) + break; + + d -= stride; + } else + found = YES; + } + } + } +} +@end
\ No newline at end of file |