1 Replies - 5888 Views - Last Post: 12 April 2007 - 06:41 AM Rate Topic: -----

#1 stl_cards   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 26-March 07

Hash function

Posted 11 April 2007 - 06:54 PM

I need to come up with a hash function with a minimal amount of collisions. I have been given 10 numbers and have to have 23 spaces to store them. The numbers are: 774, 843, 889, 912, 958, 16, 85, 200, 315, 407. The best thing I have come up with is Num / 4 %(MOD) 23
Is This A Good Question/Topic? 0
  • +

Replies To: Hash function

#2 NickDMax   User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2255
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Hash function

Posted 12 April 2007 - 06:41 AM

Well you could just nomalize and use: hash = (double)Num/Max * 23;
<mathematica code>
hash[x_] := Floor[(x/1000)*23]
hash[{774, 843, 889, 912, 958, 16, 85, 200, 315, 407}] 
-> {17, 19, 20, 20, 22, 0, 1, 4, 7, 9} 
which only has 20 twice.

and 

hash[x_] := Floor[(x/1024)*23]
hash[{774, 843, 889, 912, 958, 16, 85, 200, 315, 407}] 
-> {17, 18, 19, 20, 21, 0, 1, 4, 7, 9} 
each item has a unique hash.

When i use your version 
hash[x_]:=Mod[Floor[x/4],23]
hash[{774, 843, 889, 912, 958, 16, 85, 200, 315, 407}] 
-> {9, 3, 15, 21, 9, 4, 21, 4, 9, 9}
which has a problem with 9's and 21's... however 
hash[x_]:=Mod[Floor[x/45],23]
hash[{774, 843, 889, 912, 958, 16, 85, 200, 315, 407}] 
-> {17, 18, 19, 20, 21, 0, 1, 4, 7, 9} 
(coincidance... I think not!!!)
</mathematica code>


Well I will leave you to figure out what way to use and why.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1