mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Changes to restore sorting functiionality
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@35579 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
1b1355ff7f
commit
a4140c8f51
11 changed files with 7804 additions and 10611 deletions
26
ChangeLog
26
ChangeLog
|
@ -1,3 +1,29 @@
|
|||
2012-09-20 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* configure.ac: Change sort selection to use shellsort by default and
|
||||
to make sort selection internal to gnustep-base rather than public.
|
||||
* configure: regenerate
|
||||
* Headers/GNUstepBase/config.h.in: regenerate
|
||||
* Headers/GNUstepBase/GSConfig.h.in: Remove public sort selection info
|
||||
* Source/GSQuickSort.m: Use config.h to control build/not-build.
|
||||
* Source/NSSortDescriptor.m: Reference the selected sort class to
|
||||
ensure that it is linked in and loaded at runtime.
|
||||
* Source/GSShellSort.m: Fix bug in function arguments.
|
||||
Use config.h to control build/not-build.
|
||||
* Source/GSSorting.h: tidied a little
|
||||
* Source/GSTimSort.m: Use config.h to control build/not-build.
|
||||
The changes are basically to keep sort information internal to
|
||||
base rather than exposing it and, more importantly, to get sorting
|
||||
working again. This involves:
|
||||
1. minor fix to shellsort to get it to work.
|
||||
2. change configure script to select shellsort.
|
||||
The problems with the other sorts are:
|
||||
a. quicksort won't even compile
|
||||
b. timsort does compile, but segfaults when you try to give it
|
||||
real-world datasets to sort
|
||||
Anyone wantng to fix these, please do (it would be really cool
|
||||
to have timsort working).
|
||||
|
||||
2012-09-19 Niels Grewe <niels.grewe@halbordnung.de>
|
||||
* Source/GSSorting.h
|
||||
* Source/NSSortDescriptor.m:
|
||||
|
|
|
@ -233,27 +233,6 @@ typedef struct {
|
|||
#define GS_USE_LIBDISPATCH @HAVE_LIBDISPATCH@
|
||||
#define GS_HAVE_OBJC_ROOT_CLASS_ATTR @GS_HAVE_OBJC_ROOT_CLASS_ATTR@
|
||||
|
||||
#define GS_USE_TIMSORT @GS_USE_TIMSORT@
|
||||
#define GS_USE_QUICKSORT @GS_USE_QUICKSORT@
|
||||
#define GS_USE_SHELLSORT @GS_USE_SHELLSORT@
|
||||
|
||||
#if GS_USE_TIMSORT
|
||||
#define GS_DISABLE_QUICKSORT
|
||||
#define GS_DISABLE_SHELLSORT
|
||||
#endif
|
||||
|
||||
/*
|
||||
* QuickSort and ShellSort cannot override TimSort because that would leave us
|
||||
* without a stable sorting algorithm.
|
||||
*/
|
||||
#if GS_USE_QUICKSORT
|
||||
#define GS_DISABLE_SHELLSORT
|
||||
#endif
|
||||
|
||||
#if GS_USE_SHELLSORT
|
||||
#define GS_DISABLE_QUICKSORT
|
||||
#endif
|
||||
|
||||
#if defined(__WIN32__) || defined(_WIN32) || defined(__MS_WIN32__)
|
||||
# if !defined(__WIN32__)
|
||||
# define __WIN32__
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
/* Headers/GNUstepBase/config.h.in. Generated from configure.ac by autoheader. */
|
||||
|
||||
/* Define if building universal (internal helper macro) */
|
||||
#undef AC_APPLE_UNIVERSAL_BUILD
|
||||
|
||||
/* The normal alignment of `pthread_cond_t', in bytes. */
|
||||
#undef ALIGNOF_PTHREAD_COND_T
|
||||
|
||||
|
@ -168,6 +171,15 @@
|
|||
/* Built in default value for GNUstep user_dir web apps */
|
||||
#undef GNUSTEP_TARGET_USER_DIR_WEB_APPS
|
||||
|
||||
/* Build in/use quicksort */
|
||||
#undef GS_USE_QUICKSORT
|
||||
|
||||
/* Build in/use shellsort */
|
||||
#undef GS_USE_SHELLSORT
|
||||
|
||||
/* Build in/use timsort */
|
||||
#undef GS_USE_TIMSORT
|
||||
|
||||
/* Define to 1 if you have the <alloca.h> header file. */
|
||||
#undef HAVE_ALLOCA_H
|
||||
|
||||
|
@ -786,26 +798,44 @@
|
|||
/* Define if using the libffi library for invocations */
|
||||
#undef USE_LIBFFI
|
||||
|
||||
/* Enable extensions on AIX 3, Interix. */
|
||||
#ifndef _ALL_SOURCE
|
||||
# undef _ALL_SOURCE
|
||||
#endif
|
||||
/* Enable GNU extensions on systems that have them. */
|
||||
#ifndef _GNU_SOURCE
|
||||
# undef _GNU_SOURCE
|
||||
#endif
|
||||
/* Enable threading extensions on Solaris. */
|
||||
#ifndef _POSIX_PTHREAD_SEMANTICS
|
||||
# undef _POSIX_PTHREAD_SEMANTICS
|
||||
#endif
|
||||
/* Enable extensions on HP NonStop. */
|
||||
#ifndef _TANDEM_SOURCE
|
||||
# undef _TANDEM_SOURCE
|
||||
#endif
|
||||
/* Enable general extensions on Solaris. */
|
||||
#ifndef __EXTENSIONS__
|
||||
# undef __EXTENSIONS__
|
||||
#endif
|
||||
|
||||
|
||||
/* Define if vasprintf returns the length printed */
|
||||
#undef VASPRINTF_RETURNS_LENGTH
|
||||
|
||||
/* Define if vsprintf returns the length printed */
|
||||
#undef VSPRINTF_RETURNS_LENGTH
|
||||
|
||||
/* Define to 1 if your processor stores words with the most significant byte
|
||||
first (like Motorola and SPARC, unlike Intel and VAX). */
|
||||
#undef WORDS_BIGENDIAN
|
||||
|
||||
/* Define to 1 if on AIX 3.
|
||||
System headers sometimes define this.
|
||||
We just want to avoid a redefinition error message. */
|
||||
#ifndef _ALL_SOURCE
|
||||
# undef _ALL_SOURCE
|
||||
#endif
|
||||
|
||||
/* Enable GNU extensions on systems that have them. */
|
||||
#ifndef _GNU_SOURCE
|
||||
# undef _GNU_SOURCE
|
||||
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
|
||||
significant byte first (like Motorola and SPARC, unlike Intel). */
|
||||
#if defined AC_APPLE_UNIVERSAL_BUILD
|
||||
# if defined __BIG_ENDIAN__
|
||||
# define WORDS_BIGENDIAN 1
|
||||
# endif
|
||||
#else
|
||||
# ifndef WORDS_BIGENDIAN
|
||||
# undef WORDS_BIGENDIAN
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Define to 1 if on MINIX. */
|
||||
|
@ -818,14 +848,6 @@
|
|||
/* Define to 1 if you need to in order for `stat' and other things to work. */
|
||||
#undef _POSIX_SOURCE
|
||||
|
||||
/* Enable extensions on Solaris. */
|
||||
#ifndef __EXTENSIONS__
|
||||
# undef __EXTENSIONS__
|
||||
#endif
|
||||
#ifndef _POSIX_PTHREAD_SEMANTICS
|
||||
# undef _POSIX_PTHREAD_SEMANTICS
|
||||
#endif
|
||||
|
||||
/* Define to `__inline__' or `__inline' if that's what the C compiler
|
||||
calls it, or to nothing if 'inline' is not supported under any name. */
|
||||
#ifndef __cplusplus
|
||||
|
|
|
@ -158,19 +158,19 @@ GSBlocks.m \
|
|||
GSConcreteValue.m \
|
||||
GSCountedSet.m \
|
||||
GSDictionary.m \
|
||||
GSFormat.m \
|
||||
GSFTPURLHandle.m \
|
||||
GSFormat.m \
|
||||
GSHTTPAuthentication.m \
|
||||
GSHTTPURLHandle.m \
|
||||
GSICUString.m \
|
||||
GSQuickSort.m \
|
||||
GSRunLoopWatcher.m \
|
||||
GSSet.m \
|
||||
GSShellSort.m \
|
||||
GSSocketStream.m \
|
||||
GSStream.m \
|
||||
GSString.m \
|
||||
GSICUString.m \
|
||||
GSTimSort.m \
|
||||
GSQuickSort.m \
|
||||
GSShellSort.m \
|
||||
GSValue.m \
|
||||
NSAffineTransform.m \
|
||||
NSArchiver.m \
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#import "common.h"
|
||||
#import "Foundation/NSSortDescriptor.h"
|
||||
#import "Foundation/NSArray.h"
|
||||
#import "Foundation/NSObjCRuntime.h"
|
||||
|
@ -45,7 +46,7 @@ SwapObjects(id * o1, id * o2)
|
|||
* Sorts the provided object array's sortRange according to sortDescriptor.
|
||||
*/
|
||||
// Quicksort algorithm copied from Wikipedia :-).
|
||||
#ifndef GS_DISABLE_QUICKSORT
|
||||
#if GS_USE_QUICKSORT
|
||||
static void
|
||||
_GSQuickSort(id *objects,
|
||||
NSRange sortRange,
|
||||
|
|
|
@ -24,14 +24,13 @@
|
|||
Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#import "common.h"
|
||||
#import "Foundation/NSSortDescriptor.h"
|
||||
#import "Foundation/NSArray.h"
|
||||
#import "Foundation/NSObjCRuntime.h"
|
||||
#import "GSSorting.h"
|
||||
|
||||
#ifndef GS_DISABLE_SHELLSORT
|
||||
#if GS_USE_SHELLSORT
|
||||
void
|
||||
_GSShellSort(id *objects,
|
||||
NSRange sortRange,
|
||||
|
@ -75,7 +74,7 @@ _GSShellSort(id *objects,
|
|||
NSComparisonResult r;
|
||||
|
||||
r = GSCompareUsingDescriptorOrComparator(a, b,
|
||||
comparisonEntity, context);
|
||||
comparisonEntity, type, context);
|
||||
if (r < 0)
|
||||
{
|
||||
#ifdef GSWARN
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
#import "Foundation/NSException.h"
|
||||
#import "GSPrivate.h"
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
GSComparisonTypeSortDescriptor = 0, /** Comparison using an NSSortDescriptor */
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
*/
|
||||
|
||||
#import "common.h"
|
||||
|
||||
#import "Foundation/NSSortDescriptor.h"
|
||||
|
||||
#import "Foundation/NSCoder.h"
|
||||
|
@ -441,6 +440,8 @@ NSRange range, NSComparator cmptr)
|
|||
GSComparisonTypeComparatorBlock, NULL);
|
||||
}
|
||||
|
||||
#if GS_USE_TIMSORT
|
||||
|
||||
/* These macros make calling the cached IMPs easier,
|
||||
* if we choose to do so later.
|
||||
*/
|
||||
|
@ -508,9 +509,7 @@ _GSTimSort(id *objects,
|
|||
@implementation GSTimSortDescriptor
|
||||
+ (void) load
|
||||
{
|
||||
#ifndef GS_DISABLE_TIMSORT
|
||||
_GSSortStable = _GSTimSort;
|
||||
#endif
|
||||
}
|
||||
|
||||
+ (void) initialize
|
||||
|
@ -1030,8 +1029,8 @@ descriptorOrComparator: (id)descriptorOrComparator
|
|||
// Find an insertion point for the first element in r2 into r1
|
||||
insert = gallopRight(objects[r2.location], objects, r1, 0,
|
||||
sortDescriptorOrComparator, comparisonType, functionContext);
|
||||
r1.location += insert;
|
||||
r1.length -= insert;
|
||||
r1.length = insert - r1.location;
|
||||
r1.location = insert;
|
||||
if (r1.length == 0)
|
||||
{
|
||||
// The entire run r2 lies after r1, just return.
|
||||
|
@ -1081,7 +1080,6 @@ descriptorOrComparator: (id)descriptorOrComparator
|
|||
|
||||
|
||||
@end
|
||||
#ifndef GS_DISABLE_TIMSORT
|
||||
static void
|
||||
_GSTimSort(id *objects,
|
||||
NSRange sortRange,
|
||||
|
|
|
@ -36,8 +36,37 @@
|
|||
#import "GSPrivate.h"
|
||||
#import "GSSorting.h"
|
||||
|
||||
static BOOL initialized = NO;
|
||||
|
||||
#if GS_USE_TIMSORT
|
||||
@class GSTimSortDescriptor;
|
||||
#endif
|
||||
#if GS_USE_QUICKSORT
|
||||
@class GSQuickSortPlaceHolder;
|
||||
#endif
|
||||
#if GS_USE_SHELLSORT
|
||||
@class GSShellSortPlaceHolder;
|
||||
#endif
|
||||
|
||||
@implementation NSSortDescriptor
|
||||
|
||||
+ (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
|
||||
initialized = YES;
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL) ascending
|
||||
{
|
||||
return _ascending;
|
||||
|
@ -205,12 +234,15 @@
|
|||
void
|
||||
(*_GSSortUnstable)(id* buffer, NSRange range,
|
||||
id comparisonEntity, GSComparisonType cmprType, void *context) = NULL;
|
||||
|
||||
void
|
||||
(*_GSSortStable)(id* buffer, NSRange range,
|
||||
id comparisonEntity, GSComparisonType cmprType, void *context) = NULL;
|
||||
|
||||
void
|
||||
(*_GSSortUnstableConcurrent)(id* buffer, NSRange range,
|
||||
id comparisonEntity, GSComparisonType cmprType, void *context) = NULL;
|
||||
|
||||
void
|
||||
(*_GSSortStableConcurrent)(id* buffer, NSRange range,
|
||||
id comparisonEntity, GSComparisonType cmprType, void *context) = NULL;
|
||||
|
@ -221,6 +253,7 @@ void
|
|||
GSSortUnstable(id* buffer, NSRange range, id descriptorOrComparator,
|
||||
GSComparisonType type, void* context)
|
||||
{
|
||||
if (NO == initialized) [NSSortDescriptor class];
|
||||
if (NULL != _GSSortUnstable)
|
||||
{
|
||||
_GSSortUnstable(buffer, range, descriptorOrComparator, type, context);
|
||||
|
@ -240,6 +273,7 @@ void
|
|||
GSSortStable(id* buffer, NSRange range, id descriptorOrComparator,
|
||||
GSComparisonType type, void* context)
|
||||
{
|
||||
if (NO == initialized) [NSSortDescriptor class];
|
||||
if (NULL != _GSSortStable)
|
||||
{
|
||||
_GSSortStable(buffer, range, descriptorOrComparator, type, context);
|
||||
|
@ -256,6 +290,7 @@ void
|
|||
GSSortStableConcurrent(id* buffer, NSRange range, id descriptorOrComparator,
|
||||
GSComparisonType type, void* context)
|
||||
{
|
||||
if (NO == initialized) [NSSortDescriptor class];
|
||||
if (NULL != _GSSortStableConcurrent)
|
||||
{
|
||||
_GSSortStableConcurrent(buffer, range, descriptorOrComparator,
|
||||
|
@ -271,6 +306,7 @@ void
|
|||
GSSortUnstableConcurrent(id* buffer, NSRange range, id descriptorOrComparator,
|
||||
GSComparisonType type, void* context)
|
||||
{
|
||||
if (NO == initialized) [NSSortDescriptor class];
|
||||
if (NULL != _GSSortUnstableConcurrent)
|
||||
{
|
||||
_GSSortUnstableConcurrent(buffer, range, descriptorOrComparator,
|
||||
|
|
27
configure.ac
27
configure.ac
|
@ -3273,24 +3273,23 @@ AC_SUBST(USE_GMP)
|
|||
AC_ARG_WITH(sort-algorithm,
|
||||
[ --with-sort-algorithm=ALG force use of a specific sorting algorithm.
|
||||
Possible values are timsort, quicksort, and shellsort.
|
||||
Defaults to timsort. Timsort cannot be completely
|
||||
disabled because it is required for stable sorting.],
|
||||
sort_algorithm="$withval", sort_algorithm="timsort")
|
||||
GS_USE_TIMSORT=1
|
||||
GS_USE_QUICKSORT=0
|
||||
GS_USE_SHELLSORT=0
|
||||
if test "$sort_algorithm" = "quicksort"; then
|
||||
use_quicksort=1
|
||||
Defaults to shellsort (others broken).],
|
||||
sort_algorithm="$withval", sort_algorithm="shellsort")
|
||||
|
||||
if test "$sort_algorithm" = "timsort"; then
|
||||
AC_DEFINE(GS_USE_TIMSORT,1,[Build in/use timsort])
|
||||
else
|
||||
if test "$srot_algorithm" = "shellsort"; then
|
||||
use_shellsort=1
|
||||
if test "$sort_algorithm" = "quicksort"; then
|
||||
AC_DEFINE(GS_USE_QUICKSORT,1,[Build in/use quicksort])
|
||||
else
|
||||
if test "$sort_algorithm" = "shellsort"; then
|
||||
AC_DEFINE(GS_USE_SHELLSORT,1,[Build in/use shellsort])
|
||||
else
|
||||
AC_MSG_ERROR([Unknown sort_algorithm defined!])
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
AC_SUBST(GS_USE_TIMSORT)
|
||||
AC_SUBST(GS_USE_QUICKSORT)
|
||||
AC_SUBST(GS_USE_SHELLSORT)
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Check whether nl_langinfo(CODESET) is supported, needed by Unicode.m.
|
||||
#--------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in a new issue