Re: Re: qsort fix
| From: | (Richard Lynch) | Date: | Sat, 29 May 1999 00:56:21 +0000 |
| Subject: | Re: Re: qsort fix | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-6227@lists.php.net to get a copy of this message | ||
I'm not up-to-speed on CVS yet, but...
Since the only point of non-deterministic comparison would be for
shuffle(), and since shuffle() should really be done with something linear
rather than qsort which is O(n log n)...
Wouldn't it be better to leave qsort alone and change shuffle()?...
//untested
//And I can't even remember c syntax now :-(
//So it's pseudo-code close
void* shuffle(void* array){
int len = sizeof(array);
//Jeez. That can't be right, can it?
//How can c know how big an array is without knowing the underlying type?...
for (i = 0; i < len - 1; i++){
int index = rand(i, len);
void temp = array[i];
array[i] = array[index];
array[index] = temp;
}
return array;
}
My point being that shuffle shouldn't be using qsort, so this wouldn't be a
problem...
Disclaimer: I'm too new to this game to *really* contribute... Yet. Sorry.
-- "TANSTAAFL" Rich lynch@cognitivearts.com webmaster@ and www. all of:
R&B/jazz/blues/rock - jademaze.com music industry org - chatmusic.com
acoustic/funk/world-beat - astrakelly.com sculptures - olivierledoux.com
my own nascent company - l-i-e.com cool coffeehouse - uncommonground.com
--
PHP Development Mailing List http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net
For help: php-dev-help@lists.php.net