Re: std.container.RedBlackTree versus C++ std::set

2013-02-14 Thread Ivan Kazmenko
Namespace wrote: A small but nice intentioned advice of me is this article: http://dlang.org/dstyle.html "The names of user-defined types should be PascalCased, which is the same as camelCased except that the first letter is uppercase." Thanks for pointing that out. Indeed, PascalCase seems

Re: std.container.RedBlackTree versus C++ std::set

2013-02-14 Thread Ivan Kazmenko
Steven Schveighoffer wrote: Again, the issue here is D has restrictions on ref parameters. There are no such restrictions on pass-by-value parameters. So by default, the predicate tries by-value. I am starting to understand the difficulty with ref being too restrictive. Some kind of "cons

Re: std.container.RedBlackTree versus C++ std::set

2013-02-14 Thread Namespace
As I said elsewhere, the issue is D not having a good solution for accepting both rvalues and lvalues by ref. Jonathan mentioned auto ref, but it's not exactly implemented correctly. In C++, it just takes all parameters as const T&, and that works for both lvalues and rvalues. The extra 200

Re: std.container.RedBlackTree versus C++ std::set

2013-02-14 Thread Steven Schveighoffer
On Thu, 14 Feb 2013 15:33:19 -0500, Ivan Kazmenko wrote: ... I get only exactly 3 * LIMIT postblit constructor calls, which is 300,000 instead of 11,389,556. While I still want to find where the excess 200,000 calls originate from, this is definitely asymptotically better than before As

Re: std.container.RedBlackTree versus C++ std::set

2013-02-14 Thread Steven Schveighoffer
On Thu, 14 Feb 2013 15:33:19 -0500, Ivan Kazmenko wrote: Rob T wrote: When I look at the std.container source code, it seems that the payload element is passed by value multiple times unnecessarily, so to minimize copy construction you'll have to implement element as a class and implement

Re: std.container.RedBlackTree versus C++ std::set

2013-02-14 Thread monarch_dodra
On Thursday, 14 February 2013 at 20:44:13 UTC, bearophile wrote: Ivan Kazmenko: Thank you all for assistance, I've finally pinned it down! This is great. The first step to solve a problem is to find it. The second step is to formalize it. So I suggest you to create a small benchmark that sh

Re: std.container.RedBlackTree versus C++ std::set

2013-02-14 Thread Jonathan M Davis
On Thursday, February 14, 2013 14:31:36 Steven Schveighoffer wrote: > On Thu, 14 Feb 2013 13:45:30 -0500, Rob T wrote: > > When I look at the std.container source code, it seems that the payload > > element is passed by value multiple times unnecessarily, so to minimize > > copy construction you'l

Re: std.container.RedBlackTree versus C++ std::set

2013-02-14 Thread Namespace
On Thursday, 14 February 2013 at 20:20:59 UTC, Rob T wrote: On Thursday, 14 February 2013 at 19:56:33 UTC, Namespace wrote: There are discussions for such thing for almost a year - but nothing has changed so far. I think its finally on the priority radar, but there's still other things in m

Re: std.container.RedBlackTree versus C++ std::set

2013-02-14 Thread bearophile
Ivan Kazmenko: Thank you all for assistance, I've finally pinned it down! This is great. The first step to solve a problem is to find it. The second step is to formalize it. So I suggest you to create a small benchmark that shows what you mean (it should not include RedBlackTree) and put it

Re: std.container.RedBlackTree versus C++ std::set

2013-02-14 Thread Ivan Kazmenko
Rob T wrote: When I look at the std.container source code, it seems that the payload element is passed by value multiple times unnecessarily, so to minimize copy construction you'll have to implement element as a class and implement a dup function for it. Thank you all for assistance, I've f

Re: std.container.RedBlackTree versus C++ std::set

2013-02-14 Thread Rob T
On Thursday, 14 February 2013 at 19:56:33 UTC, Namespace wrote: There are discussions for such thing for almost a year - but nothing has changed so far. I think its finally on the priority radar, but there's still other things in more dire need to be resolved first, like @property and lack

