Re: avoid toLower in std.algorithm.sort compare alias

2012-04-26 Thread Marco Leise
Am Sun, 22 Apr 2012 09:23:45 +0200 schrieb Jay Norwood j...@prismnet.com: On Sunday, 22 April 2012 at 06:26:42 UTC, Jonathan M Davis wrote: You can look at the code. It checks each of the characters in place. Unlike toLower, it doesn't need to generate a new string. But as far as the

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-24 Thread Regan Heath
On Mon, 23 Apr 2012 16:43:20 +0100, Steven Schveighoffer schvei...@yahoo.com wrote: While dealing with unicode in my std.stream rewrite, I've found that hand-decoding dchars is way faster than using library calls. After watching Andrei's talk on generic and generative programming I have

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-24 Thread Steven Schveighoffer
On Tuesday, 24 April 2012 at 11:24:44 UTC, Regan Heath wrote: On Mon, 23 Apr 2012 16:43:20 +0100, Steven Schveighoffer schvei...@yahoo.com wrote: While dealing with unicode in my std.stream rewrite, I've found that hand-decoding dchars is way faster than using library calls. After watching

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-24 Thread Steven Schveighoffer
On Tuesday, 24 April 2012 at 14:54:48 UTC, Steven Schveighoffer wrote: On Tuesday, 24 April 2012 at 11:24:44 UTC, Regan Heath wrote: After watching Andrei's talk on generic and generative programming I have to ask, which routines are you avoiding .. it seems we need to make them as good as the

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-24 Thread Jonathan M Davis
On Tuesday, April 24, 2012 12:24:44 Regan Heath wrote: On Mon, 23 Apr 2012 16:43:20 +0100, Steven Schveighoffer schvei...@yahoo.com wrote: While dealing with unicode in my std.stream rewrite, I've found that hand-decoding dchars is way faster than using library calls. After watching

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-23 Thread Steven Schveighoffer
On Sat, 21 Apr 2012 19:24:56 -0400, Jay Norwood j...@prismnet.com wrote: While playing with sorting the unzip archive entries I tried use of the last example in http://dlang.org/phobos/std_algorithm.html#sort std.algorithm.sort!(toLower(a.name)

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-23 Thread Jay Norwood
On Monday, 23 April 2012 at 11:27:40 UTC, Steven Schveighoffer wrote: I think using std.string.icmp is the best solution. I would expect it to outperform even schwartz sort. -Steve icmp took longer... added about 1 sec vs 0.3 sec (for schwartzSort ) to the program execution time. bool

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-23 Thread Steven Schveighoffer
On Mon, 23 Apr 2012 09:49:50 -0400, Jay Norwood j...@prismnet.com wrote: On Monday, 23 April 2012 at 11:27:40 UTC, Steven Schveighoffer wrote: I think using std.string.icmp is the best solution. I would expect it to outperform even schwartz sort. -Steve icmp took longer... added about 1

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-22 Thread Jay Norwood
On Sunday, 22 April 2012 at 02:29:45 UTC, Jonathan M Davis wrote: Regardless of whether it's the Big(O) complexity or the constant factor that's the problem here, clearly there's enough additional overhead that it's causing problems for Jay's particular case. It's also the sort of thing that

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-22 Thread Jonathan M Davis
On Sunday, April 22, 2012 08:20:13 Jay Norwood wrote: The comment below worries me a little bit about std.string.icmp. What if they are two 1MB strings that differ in he first character? Does it really convert both strings to lower case before comparing the first character?

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-22 Thread Jay Norwood
On Sunday, 22 April 2012 at 06:26:42 UTC, Jonathan M Davis wrote: You can look at the code. It checks each of the characters in place. Unlike toLower, it doesn't need to generate a new string. But as far as the comparison goes, they're the same - hence that line in the docs. - Jonathan M

Re: toLower() and Unicode are incomplete was: Re: avoid toLower in std.algorithm.sort compare alias

