Regarding implementing a stable sort for Phobos

2012-03-12 Thread Xinok
I've been playing with sorting algorithms a lot in recent months, so I want to implement a *working* stable sort for Phobos which is broken at the moment. I have a working library and I'm still adding to it. It's much more complex than a simple merge sort, being over 300 lines of code at the mo

Re: Regarding implementing a stable sort for Phobos

2012-03-12 Thread Chad J
On 03/13/2012 02:31 AM, Xinok wrote: I've been playing with sorting algorithms a lot in recent months, so I want to implement a *working* stable sort for Phobos which is broken at the moment. I have a working library and I'm still adding to it. It's much more complex than a simple merge sort, bei

Re: Regarding implementing a stable sort for Phobos

2012-03-13 Thread deadalnix
Le 13/03/2012 07:53, Chad J a écrit : On 03/13/2012 02:31 AM, Xinok wrote: I've been playing with sorting algorithms a lot in recent months, so I want to implement a *working* stable sort for Phobos which is broken at the moment. I have a working library and I'm still adding to it. It's much mor

Re: Regarding implementing a stable sort for Phobos

2012-03-13 Thread Xinok
On Tuesday, 13 March 2012 at 06:53:30 UTC, Chad J wrote: Hey, I'd love to see more sorting algorithms in phobos. Being stuck with one seems kind of... wrong. Things like this are better left to 3rd party libs. Phobos already has two, a stable and unstable sort, which fulfill 99% of cases.

Re: Regarding implementing a stable sort for Phobos

2012-03-13 Thread Xinok
On Tuesday, 13 March 2012 at 08:37:06 UTC, deadalnix wrote: I have a radix sort (that need some rework to be phobos quality) and a smoothsort (that could be included in phobos). Would you mind sharing your smoothsort? I haven't implemented one myself and I'd love to test it out. Radix sort, on

Re: Regarding implementing a stable sort for Phobos

2012-03-13 Thread deadalnix
Le 13/03/2012 10:19, Xinok a écrit : On Tuesday, 13 March 2012 at 08:37:06 UTC, deadalnix wrote: I have a radix sort (that need some rework to be phobos quality) and a smoothsort (that could be included in phobos). Would you mind sharing your smoothsort? I haven't implemented one myself and I'

Re: Regarding implementing a stable sort for Phobos

2012-03-13 Thread Andrei Alexandrescu
On 3/13/12 4:02 AM, Xinok wrote: On Tuesday, 13 March 2012 at 06:53:30 UTC, Chad J wrote: Hey, I'd love to see more sorting algorithms in phobos. Being stuck with one seems kind of... wrong. Things like this are better left to 3rd party libs. Phobos already has two, a stable and unstable sort,

Re: Regarding implementing a stable sort for Phobos

2012-03-13 Thread Andrei Alexandrescu
On 3/13/12 1:31 AM, Xinok wrote: I've been playing with sorting algorithms a lot in recent months, so I want to implement a *working* stable sort for Phobos which is broken at the moment. I have a working library and I'm still adding to it. It's much more complex than a simple merge sort, being o

Re: Regarding implementing a stable sort for Phobos

2012-03-13 Thread Xinok
On Tuesday, 13 March 2012 at 09:32:49 UTC, deadalnix wrote: Le 13/03/2012 10:19, Xinok a écrit : Would you mind sharing your smoothsort? I haven't implemented one myself and I'd love to test it out. It is on github : https://github.com/deadalnix/Dsort/blob/master/sort/smooth.d Thanks. I fo

Re: Regarding implementing a stable sort for Phobos

2012-03-13 Thread Xinok
On Tuesday, 13 March 2012 at 14:31:59 UTC, Andrei Alexandrescu wrote: On 3/13/12 1:31 AM, Xinok wrote: - It's a natural merge sort, which is faster on partially sorted lists, and adds little overhead for mostly random lists. - It uses O(log n log n) additional space for merging. That's 1024 w

Re: Regarding implementing a stable sort for Phobos

2012-03-13 Thread Sean Kelly
How does the built-in sort do? I ask because the sort routine I wrote works the same way, which is optimized for ranges with a lot of common elements. On Mar 13, 2012, at 7:33 AM, Andrei Alexandrescu wrote: > On 3/13/12 4:02 AM, Xinok wrote: >> On Tuesday, 13 March 2012 at 06:53:30 UTC, Chad

Re: Regarding implementing a stable sort for Phobos

2012-03-13 Thread Sean Kelly
I forgot to mention that my routine uses the same basic algorithm as the built-in sort. On Mar 13, 2012, at 8:54 AM, Sean Kelly wrote: > How does the built-in sort do? I ask because the sort routine I wrote works > the same way, which is optimized for ranges with a lot of common elements. >

