Re: QSort in D: is this best?

2009-12-23 Thread Philippe Sigaud
On Tue, Dec 22, 2009 at 23:25, dsimcha dsim...@yahoo.com wrote: The work you've done looks excellent and will probably get noticed a lot more in a few months when development of Phobos gets put back on the front burner. I apologize for the relative silence on what looks to be lots of very

Re: QSort in D: is this best?

2009-12-22 Thread Philippe Sigaud
On Mon, Dec 21, 2009 at 23:44, Andrei Alexandrescu seewebsiteforem...@erdani.org wrote: This is a great example that I don't have the time to look into now. In essence the task is to generate all numbers of the form 2^^a*3^^b*5^^c where a, b, and c are natural numbers. Currently Phobos

Re: QSort in D: is this best?

2009-12-22 Thread dsimcha
== Quote from Philippe Sigaud (philippe.sig...@gmail.com)'s article --0016e6db29968796e0047b5716c2 Content-Type: text/plain; charset=ISO-8859-1 On Mon, Dec 21, 2009 at 23:44, Andrei Alexandrescu seewebsiteforem...@erdani.org wrote: This is a great example that I don't have the time to look

Re: QSort in D: is this best?

2009-12-22 Thread bearophile
Philippe Sigaud: merge2 is greedy and works only for two ranges (hence it's name), but I have a templated, predicate-aliased, lazy, n-ranges version called merge in the module. This is how merge is implemented in the heapq module of the Python standard lib: def merge(*iterables): h = []

Re: QSort in D: is this best?

2009-12-21 Thread Andrei Alexandrescu
This is a great example that I don't have the time to look into now. In essence the task is to generate all numbers of the form 2^^a*3^^b*5^^c where a, b, and c are natural numbers. Currently Phobos doesn't have the means to compute the cross-product of ranges. I encourage people to think

Re: QSort in D: is this best?

2009-12-21 Thread bearophile
Andrei Alexandrescu: This is a great example that I don't have the time to look into now. It's a nice example, and I know you don't have a lot of time to implement it now. Currently Phobos doesn't have the means to compute the cross-product of ranges. The idea is to have standard means in

QSort in D: is this best?

2009-12-20 Thread downs
Or are there any bugs/optimization opportunities I'm missing? void qsort(T)(T[] array) { if (array.length 2) return; static int i; auto pivot = array[i++%$]; // from is base-0, to is base-1. int from = 0, to = array.length; while (from != to) { if (array[from] = pivot

Re: QSort in D: is this best?

2009-12-20 Thread Lutger
downs wrote: Or are there any bugs/optimization opportunities I'm missing? void qsort(T)(T[] array) { if (array.length 2) return; static int i; auto pivot = array[i++%$]; // from is base-0, to is base-1. int from = 0, to = array.length; while (from != to) { if

Re: QSort in D: is this best?

2009-12-20 Thread downs
Lutger wrote: downs wrote: Or are there any bugs/optimization opportunities I'm missing? void qsort(T)(T[] array) { if (array.length 2) return; static int i; auto pivot = array[i++%$]; // from is base-0, to is base-1. int from = 0, to = array.length; while (from != to) {

Re: QSort in D: is this best?

2009-12-20 Thread Lutger
downs wrote: Lutger wrote: downs wrote: Or are there any bugs/optimization opportunities I'm missing? void qsort(T)(T[] array) { if (array.length 2) return; static int i; auto pivot = array[i++%$]; // from is base-0, to is base-1. int from = 0, to = array.length; while

Re: QSort in D: is this best?

2009-12-20 Thread bearophile
You can try translating this in efficient, readable and short D2 code using Phobos2 (the purpose is to find spots where Phobos2 may need improvements): http://rosettacode.org/wiki/Hamming_numbers#Haskell Haskell version: hamming = 1 : map (2*) hamming `merge` map (3*) hamming `merge` map (5*)

Re: QSort in D: is this best?

2009-12-20 Thread Sean Kelly
downs Wrote: Or are there any bugs/optimization opportunities I'm missing? void qsort(T)(T[] array) { if (array.length 2) return; static int i; auto pivot = array[i++%$]; // from is base-0, to is base-1. int from = 0, to = array.length; while (from != to) { if

Re: QSort in D: is this best?

2009-12-20 Thread BCS
Hello downs, Or are there any bugs/optimization opportunities I'm missing? void qsort(T)(T[] array) { if (array.length 2) return; static int i; auto pivot = array[i++%$]; // from is base-0, to is base-1. int from = 0, to = array.length; while (from != to) { if (array[from] = pivot