Re: Why std.algorithm.sort can't be applied to char[]?

2014-05-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On Wed, 14 May 2014 05:13:42 -0400, Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Wed, 14 May 2014 08:27:45 + monarch_dodra via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Monday, 12 May 2014 at 18:44:22 UTC, Jonathan M Davis

Re: Why std.algorithm.sort can't be applied to char[]?

2014-05-15 Thread monarch_dodra via Digitalmars-d-learn
On Wednesday, 14 May 2014 at 09:01:23 UTC, John Colvin wrote: Why would anyone ever want to sort code-points? Why not? To remove duplicate characters? They might want to sort graphemes, but that's difficult to do in-place (needs O(n) memory, I think...). If out-of-place is good enough

Re: Why std.algorithm.sort can't be applied to char[]?

2014-05-15 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 15 May 2014 at 13:26:45 UTC, Steven Schveighoffer wrote: On Wed, 14 May 2014 05:13:42 -0400, Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Wed, 14 May 2014 08:27:45 + monarch_dodra via Digitalmars-d-learn

Re: Why std.algorithm.sort can't be applied to char[]?

2014-05-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On Thu, 15 May 2014 11:37:07 -0400, monarch_dodra monarchdo...@gmail.com wrote: On Thursday, 15 May 2014 at 13:26:45 UTC, Steven Schveighoffer wrote: On Wed, 14 May 2014 05:13:42 -0400, Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Wed, 14 May 2014

Re: Why std.algorithm.sort can't be applied to char[]?

2014-05-15 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 15 May 2014 at 17:46:52 UTC, Steven Schveighoffer wrote: As far as I'm concerned, if we *can* do it in n.log(n), and somebody provides the implementation, then there is no reason to not offer dchar sorting for char[]/wchar. I think there is nothing wrong with requiring the steps

Re: Why std.algorithm.sort can't be applied to char[]?

2014-05-14 Thread monarch_dodra via Digitalmars-d-learn
On Monday, 12 May 2014 at 18:44:22 UTC, Jonathan M Davis via Digitalmars-d-learn wrote: Sure, you can cast char[] to ubyte[] and sort that if you know that the array only holds pure ASCII. In fact, you can use std.string.representation to do it - e.g. auto ascii = str.representation; and if

Re: Why std.algorithm.sort can't be applied to char[]?

2014-05-14 Thread bearophile via Digitalmars-d-learn
monarch_dodra: As a matter of fact, the built in sort property does it. It's going to be deprecated soon. Bye, bearophile

Re: Why std.algorithm.sort can't be applied to char[]?

2014-05-14 Thread John Colvin via Digitalmars-d-learn
On Wednesday, 14 May 2014 at 08:27:46 UTC, monarch_dodra wrote: On Monday, 12 May 2014 at 18:44:22 UTC, Jonathan M Davis via Digitalmars-d-learn wrote: Sure, you can cast char[] to ubyte[] and sort that if you know that the array only holds pure ASCII. In fact, you can use

Re: Why std.algorithm.sort can't be applied to char[]?

2014-05-14 Thread Jonathan M Davis via Digitalmars-d-learn
On Wed, 14 May 2014 08:27:45 + monarch_dodra via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Monday, 12 May 2014 at 18:44:22 UTC, Jonathan M Davis via Digitalmars-d-learn wrote: Sure, you can cast char[] to ubyte[] and sort that if you know that the array only

Re: Why std.algorithm.sort can't be applied to char[]?

2014-05-13 Thread hane via Digitalmars-d-learn
On Monday, 12 May 2014 at 14:56:46 UTC, John Colvin wrote: char[] is a rather special type of array: the language has unicode support and iterates over it by code-point (i.e. not guaranteed to be a single char per iteration). If you want to sort chars and are assuming ASCII, you can just use

Why std.algorithm.sort can't be applied to char[]?

2014-05-12 Thread hane via Digitalmars-d-learn
and is there any way to sort char array with algorithm.sort? --- import std.algorithm; import std.range; void main() { int[] arr = [5, 3, 7]; sort(arr); // OK char[] arr2 = ['z', 'g', 'c']; sort(arr2); // error sort!q{ a[0] b[0] }(zip(arr, arr2)); // error } --- I don't know what's

Re: Why std.algorithm.sort can't be applied to char[]?

2014-05-12 Thread John Colvin via Digitalmars-d-learn
On Monday, 12 May 2014 at 14:49:53 UTC, hane wrote: and is there any way to sort char array with algorithm.sort? --- import std.algorithm; import std.range; void main() { int[] arr = [5, 3, 7]; sort(arr); // OK char[] arr2 = ['z', 'g', 'c']; sort(arr2); // error sort!q{ a[0] b[0]

Re: Why std.algorithm.sort can't be applied to char[]?

2014-05-12 Thread John Colvin via Digitalmars-d-learn
On Monday, 12 May 2014 at 14:56:46 UTC, John Colvin wrote: On Monday, 12 May 2014 at 14:49:53 UTC, hane wrote: and is there any way to sort char array with algorithm.sort? --- import std.algorithm; import std.range; void main() { int[] arr = [5, 3, 7]; sort(arr); // OK char[] arr2 = ['z',

Re: Why std.algorithm.sort can't be applied to char[]?

2014-05-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Mon, 12 May 2014 14:49:52 + hane via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: and is there any way to sort char array with algorithm.sort? --- import std.algorithm; import std.range; void main() { int[] arr = [5, 3, 7]; sort(arr); // OK char[] arr2 =

Re: Why std.algorithm.sort can't be applied to char[]?

2014-05-12 Thread Charles Hixson via Digitalmars-d-learn
On 05/12/2014 09:29 AM, Jonathan M Davis via Digitalmars-d-learn wrote: On Mon, 12 May 2014 14:49:52 + hane via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: and is there any way to sort char array with algorithm.sort? --- import std.algorithm; import std.range; void main()

Re: Why std.algorithm.sort can't be applied to char[]?

2014-05-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Mon, 12 May 2014 11:08:47 -0700 Charles Hixson via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On 05/12/2014 09:29 AM, Jonathan M Davis via Digitalmars-d-learn wrote: On Mon, 12 May 2014 14:49:52 + hane via Digitalmars-d-learn digitalmars-d-learn@puremagic.com