mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-29 16:01:38 +00:00
Sort algorithms should always be built, and be selectable at runtime
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@39998 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
f56e1bdd0c
commit
39cc09e2ca
12 changed files with 100 additions and 108 deletions
|
@ -30,6 +30,8 @@
|
|||
#import "Foundation/NSCoder.h"
|
||||
#import "Foundation/NSException.h"
|
||||
#import "Foundation/NSKeyValueCoding.h"
|
||||
#import "Foundation/NSNotification.h"
|
||||
#import "Foundation/NSUserDefaults.h"
|
||||
|
||||
#import "GNUstepBase/GSObjCRuntime.h"
|
||||
#import "GSPrivate.h"
|
||||
|
@ -41,34 +43,61 @@ static BOOL initialized = NO;
|
|||
#pragma clang diagnostic ignored "-Wreceiver-forward-class"
|
||||
#endif
|
||||
|
||||
#if GS_USE_TIMSORT
|
||||
@interface GSTimSortDescriptor : NSObject
|
||||
@interface GSTimSortPlaceHolder : NSObject
|
||||
+ (void) setUnstable;
|
||||
@end
|
||||
#endif
|
||||
#if GS_USE_QUICKSORT
|
||||
@interface GSQuickSortPlaceHolder : NSObject
|
||||
+ (void) setUnstable;
|
||||
@end
|
||||
#endif
|
||||
#if GS_USE_SHELLSORT
|
||||
@interface GSShellSortPlaceHolder : NSObject
|
||||
+ (void) setUnstable;
|
||||
@end
|
||||
#endif
|
||||
|
||||
@implementation NSSortDescriptor
|
||||
|
||||
+ (void) defaultsChanged: (NSNotification*)n
|
||||
{
|
||||
NSUserDefaults *defs = (NSUserDefaults*)[n object];
|
||||
NSString *algorithm;
|
||||
|
||||
algorithm = [defs stringForKey: @"GSSortAlgorithm"];
|
||||
if ([algorithm isEqual: @"QuickSort"])
|
||||
{
|
||||
[GSQuickSortPlaceHolder setUnstable];
|
||||
}
|
||||
else if ([algorithm isEqual: @"ShellSort"])
|
||||
{
|
||||
[GSShellSortPlaceHolder setUnstable];
|
||||
}
|
||||
else if ([algorithm isEqual: @"TimSort"])
|
||||
{
|
||||
[GSTimSortPlaceHolder setUnstable];
|
||||
}
|
||||
else
|
||||
{
|
||||
[GSTimSortPlaceHolder setUnstable];
|
||||
if (nil != algorithm)
|
||||
{
|
||||
NSLog(@"GSSortAlgorithm default unknown value (%@)", algorithm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
if (NO == initialized)
|
||||
{
|
||||
#if GS_USE_TIMSORT
|
||||
[GSTimSortDescriptor class];
|
||||
#endif
|
||||
#if GS_USE_QUICKSORT
|
||||
[GSQuickSortPlaceHolder class];
|
||||
#endif
|
||||
#if GS_USE_SHELLSORT
|
||||
[GSShellSortPlaceHolder class];
|
||||
#endif
|
||||
NSNotificationCenter *nc;
|
||||
NSUserDefaults *defs;
|
||||
|
||||
[GSTimSortPlaceHolder class]; // default stable sort
|
||||
nc = [NSNotificationCenter defaultCenter];
|
||||
defs = [NSUserDefaults standardUserDefaults];
|
||||
[nc addObserver: self
|
||||
selector: @selector(defaultsChanged:)
|
||||
name: NSUserDefaultsDidChangeNotification
|
||||
object: defs];
|
||||
[self defaultsChanged: nil]; // set unstable sort
|
||||
initialized = YES;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue