Hash Function

A

ahd292

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.
please help me
thanks
 
B

Bjorn Borud

[ahd292 <[email protected]>]
| 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
 
R

Roedy Green

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.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top