Re: Struct hash issues with string fields

2012-06-03 Thread H. S. Teoh
On Sat, May 26, 2012 at 09:53:07PM +0200, Andrej Mitrovic wrote: > I don't understand this: > > import std.stdio; > > struct Symbol { string val; } > > void main() > { > int[string] hash1; > hash1["1".idup] = 1; > hash1["1".idup] = 2; > writeln(hash1); // writes "["1":2]" > >

Re: Struct hash issues with string fields

2012-05-27 Thread Ali Çehreli
On 05/27/2012 04:22 AM, Andrej Mitrovic wrote: On 5/27/12, Ali Çehreli wrote: On 05/26/2012 05:13 PM, Ali Çehreli wrote: > once you define toHash(), you > must also define opCmp() and opEquals() that are all consistent with > each other. Correction: opEquals() is only for potential o

Re: Struct hash issues with string fields

2012-05-27 Thread Andrej Mitrovic
On 5/27/12, Ali Çehreli wrote: > On 05/26/2012 05:13 PM, Ali Çehreli wrote: > > > once you define toHash(), you > > must also define opCmp() and opEquals() that are all consistent with > > each other. > > Correction: opEquals() is only for potential optimizations. What is > needed alongside toH

Re: Struct hash issues with string fields

2012-05-26 Thread Ali Çehreli
On 05/26/2012 05:13 PM, Ali Çehreli wrote: > once you define toHash(), you > must also define opCmp() and opEquals() that are all consistent with > each other. Correction: opEquals() is only for potential optimizations. What is needed alongside toHash() is just opCmp(), and the reason is to be

Re: Struct hash issues with string fields

2012-05-26 Thread Ali Çehreli
On 05/26/2012 12:53 PM, Andrej Mitrovic wrote: I don't understand this: import std.stdio; struct Symbol { string val; } void main() { int[string] hash1; hash1["1".idup] = 1; hash1["1".idup] = 2; writeln(hash1); // writes "["1":2]" int[Symbol] hash2; Symbol sym1

Re: Struct hash issues with string fields

2012-05-26 Thread Andrej Mitrovic
On 5/27/12, Era Scarecrow wrote: > Problem goes > away when not idup-ing, but likely that is the compiler saving > space and assigning the same pointer address (which makes sense). Yes, the .idup was done on purpose here for demonstration.

Re: Struct hash issues with string fields

2012-05-26 Thread Era Scarecrow
On Saturday, 26 May 2012 at 22:02:10 UTC, Jonathan M Davis wrote: Now, that aside, the results with hash2 definitely look like a bug to me. It's probably just the result of one more of the many issues with the current AA implementation. This is what I'm guessing too. I've made toHashes in my

Re: Struct hash issues with string fields

2012-05-26 Thread Jonathan M Davis
On Sunday, May 27, 2012 00:08:01 Andrej Mitrovic wrote: > On 5/27/12, Jonathan M Davis wrote: > > Why can't you have a toHash in your struct? > > I mean it doesn't seem to make any difference: Yeah. I don't know what the deal is. There's definitely at least one bug here, if not several. > impo

Re: Struct hash issues with string fields

2012-05-26 Thread Andrej Mitrovic
On 5/27/12, Jonathan M Davis wrote: > Why can't you have a toHash in your struct? I mean it doesn't seem to make any difference: import std.stdio; struct Foo { string x; size_t toHash() { return 1; } } void main() { int[Foo] hash; Foo foo1 = Foo("a".idup); Foo foo2 = Foo("a

Re: Struct hash issues with string fields

2012-05-26 Thread Jonathan M Davis
On Saturday, May 26, 2012 21:53:07 Andrej Mitrovic wrote: > I don't understand this: > > import std.stdio; > > struct Symbol { string val; } > > void main() > { > int[string] hash1; > hash1["1".idup] = 1; > hash1["1".idup] = 2; > writeln(hash1); // writes "["1":2]" > > int[

Struct hash issues with string fields

2012-05-26 Thread Andrej Mitrovic
I don't understand this: import std.stdio; struct Symbol { string val; } void main() { int[string] hash1; hash1["1".idup] = 1; hash1["1".idup] = 2; writeln(hash1); // writes "["1":2]" int[Symbol] hash2; Symbol sym1 = Symbol("1".idup); Symbol sym2 = Symbol("1".idup);