>I want to create word dictionary by hash algorithm. But I don't know
>what is the best hash function for this and then how to implement hash
>table in java.
see http://mindprod.com/jgloss/hashcode.html
http://mindprod.com/jgloss/hashtable.html
http://mindprod.com/jgloss/hashmap.html
You don't have to write a hashCode function. The one can comes with
String is just fine.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Lew - 07 Jul 2007 16:10 GMT
> http://mindprod.com/jgloss/hashtable.html
> http://mindprod.com/jgloss/hashmap.html
Make sure to read the Javadocs for both these classes. Practically speaking
there is no need whatsoever any more to use Hashtable when you can make a
Collections.synchronizedMap() call on the HashMap of interest; the latter is
safer, too.

Signature
Lew
Roedy Green - 07 Jul 2007 16:22 GMT
>> http://mindprod.com/jgloss/hashtable.html
>> http://mindprod.com/jgloss/hashmap.html
[quoted text clipped - 3 lines]
>Collections.synchronizedMap() call on the HashMap of interest; the latter is
>safer, too.
The reason I send people to read about Hashtables too is that I wrote
that essay before HashMaps existed. It contains a some under the mood
information about how hashing works. I did not repeat it in the
HashMap entry.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
[ahd292 <ahd.arman@gmail.com>]
| Hi
| I want to create word dictionary by hash algorithm. But I don't know
| what is the best hash function for this and then how to implement hash
| table in java.
the simple answer is: use java.util.HashSet or java.util.HashMap,
depending on what you need. there's no need to roll your own when
adequate tools exist in the standard library.
if you have special needs that are not adequately catered for in the
standard library, it is quite hard to help you unless you identify
what those needs are.
if you are a student wanting to learn this I would suspect that your
textbook should contain something about hash functions. I can also
recommend "Effective Java" by Josh Bloch, which tells you a bit about
how you override hashCode() (and equals()). you can also locate the
src.jar file, unpack it with a Zip unpacking-utility and have a peek
at the source code of Map and Set types.
-Bjørn