• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

hash code

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is a hashcode? give an example
 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check this out.
 
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A hash code is a number, period. It's whatever you say it is. Hash code functions are either good or bad. If you take input data and generate a number from that data using an algorithm of your choosing, you have a hash code.

Here is a hash function for string data that returns a hash code:

int hash(String data) { return 0; }

Note that it returns the same value no matter what. This is the worst kind of hash function.

Here's another bad one. It adds all the characters in the string. Alice would generate the same value as Aceli or Aleic. Duplicates are allowed, however, the more you have the worse your hash function.



(sadly, strings cannot be iterated it's the idea that's important here not writing a valid hash code method)
[ September 16, 2005: Message edited by: Rick O'Shay ]
reply
    Bookmark Topic Watch Topic
  • New Topic