• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Example of hash function?

 
Jhon Ortiz
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch!
 
Jhon Ortiz
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 2946
46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 808
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote:I gotta say, I'm getting a little frustrated here.

Take a deep breath and count to a thousand by sevens.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic