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

World: r3wp

[Core] Discuss core issues

GrahamC
9-Dec-2010
[670x2]
If ''layout completes, then FN will be a VID field object
so this suggests to me that db = [ ]
BrianH
9-Dec-2010
[672]
If there are no rows returned then that makes sense. Looks like the 
database access needs some work. And even if the path succeeded, 
the SQL at the end of btn-save would fail because the database is 
disconnected. Plus, the create statement at the beginning just creates 
a database, not a table.
GrahamC
9-Dec-2010
[673]
I didn't look at the rest of the code .. I'm just interested in the 
tech explanation as to why the function errors out like that
BrianH
9-Dec-2010
[674]
The error message itself refers to some fairly limited code. A couple 
probe statements would narrow things down even further.
Steeve
10-Dec-2010
[675]
Anyone know which algo is used by the SORT function ?
BrianH
10-Dec-2010
[676]
Not a stable one (there's a ticket about that). It could be guessed 
by using a logging compare function.
Steeve
10-Dec-2010
[677]
So, did you guess it ?
Dockimbel
10-Dec-2010
[678]
I would bet on a quick sort.
Steeve
10-Dec-2010
[679x2]
If it uses several algos it will be difficult
Quick sort is not optimal for cases where the comparison cost is 
expensive.
And with Rebol comparisons have high cost
BrianH
10-Dec-2010
[681]
>> print mold collect [sort/compare [20 19 18 17 16 15 14 13 12 11 
10 9 8 7 6 5 4 3 2 1] func [x y] [keep/only reduce [x y] x < y]]

[[10 20] [1 10] [10 20] [10 19] [10 2] [10 18] [10 3] [10 17] [10 
4] [10 16] [10 5] [10 15] [10 6] [10 14] [10 7] [10 13] [10 8] [10 
12] [10 9] [10 11] [10 11] [10 9] [5 1] [9 1] [9 5] [5 2] [5 3] [5 
4] [5 6] [5 8] [5 7] [5 6] [5 4] [6 7] [7 8] [8 9] [6 7] [7 8] [6 
7] [1 2] [2 3] [3 4] [1 2] [2 3] [1 2] [16 11] [20 11] [20 16] [16 
12] [16 13] [16 14] [16 15] [16 17] [16 19] [16 18] [16 17] [16 15] 
[17 18] [18 19] [19 20] [17 18] [18 19] [17 18] [11 12] [12 13] [13 
14] [14 15] [11 12] [12 13] [13 14] [11 12] [12 13] [11 12]]
Steeve
10-Dec-2010
[682x3]
ok it's quick sort
far from behing the best one in our context as I said. Too much comparisons
*from beeing
BrianH
10-Dec-2010
[685x3]
Darn. Quicksort is still slow for mostly sorted stuff:
>> print mold collect [sort/compare [1 2 3 4 5 6 7 8 9 10] func [x 
y] [keep/only reduce [x y] x < y]]

[[6 1] [10 1] [10 6] [6 2] [6 3] [6 4] [6 5] [6 7] [6 9] [6 8] [6 
7] [6 5] [7 8] [8 9] [9 10] [7 8] [8 9] [7 8] [1 2] [2 3] [3 4] [4 
5] [1 2] [2 3] [3 4] [1 2] [2 3] [1 2]]
See also this: http://curecode.org/rebol3/ticket.rsp?id=1152
Steeve
10-Dec-2010
[688]
Merge sort seems to give the best results when the comparison functions 
are expensive.
http://warp.povusers.org/SortComparison
BrianH
10-Dec-2010
[689]
Good idea, as long as the sort is stable.
Steeve
10-Dec-2010
[690]
Shell sort seems pretty good aswell
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
[719]
I guess I wouldn't have told you about std::sort being unstable, 
if I wouldn't know what a stable sort is?