2012-04-22 Thread Dmitry Olshansky
On 22.04.2012 5:43, Ali Çehreli wrote: On 04/21/2012 04:24 PM, Jay Norwood wrote: While playing with sorting the unzip archive entries I tried use of the last example in http://dlang.org/phobos/std_algorithm.html#sort std.algorithm.sort!(toLower(a.name)

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-22 Thread Jacob Carlborg
On 2012-04-22 01:24, Jay Norwood wrote: While playing with sorting the unzip archive entries I tried use of the last example in http://dlang.org/phobos/std_algorithm.html#sort std.algorithm.sort!(toLower(a.name) toLower(b.name),std.algorithm.SwapStrategy.stable)(entries); It was terribly slow

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-22 Thread SomeDude
On Saturday, 21 April 2012 at 23:24:57 UTC, Jay Norwood wrote: While playing with sorting the unzip archive entries I tried use of the last example in http://dlang.org/phobos/std_algorithm.html#sort std.algorithm.sort!(toLower(a.name)

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-22 Thread Jay Norwood
On Sunday, 22 April 2012 at 00:36:19 UTC, bearophile wrote: Performing the toLower every time the cmp function is called doesn't change the O complexity. In Phobos there is an alternative sorting (Schwartzian sorting routime) that applies a function to each item before sorting them, usually is

avoid toLower in std.algorithm.sort compare alias

2012-04-21 Thread Jay Norwood
While playing with sorting the unzip archive entries I tried use of the last example in http://dlang.org/phobos/std_algorithm.html#sort std.algorithm.sort!(toLower(a.name) toLower(b.name),std.algorithm.SwapStrategy.stable)(entries); It was terribly slow for sorting the 34k entries in my

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-21 Thread Jonathan M Davis
On Sunday, April 22, 2012 01:24:56 Jay Norwood wrote: While playing with sorting the unzip archive entries I tried use of the last example in http://dlang.org/phobos/std_algorithm.html#sort std.algorithm.sort!(toLower(a.name) toLower(b.name),std.algorithm.SwapStrategy.stable)(entries);

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-21 Thread Jonathan M Davis
On Saturday, April 21, 2012 20:36:18 bearophile wrote: Jonathan M Davis: I'm not sure if it's an order of magnitude worse than your solution though, since it's been a while since I studied Big(O) notation (doing the conversion only once is still more expensive than not converting, but I'm

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-21 Thread H. S. Teoh
On Sat, Apr 21, 2012 at 05:45:35PM -0700, Jonathan M Davis wrote: On Saturday, April 21, 2012 20:36:18 bearophile wrote: Jonathan M Davis: I'm not sure if it's an order of magnitude worse than your solution though, since it's been a while since I studied Big(O) notation (doing the

toLower() and Unicode are incomplete was: Re: avoid toLower in std.algorithm.sort compare alias

2012-04-21 Thread Ali Çehreli
On 04/21/2012 04:24 PM, Jay Norwood wrote: While playing with sorting the unzip archive entries I tried use of the last example in http://dlang.org/phobos/std_algorithm.html#sort std.algorithm.sort!(toLower(a.name) toLower(b.name),std.algorithm.SwapStrategy.stable)(entries); Stealing this

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-21 Thread Jay Norwood
On Saturday, 21 April 2012 at 23:54:26 UTC, Jonathan M Davis wrote: Yeah. toLower would be called on both strings on _every_ compare. And since that involves a loop, that would make the overall call to sort an order of magnitude worse than if you didn't call toLower at all. I'm not sure if

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-21 Thread Jonathan M Davis
On Sunday, April 22, 2012 03:47:30 Jay Norwood wrote: On Saturday, 21 April 2012 at 23:54:26 UTC, Jonathan M Davis wrote: Yeah. toLower would be called on both strings on _every_ compare. And since that involves a loop, that would make the overall call to sort an order of magnitude

Re: toLower() and Unicode are incomplete was: Re: avoid toLower in std.algorithm.sort compare alias

2012-04-21 Thread Jonathan M Davis
On Saturday, April 21, 2012 18:43:23 Ali Çehreli wrote: On 04/21/2012 04:24 PM, Jay Norwood wrote: While playing with sorting the unzip archive entries I tried use of the last example in http://dlang.org/phobos/std_algorithm.html#sort std.algorithm.sort!(toLower(a.name)

Re: avoid toLower in std.algorithm.sort compare alias

2012-04-21 Thread Jonathan M Davis
On Saturday, April 21, 2012 18:26:42 H. S. Teoh wrote: Actually, I don't think the nested loops affect Big-O complexity at all. The O(l) complexity (where l = string length) is already inherent in the string comparison str otherStr. Adding more loops over the strings doesn't change the Big-O