Re: std.container.RedBlackTree versus C++ std::set

2013-02-14 Thread Namespace
On Thursday, 14 February 2013 at 19:31:36 UTC, Steven Schveighoffer wrote: On Thu, 14 Feb 2013 13:45:30 -0500, Rob T wrote: When I look at the std.container source code, it seems that the payload element is passed by value multiple times unnecessarily, so to minimize copy construction you'll

Re: std.container.RedBlackTree versus C++ std::set

2013-02-14 Thread Rob T
On Thursday, 14 February 2013 at 19:31:36 UTC, Steven Schveighoffer wrote: On Thu, 14 Feb 2013 13:45:30 -0500, Rob T wrote: When I look at the std.container source code, it seems that the payload element is passed by value multiple times unnecessarily, so to minimize copy construction you'll

Re: std.container.RedBlackTree versus C++ std::set

2013-02-14 Thread Steven Schveighoffer
On Thu, 14 Feb 2013 13:45:30 -0500, Rob T wrote: When I look at the std.container source code, it seems that the payload element is passed by value multiple times unnecessarily, so to minimize copy construction you'll have to implement element as a class and implement a dup function for it

Re: std.container.RedBlackTree versus C++ std::set

2013-02-14 Thread Rob T
When I look at the std.container source code, it seems that the payload element is passed by value multiple times unnecessarily, so to minimize copy construction you'll have to implement element as a class and implement a dup function for it. I expect performance will increase substantially ev

Re: std.regex: bug or something special?

2013-02-14 Thread Dmitry Olshansky
14-Feb-2013 22:24, Lubos Pintes пишет: Hi, I am reading std.regex. I found the following code on line 671: else if('A' <= current && current <= 'Z') val = val * 16 + current - 'A' + 10; Hex digits are parsed there. So unles this is something special, this is a bug. Because

Re: How to read fastly files ( I/O operation)

2013-02-14 Thread bioinfornatics
Mr.Bio, what usage cases you'll be interested in, other than those counters? some idea such as letter counting: rename identifier trimming sequence from quality value to cutoff convert to a binary format convert to fasta + sff merge close sequence to one concenus create a brujin graph more ide

Re: std.regex: bug or something special?

2013-02-14 Thread H. S. Teoh
On Thu, Feb 14, 2013 at 07:24:32PM +0100, Lubos Pintes wrote: > Hi, > I am reading std.regex. I found the following code on line 671: > else if('A' <= current && current <= 'Z') > val = val * 16 + current - 'A' + 10; > > Hex digits are parsed there. So unles this is something s

std.regex: bug or something special?

2013-02-14 Thread Lubos Pintes
Hi, I am reading std.regex. I found the following code on line 671: else if('A' <= current && current <= 'Z') val = val * 16 + current - 'A' + 10; Hex digits are parsed there. So unles this is something special, this is a bug. Because for example what 'J' would mean in this c

Re: std.container.RedBlackTree versus C++ std::set

2013-02-14 Thread Ivan Kazmenko
Dmitry Olshansky wrote: D2 (DMD 2.059, -O): 11,389,556 I'd add : -release -inline or it may not inline away temporary copies. Thank you for the suggestion. However, the result after "-O -release -inline" is still 11,389,556.

Re: std.container.RedBlackTree versus C++ std::set

