From ffa73a4a2673fece7cd63c471476db6bc4aef9e6 Mon Sep 17 00:00:00 2001 From: solar Date: Fri, 12 Mar 2010 11:06:16 +0000 Subject: [PATCH] Thinko pointed out by Brian Damgaard. --- Notes.txt | 5 ++++- functions/stdlib/qsort.c | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Notes.txt b/Notes.txt index aa06503..dd85931 100644 --- a/Notes.txt +++ b/Notes.txt @@ -1,4 +1,4 @@ -$Id$ +$Id$ Credits ======= @@ -31,6 +31,9 @@ the Public Domain which can now be found in <_PDCLIB_config.h>, thanks. Rod Pemberton, for pointing out several flaws in early versions of PDCLib and giving other valuable hints, thanks. +Brian Damgaard, for a very friendly exchange over the fine details of the +Quicksort algorithm and its implementation in PDCLib, thanks. + Everyone involved in the first, "public" attempt at PDCLib, for bearing with me when I restarted from scratch, thanks. diff --git a/functions/stdlib/qsort.c b/functions/stdlib/qsort.c index c37760f..3e349fb 100644 --- a/functions/stdlib/qsort.c +++ b/functions/stdlib/qsort.c @@ -34,8 +34,11 @@ static inline void memswp( char * i, char * j, size_t size ) #define PREPARE_STACK char * stack[STACKSIZE]; char * * stackptr = stack #define PUSH( base, limit ) stackptr[0] = base; stackptr[1] = limit; stackptr += 2 #define POP( base, limit ) stackptr -= 2; base = stackptr[0]; limit = stackptr[1] -/* TODO: This is platform-dependent */ -#define STACKSIZE 40 +/* TODO: Stack usage is log2( nmemb ) (minus what T shaves off the worst case). + Worst-case nmemb is platform dependent and should probably be + configured through _PDCLIB_config.h. +*/ +#define STACKSIZE 64 void qsort( void * base, size_t nmemb, size_t size, int (*compar)( const void *, const void * ) ) { -- 2.40.0