r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Core] Discuss core issues

BrianH
10-Dec-2010
[691]
Merge sort is for when comparisons are *really* slow, sorting disk 
records slow. You have to have a really heavyweight mezz compare 
function to justify that. The overhead of the second series would 
be pretty high in cases where the speed difference would really matter. 
One of the inplace sorts would be better, as long as it's stable.
Steeve
10-Dec-2010
[692]
there's no need to have heavy mezz, the Rebol's scheme is already 
50 times slower (at least) than same compiled code when it ferdorms 
comparisons.
BrianH
10-Dec-2010
[693]
std::sort seems to do really well.
Steeve
10-Dec-2010
[694]
I don't know this algo
BrianH
10-Dec-2010
[695x3]
Apparently the actual algo varies from compiler to compiler, but 
it is a mix of qsort, heapsort and insertion sort depending on which 
is fastest in particular circumstances.
But it is in the C++ standard library, so C code wouldn't be able 
to use it without copying and rewriting.
It could in theory be the best, but that depends on how smartly it 
was written. It tends to be pretty reliable though because the pathalogical 
cases are in theory sorted with different algorithms when they would 
otherwise cause problems.
Andreas
10-Dec-2010
[698x2]
std::sort is not stable.
std::stable_sort is.
BrianH
10-Dec-2010
[700]
Interesting. It's been a long time since I used C++ (there were no 
standard libraries then). It never occured to me that someone would 
use an unstable sort algorithm without checking first whether it 
would be safe to do so. I must have missed that in college.
Ladislav
10-Dec-2010
[701x2]
the funny thing about REBOL SORT is, that, it is actually stable, 
provided you use /compare
, which proves, that it just uses a wrong operator somewhere
Steeve
10-Dec-2010
[703]
I don't think it's the purpose of compare
BrianH
10-Dec-2010
[704]
That is what I thought when I write the ticket. Could you give an 
example of /compare use which is stable, to add to the ticket?
Steeve
10-Dec-2010
[705]
/compare is used to sort your own data structures
BrianH
10-Dec-2010
[706]
Or to reverse a sort, or for whatever you need it to be for.
Ladislav
10-Dec-2010
[707]
OK, Brian, will do
Andreas
10-Dec-2010
[708]
For reversing we'd also have /reverse.
BrianH
10-Dec-2010
[709x2]
Yeah, we have options for the most common variants, and the default 
for the most common case. The /compare option is for everything else.
And not well enough documented either. I don't really know how /compare 
works, not completely.
Steeve
10-Dec-2010
[711]
to sort  gobs for instance, with your own scheme
BrianH
10-Dec-2010
[712]
I know *why* it is there, I just don't know how it *works*. How does 
it react to different return types of the comparison function? What 
types are allowed? When is the security hole going to be fixed?
Ladislav
10-Dec-2010
[713]
I know, that it is documented somewhere, that the Comparator can 
yield either logic! value or a number, where a negative number means 
"<", zero means "=", and a positive number means ">"
Andreas
10-Dec-2010
[714]
Btw, Linux A110's SORT seems rather stable for me :)
Ladislav
10-Dec-2010
[715]
using the example Brian gave?
BrianH
10-Dec-2010
[716]
Read the ticket. "Stable" means a different thing when applied to 
sorting algorithms.
Andreas
10-Dec-2010
[717]
Thanks Brian, I'm fine with terminology here.
BrianH
10-Dec-2010
[718]
No offence intended :)
Andreas
10-Dec-2010
[719x2]
I guess I wouldn't have told you about std::sort being unstable, 
if I wouldn't know what a stable sort is?
Yes Ladislav, for all examples in that ticket.
BrianH
10-Dec-2010
[721]
Sorry, momentary lack of humor. Did you mean that it works correctly 
on Linux?
Andreas
10-Dec-2010
[722]
Yes.
BrianH
10-Dec-2010
[723x2]
If so, please mention that in a ticket comment.
It might be a compiler problem.
Andreas
10-Dec-2010
[725]
A library problem, yes.
BrianH
10-Dec-2010
[726]
Are you talking about R2 or R3?
Andreas
10-Dec-2010
[727x2]
Read what I said above: A110
Two tests in the example code given in the ticket seem wrong to me.
BrianH
10-Dec-2010
[729]
Right, sorry. I read that after I sent the message.
Andreas
10-Dec-2010
[730x3]
; Verification using SAME?
>> set [c d] sort reduce [a: "a" b: "a"]
== ["a" "a"]
>> same? c a
== false  ; should be true
>> same? c b
== true  ; should be false
>> same? d a
== true  ; should be true
>> same? d b
== false  ; should be false
The last two tests should be the other way round, no?
same? d a ; should be false
same? d b ; should be true
BrianH
10-Dec-2010
[733]
Fixed.
Andreas
10-Dec-2010
[734]
Thanks
Steeve
10-Dec-2010
[735]
Btw, by reading again your samples Brian, I think now it"s weird 
for a quick sort.
Not exactly what I expected....
Andreas
10-Dec-2010
[736]
At least on Linux, it definitely is a qsort.
BrianH
10-Dec-2010
[737]
It might be using the C library qsort.
Andreas
10-Dec-2010
[738]
Calling the C librabry's qsort(3).
BrianH
10-Dec-2010
[739]
Definitely mention that in a ticket comment. We might be able to 
make this a platform-specific ticket.
Andreas
10-Dec-2010
[740]
Not really, I fear.