Re: Regarding implementing a stable sort for Phobos

2012-03-13 Thread deadalnix
Le 13/03/2012 16:08, Xinok a écrit : On Tuesday, 13 March 2012 at 09:32:49 UTC, deadalnix wrote: Le 13/03/2012 10:19, Xinok a écrit : Would you mind sharing your smoothsort? I haven't implemented one myself and I'd love to test it out. It is on github : https://github.com/deadalnix/Dsort/blob

Re: Regarding implementing a stable sort for Phobos

2012-03-13 Thread Andrei Alexandrescu
On 3/13/12 10:54 AM, Sean Kelly wrote: How does the built-in sort do? I ask because the sort routine I wrote works the same way, which is optimized for ranges with a lot of common elements. It's not about common (equal) elements, it's about elements for which comparisons do a lot of work beca

Re: Regarding implementing a stable sort for Phobos

2012-03-13 Thread Xinok
On Tuesday, 13 March 2012 at 16:04:55 UTC, deadalnix wrote: Le 13/03/2012 16:08, Xinok a écrit : On Tuesday, 13 March 2012 at 09:32:49 UTC, deadalnix wrote: Le 13/03/2012 10:19, Xinok a écrit : Would you mind sharing your smoothsort? I haven't implemented one myself and I'd love to test it ou

Re: Regarding implementing a stable sort for Phobos

2012-03-13 Thread Xinok
On Tuesday, 13 March 2012 at 16:11:05 UTC, Andrei Alexandrescu wrote: On 3/13/12 10:54 AM, Sean Kelly wrote: How does the built-in sort do? I ask because the sort routine I wrote works the same way, which is optimized for ranges with a lot of common elements. It's not about common (equal) e

Re: Regarding implementing a stable sort for Phobos

2012-03-13 Thread deadalnix
Le 13/03/2012 17:38, Xinok a écrit : On Tuesday, 13 March 2012 at 16:04:55 UTC, deadalnix wrote: Le 13/03/2012 16:08, Xinok a écrit : On Tuesday, 13 March 2012 at 09:32:49 UTC, deadalnix wrote: Le 13/03/2012 10:19, Xinok a écrit : Would you mind sharing your smoothsort? I haven't implemented

Re: Regarding implementing a stable sort for Phobos

2012-03-13 Thread bearophile
Andrei Alexandrescu: > it's about elements for which > comparisons do a lot of work because they have common prefixes. Consider: > > auto arr = [ "aaa", "aab", "aac", "aad" ]; > sort!((a, b) => a > b)(arr); > > There will be a lot of redundant prefix comparisons because the sorting > method do

Re: Regarding implementing a stable sort for Phobos

2012-03-13 Thread Xinok
On Tuesday, 13 March 2012 at 06:32:01 UTC, Xinok wrote: I've been playing with sorting algorithms a lot in recent months, so I want to implement a *working* stable sort for Phobos which is broken at the moment. I have a working library and I'm still adding to it. It's much more complex than a

Re: Regarding implementing a stable sort for Phobos

2012-03-13 Thread Jesse Phillips
On Tuesday, 13 March 2012 at 14:31:59 UTC, Andrei Alexandrescu wrote: On 3/13/12 1:31 AM, Xinok wrote: - I wrote it to sort random-access ranges *without* slicing, but I think the exclusion of slicing makes it slower. I'm writing a separate implementation which uses slicing and I'll keep it if

Re: Regarding implementing a stable sort for Phobos

2012-03-13 Thread Xinok
On Tuesday, 13 March 2012 at 18:32:27 UTC, Xinok wrote: On Tuesday, 13 March 2012 at 06:32:01 UTC, Xinok wrote: I've been playing with sorting algorithms a lot in recent months, so I want to implement a *working* stable sort for Phobos which is broken at the moment. I have a working library an

Re: Regarding implementing a stable sort for Phobos

2012-03-15 Thread Xinok
On Wednesday, 14 March 2012 at 03:55:31 UTC, Xinok wrote: I removed the code without slicing from the lib, though I still retain a copy. I added 3 unittests: A basic sort test, a stability test, and a CTFE test. I added a few asserts which have helped me discover bugs in the past. I only added

Re: Regarding implementing a stable sort for Phobos

2012-03-24 Thread Xinok
On Thursday, 15 March 2012 at 20:20:59 UTC, Xinok wrote: Third update: http://www.mediafire.com/?9jx07estd58wh2p + Added in-place sorting; Set template argument inPlace to true + Fixed CTFE compatibility issues + Vastly improved unittest + CTFE unittest will no longer stop compilation upon failu