2013-02-14 Thread Jonathan M Davis
On Thursday, February 14, 2013 13:27:30 monarch_dodra wrote: > Actually, (and IMO, this is a very big problem), these structures > are *always* null by default. There is no easy way to "default > initialize" structs in D :( You mean there's no way to default-construct them. They're always default-

Re: Strange that D is printing large values as zero. Any mistake in my code?

2013-02-14 Thread bearophile
Sparsh Mittal: const long DIM = 1024*1024*1024*1024*4; Vote, if you want: http://d.puremagic.com/issues/show_bug.cgi?id=4835 Go language doesn't have such bugs. Likewise D should not have such bugs. Bye, bearophile

Re: Strange that D is printing large values as zero. Any mistake in my code?

2013-02-14 Thread Joseph Rushton Wakeling
On 02/14/2013 04:49 PM, Adam D. Ruppe wrote: const long DIM = 1024*1024*1024*1024*4; Those are all int (32 bit) literals so it is prolly wrapping around the intermediates before it actually assigns to DIM. If you used 1024L it should be better, by making the right hand side 64 bit too. Oh, s

Re: Strange that D is printing large values as zero. Any mistake in my code?

2013-02-14 Thread monarch_dodra
On Thursday, 14 February 2013 at 15:44:25 UTC, Sparsh Mittal wrote: Here is the program: import std.stdio; const long DIM = 1024*1024*1024*1024*4; void main() { writeln(" DIM is ", DIM); writeln(" Value ", 1024*1024*1024*1024*4); writeln(" Max ", long.max); } I compiled it: gdc -frelease -O

Re: Strange that D is printing large values as zero. Any mistake in my code?

2013-02-14 Thread Sparsh Mittal
On Thursday, 14 February 2013 at 15:51:45 UTC, Joseph Rushton Wakeling wrote: On 02/14/2013 04:44 PM, Sparsh Mittal wrote: Can you please tell, why it is taking DIM as zero? If I reduce DIM, it works fine. It is strange. 1024 is an int value. Write 1024L instead to ensure that the calculati

Re: Strange that D is printing large values as zero. Any mistake in my code?

2013-02-14 Thread Joseph Rushton Wakeling
On 02/14/2013 04:44 PM, Sparsh Mittal wrote: Can you please tell, why it is taking DIM as zero? If I reduce DIM, it works fine. It is strange. 1024 is an int value. Write 1024L instead to ensure that the calculation is performed using long.

Re: Strange that D is printing large values as zero. Any mistake in my code?

2013-02-14 Thread Adam D. Ruppe
const long DIM = 1024*1024*1024*1024*4; Those are all int (32 bit) literals so it is prolly wrapping around the intermediates before it actually assigns to DIM. If you used 1024L it should be better, by making the right hand side 64 bit too. It is similar to float x = 1 / 2; // x == 0 bec

Strange that D is printing large values as zero. Any mistake in my code?

2013-02-14 Thread Sparsh Mittal
Here is the program: import std.stdio; const long DIM = 1024*1024*1024*1024*4; void main() { writeln(" DIM is ", DIM); writeln(" Value ", 1024*1024*1024*1024*4); writeln(" Max ", long.max); } I compiled it: gdc -frelease -O3 temp.d -o t1 ; ./t1 DIM is 0 Value 0 Max 9223372036854775807 C

Re: std.container.RedBlackTree versus C++ std::set

2013-02-14 Thread Ivan Kazmenko
If I use (as you do) this(ref this) { I get 0 as output. (dmd 2.062 beta1) If I remove the 'ref' I get 11389556. Ouch, sorry! That's a copy & paste bug I introduced when posting here. Actually, I use this (this) of course. I tried this (ref this) at some point, it does indeed c

Re: std.container.RedBlackTree versus C++ std::set

2013-02-14 Thread Steven Schveighoffer
On Thu, 14 Feb 2013 09:47:31 -0500, Namespace wrote: If I use (as you do) this(ref this) { I get 0 as output. (dmd 2.062 beta1) If I remove the 'ref' I get 11389556. this(ref this) is not a postblit. That it would even compile is a bug. -Steve

Re: std.container.RedBlackTree versus C++ std::set

2013-02-14 Thread Namespace
If I use (as you do) this(ref this) { I get 0 as output. (dmd 2.062 beta1) If I remove the 'ref' I get 11389556.

Re: std.container.RedBlackTree versus C++ std::set

2013-02-14 Thread Dmitry Olshansky
14-Feb-2013 03:22, Ivan Kazmenko пишет: Hi! I'm learning to use D collections properly, and I'm looking for a sorted data structure with logarithmic access time (i.e., a binary search tree will do, but a hash table would not help). As far as I can see, std.container.RedBlackTree is exactly what

Re: Finding large difference b/w execution time of c++ and D codes for same problem

2013-02-14 Thread Sparsh Mittal
Thanks a lot for your reply.

Re: Static class question

2013-02-14 Thread anonymous
On Thursday, 14 February 2013 at 12:49:01 UTC, Lubos Pintes wrote: Hi, I saw one ListBox class implementation. As we all know, ListBox class collects and displays strings. Author decided that he encapsulate the Object as item, and uses its toString() method when string is needed for display. Fo

Static class question

2013-02-14 Thread Lubos Pintes
Hi, I saw one ListBox class implementation. As we all know, ListBox class collects and displays strings. Author decided that he encapsulate the Object as item, and uses its toString() method when string is needed for display. For cases when string is added, he defined this small class, internal

Re: std.container.RedBlackTree versus C++ std::set

2013-02-14 Thread monarch_dodra
On Thursday, 14 February 2013 at 10:58:19 UTC, Namespace wrote: struct S { static struct Payload { //Tons of data here } Payload* _p; //fonctions } Ref counted is implemented that way. most of the containers are also implemented that way. associative arrays are also impl

Re: std.container.RedBlackTree versus C++ std::set

2013-02-14 Thread Ivan Kazmenko
First, thank you all for the replies! Jonathan M Davis wrote: Also, it could make a big difference if you use gdc or ldc rather than dmd. Thank you for the suggestion, I'll check that. However, I don't expect the GCC optimizer to reduce the number of calls in this specific test, since it di

Re: std.container.RedBlackTree versus C++ std::set

2013-02-14 Thread Namespace
struct S { static struct Payload { //Tons of data here } Payload* _p; //fonctions } Ref counted is implemented that way. most of the containers are also implemented that way. associative arrays are also implemented that way under the hood. But you have to allocate

Re: std.container.RedBlackTree versus C++ std::set

2013-02-14 Thread monarch_dodra
On Thursday, 14 February 2013 at 10:44:22 UTC, Namespace wrote: Another good balance are stack based struct pointer wrappers to implementation : You can pass them by value, but they carry a complex payload. I'm not sure what that is. Can you give a small example? struct S { static struct

Re: std.container.RedBlackTree versus C++ std::set

2013-02-14 Thread Namespace
Another good balance are stack based struct pointer wrappers to implementation : You can pass them by value, but they carry a complex payload. I'm not sure what that is. Can you give a small example?

Re: std.container.RedBlackTree versus C++ std::set

2013-02-14 Thread monarch_dodra
On Thursday, 14 February 2013 at 10:23:18 UTC, Namespace wrote: I agree. There are cases where structs make a lot of sense, usually when they are very simple simple and contain no pointers or references, otherwise structs should be avoided in favor of classes to avoid doing copy/move constructo

Re: std.container.RedBlackTree versus C++ std::set

2013-02-14 Thread Namespace
I agree. There are cases where structs make a lot of sense, usually when they are very simple simple and contain no pointers or references, otherwise structs should be avoided in favor of classes to avoid doing copy/move constructors and to avoid concerns over performance optimizations. With cl

Re: std.container.RedBlackTree versus C++ std::set

2013-02-14 Thread Rob T
On Thursday, 14 February 2013 at 06:56:38 UTC, monarch_dodra wrote: On Wednesday, 13 February 2013 at 23:22:03 UTC, Ivan Kazmenko wrote: Hi! - Ivan Kazmenko. Keep in mind that C++ and D have very different philosophies regarding copy construction. C++ has "strong ownership", so for exam

Re: Mixin template function

2013-02-14 Thread cal
On Thursday, 14 February 2013 at 07:40:58 UTC, Jacob Carlborg wrote: This is by design. Foo and A have different overload sets. Try: alias Foo.foo foo; http://dlang.org/template-mixin.html Search for: "Mixin Scope" and pay attention to: "Alias declarations can be used to overload together fun