www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - .rehash

reply bearophile <bearophileHUGS lycos.com> writes:
I think D builtins lack some very useful methods (member functions), like an
index() for the arrays, a dup/deepdup for the associative arrays, and so on.
On the other hand I have tried to use the .rehash method few times, but most
times its usage increases the total running time of my small program. So do you
use the rehash method? If not enough people find it useful, then it may be
removed, simplifying the API (freeing *brain* space for more important methods).

Bye,
bearophile
Sep 30 2008
parent reply dsimcha <dsimcha yahoo.com> writes:
Rehash is nice, in my experience, for the specific but common usage case of
dumping tons of data into an AA, and then using it for lots of read-only access
after it's been built.  Hash collisions greatly hurt the performance of AAs.
Rehash basically increases the hash space if necessary, to lessen hash
collisions
at the price of slightly more memory usage and some upfront processing time. 
This
happens anyway occasionally as your AA gets larger, but calling .rehash makes it
happen explicitly.
Sep 30 2008
parent bearophile <bearophileHUGS lycos.com> writes:
dsimcha:
 Rehash is nice, in my experience, for the specific but common usage case of
 dumping tons of data into an AA, and then using it for lots of read-only access
 after it's been built.  Hash collisions greatly hurt the performance of AAs.
 Rehash basically increases the hash space if necessary, to lessen hash
collisions
 at the price of slightly more memory usage and some upfront processing time. 
This
 happens anyway occasionally as your AA gets larger, but calling .rehash makes
it
 happen explicitly.
Have you timed your real programs (not benchmarks) and seen an actual improvement of their global running times? Bye, bearophile
Sep 30 2008