GeeCON Prague 2014*
The moose likes Java in General and the fly likes Example of hash function? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Example of hash function?" Watch "Example of hash function?" New topic
Author

Example of hash function?

Jhon Ortiz
Greenhorn

Joined: May 28, 2009
Posts: 16
Hi!

Now I'm creating an application to administer movies using Data Structures (Hash tables). I have searching for examples, but my search hasn't been the better.

Can you offer concrete examples: how to create a hash function, store or locate objects starting from that function.

Thanks in advance.

So long

--

Jojn Ortiz
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

http://java.sun.com/developer/Books/effectivejava/Chapter3.pdf

That tells you how to override hashCode() and equals() for a class you define.

As for storing it, just use java.util.HashMap. Unless you want to write your own for academic reasons, in which case you'll have to give it a shot on your own first and then post your efforts and a more specific question about what exactly you're having trouble with.
Jhon Ortiz
Greenhorn

Joined: May 28, 2009
Posts: 16
Thanks for your response, Jeff Verdegan.

I forgot to specify or clarify, that the Design Restrictions does not allow the use of Java Collections :-( Because of, I am coursing a Data Structures course, then we must understand low level concepts.

I need a example that uses any hash function.

Thanks, again.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Jhon Ortiz wrote:Thanks for your response, Jeff Verdegan.
I need a example that uses any hash function.


Then you can google for one.

If you want help here, you need to ShowSomeEffort(⇐click) and ask a more specific question.

Based on what you've said--"I need a example that uses any hash function"--all I can give you is this:



And you can still use the doc I linked to give you an example of how to write a hash function.

Finally, make sure you're clear--both in your own mind and in your comments and questions here--on the distinctions among a hash function, a hash-based data structure such as a hashtable that uses a hash function, and a given class's implementation of hashCode().
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

And welcome to the Ranch!
Jhon Ortiz
Greenhorn

Joined: May 28, 2009
Posts: 16
Thanks for your suggestion, Verdegan.

I have a long movie list (Name, Year, Description), I'm trying to create a function for that to create indices to store a value to correspond to that value produced by hash function.

As I said, I can't use Java Collections Framework. Now I am searching in other forums, but I have found a useful to understand that topic.

Thanks.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

You still haven't shown what you've tried, and you still haven't asked a specific question about a specific thing that you're having trouble with.

And, yes, I get that you can't use Java's Collections. That doesn't mean you can't use the hashCode() method, and it doesn't mean you can't learn how to write a hashing function from the document I linked in my first response? Did you even read it?

I gotta say, I'm getting a little frustrated here.
Jhon Ortiz
Greenhorn

Joined: May 28, 2009
Posts: 16
You are right, Verdeban.

I am going to be more specific. Give some time to create a more complete and specific answer.

See you later.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Jhon Ortiz wrote:
I am going to be more specific. Give some time to create a more complete and specific answer.


Cool. I'm looking forward to it!
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
If you want to learn about hashing, check out the relevant chapter in Niklaus Wirth's classic book Algorithms and Data Structures. It's well worth the read.
dennis deems
Ranch Hand

Joined: Mar 12, 2011
Posts: 808
Jeff Verdegan wrote:I gotta say, I'm getting a little frustrated here.

Take a deep breath and count to a thousand by sevens.
 
GeeCON Prague 2014
 
subject: Example of hash function?