Performance of hashes and associative arrays

Dan dbdavidson at yahoo.com
Sat Nov 10 05:17:23 PST 2012


On Saturday, 10 November 2012 at 07:55:18 UTC, Raphaël Jakse 
wrote:
> Hello,
>
> Thanks for this complete answer. I will take a look to your 
> code.

Ok - good. I've been using 2.061 which I just realized allows 
"dup" on an associative array, a feature which was not available 
in 2.060. So mixin(Dup) and the unit tests require 2.061.

> If you didn't read it, it might interest you. Here it is:
>

I had not seen it and will read - thanks.

>>
>>> Questions are :
>>> - what is the most efficient solution, and in which case ?
>>
>> No string concatenation is good. I think a single pass on all 
>> important
>> data (in most cases is all the data) is the goal.
>
> I'm not sure I understood well. You wanted to say that string 
> contatenations are good, right ?
>

I just meant string concatenation is likely unnecessary. Imagine 
two one megabyte strings. It is easy to concat them and call the 
string hash function on the result but you have to create a 2Mb 
string first. Alternatively, you could hash each and combine the 
hash codes in some consistent way.

> I was thinking about a hash function that would take several 
> arguments and hash them together. That would let take in 
> account more than one string in the hash while avoiding 
> concatenation.
>
Yes.

Thanks
Dan




More information about the Digitalmars-d-learn mailing list