On Wed, 29 Dec 2004 18:54:41 -0500, Tom Metro <[EMAIL PROTECTED]> wrote:
> Ben Tilly wrote:
> > That said, the suggestion of using MD5 keys is a non-starter for
> > eliminating the performance issue.  Calculating an MD5 hash of a
> > string of length n is O(n).
> 
> The qualifier I added to my suggestion of using MD5 was that the
> application be of a write-once, read-many nature, with respect to the
> keys. Thus once you generate the digest of the long key, you cache it.
> It isn't a universal solution.

Where do you cache it, and given that you've cached it, why not
cache the hash value instead?

That is, if you're going to write once, read many times, you can do
something like this:

  my $value_ref = \ $hash{$big_key};
  # now access $$value_ref lots of times

This strikes me as simpler and more efficient than the following:

  my $short_key = md5($big_key);
  # now access $hash{$short_key} lots of times

The only problem with this scheme is that if $big_key is not in
the hash it can be inconvenient.  But even so, you may find that
two regular hash lookups in Perl are faster than computing one
md5 hash.  (Or you may not - benchmark it.)

Cheers,
Ben
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to