Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > efficient use of hashtable with string like keys

Thread Tools

efficient use of hashtable with string like keys

Roedy Green
Posts: n/a
On 16 Aug 2003 05:29:03 -0700, Removed) (Harald Kirsch) wrote
or quoted :

>I hoped someone
>came up with an ingenious idea of how to borrow String.hashcode() and and
>String.equals() and apply it to StringBuffer without rewriting everything.

A few thoughts:

1. You can't change the lookup hashCode of an object in a HashMap on
the fly. You have to remove it, change the fields the hashCode
depends on and re-add it. HashMap presumes the hashCode won't change.

2. You would likely want to cache it since it is expensive to compute.

3. If the StringBuffer is changing all the time, you might want a
faster but lower quality algorithm, or perhaps even one that just
looks at the first few characters to speed computation. You don't
need to recompute it if the first few chars don't change.

Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See for The Java Glossary.
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: I need something like a "Hashtable<String[], Integer>" kind ofdata type ... Tom Anderson Java 1 11-28-2010 10:39 PM
Re: hashtable or map? (map inserts not behaving as I expect - and I cant find a decent simple example for hashtable) Kai-Uwe Bux C++ 1 12-21-2008 09:25 PM
Hashtable filled with own key just has the same keys in enumeration. Java 8 06-19-2006 07:08 PM
how to sort the keys from Hashtable into Alphabet order when use for output display Java 8 05-08-2006 08:29 AM
Hashtable/Two keys Alexander Mueller Java 29 03-22-2005 10:57 AM