Re: QuickSort on ranges

2020-10-18 Thread jerome via Digitalmars-d-learn
I posted some sum-up on my github. https://preview.tinyurl.com/y6sprdbq

Re: QuickSort on ranges

2020-10-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/4/20 6:50 AM, jerome wrote: Thanks you very much Ali, I will try to wrap my head around your inputs, and get a better understanding of ranges in the process. I feel there is a lot of power in D ranges, and like the hammer of Thor, I am not worthy yet :) Just to elaborate a bit furthe

Re: QuickSort on ranges

2020-10-04 Thread jerome via Digitalmars-d-learn
Thanks you very much Ali, I will try to wrap my head around your inputs, and get a better understanding of ranges in the process. I feel there is a lot of power in D ranges, and like the hammer of Thor, I am not worthy yet :)

Re: QuickSort on ranges

2020-09-12 Thread Ali Çehreli via Digitalmars-d-learn
On 9/12/20 11:25 AM, jerome wrote: > > import std.stdio : writeln; > import std.algorithm.sorting; > > pure void quickSort(T) (T[] r) > { >if (r.length > 1) >{ > size_t p = pivotPartition(r, r.length-1); //r[$-1] is swapped to r[p] > > quickSo

Re: Quicksort Variants

2014-07-09 Thread Nordlöw
On Tuesday, 8 July 2014 at 20:50:01 UTC, Nordlöw wrote: Also related: http://forum.dlang.org/thread/eaxcfzlvsakeucwpx...@forum.dlang.org#post-mailman.2809.1355844427.5162.digitalmars-d:40puremagic.com

Re: Quicksort Variants

2014-07-09 Thread Nordlöw
On Tuesday, 8 July 2014 at 20:50:01 UTC, Nordlöw wrote: I recall that Python's default sorting algorithm is related to this, right? https://en.wikipedia.org/wiki/Timsort

Re: Phobos orthogonality [Was: Re: quickSort]

2011-09-14 Thread Jonathan M Davis
On Wednesday, September 14, 2011 14:36 bearophile wrote: > Jonathan M Davis: > > So, basically, you just want to shorten your code by wrapping array(func) > > in a afunc function, and you think that this happens enough with map and > > filter enough to merit putting these functions into Phobos. >

Re: Phobos orthogonality [Was: Re: quickSort]

2011-09-14 Thread bearophile
Jonathan M Davis: > So, basically, you just want to shorten your code by wrapping array(func) in > a > afunc function, and you think that this happens enough with map and filter > enough to merit putting these functions into Phobos. There is also the point 3) that you have not seen, plus the n

Re: Phobos orthogonality [Was: Re: quickSort]

2011-09-14 Thread Jonathan M Davis
On Wednesday, September 14, 2011 07:46:37 bearophile wrote: > Jonathan M Davis: > > What would that gain you over passing the result of map or filter to > > std.array.array? > > 1) The code gets shorter > 2) The code gets a bit less noisy, because () add noise. > 3) You use a single function inste

Phobos orthogonality [Was: Re: quickSort]

2011-09-14 Thread bearophile
Jonathan M Davis: > What would that gain you over passing the result of map or filter to > std.array.array? 1) The code gets shorter 2) The code gets a bit less noisy, because () add noise. 3) You use a single function instead of two, so you reduce the number of chunks your brain has to manage.

Re: quickSort

2011-09-14 Thread Jonathan M Davis
On Wednesday, September 14, 2011 06:09:52 bearophile wrote: > %u: > > i have qustion why filter can't return int[] > > Because a lazy filter is handy, you often don't need a real array result, a > lazy sequence is enough. A lazy sequence avoids the memory allocation of > the output array. In D pro

Re: quickSort

2011-09-14 Thread bearophile
%u: > i have qustion why filter can't return int[] Because a lazy filter is handy, you often don't need a real array result, a lazy sequence is enough. A lazy sequence avoids the memory allocation of the output array. In D programs often the slowest parts are the memory allocations. On the othe

Re: quickSort

2011-09-13 Thread Jonathan M Davis
On Wednesday, September 14, 2011 05:43:37 %u wrote: > i have qustion why filter can't return int[] > and if lambda return the last Expression without return keyword it would > much cleaner filter can't return int[]. filter does not alter the original array. It returns a new range with only the e

Re: quickSort

2011-09-13 Thread %u
i have qustion why filter can't return int[] and if lambda return the last Expression without return keyword it would much cleaner

Re: quickSort

2011-09-13 Thread Timon Gehr
On 09/14/2011 04:12 AM, Timon Gehr wrote: On 09/14/2011 03:34 AM, hdsh wrote: this my try int[] quickSort(int[] arr) { int[] result = quickSort(filter!(arr< arr[0])(arr)) ~ arr[0] ~ quickSort(filter!(arr> arr[0])(arr)); } but it fail to compile Note that this approach is an inefficient way o

Re: quickSort

2011-09-13 Thread Timon Gehr
On 09/14/2011 03:34 AM, hdsh wrote: this my try int[] quickSort(int[] arr) { int[] result = quickSort(filter!(arr< arr[0])(arr)) ~ arr[0] ~ quickSort(filter!(arr> arr[0])(arr)); } but it fail to compile Note that this approach is an inefficient way of implementing a sorting routine.

Re: quickSort

2011-09-13 Thread Jonathan M Davis
On Wednesday, September 14, 2011 01:34:34 hdsh wrote: > this my try > > int[] quickSort(int[] arr) { > int[] result = quickSort(filter!(arr < arr[0])(arr)) ~ arr[0] ~ > quickSort(filter!(arr > arr[0])(arr)); > } > > but it fail to compile filter does not return an array. It returns a new ran