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
Hash function
Page 1 of 11 Replies - 5888 Views - Last Post: 12 April 2007 - 06:41 AM
Replies To: Hash function
#2
Re: Hash function
Posted 12 April 2007 - 06:41 AM
Well you could just nomalize and use: hash = (double)Num/Max * 23;
Well I will leave you to figure out what way to use and why.
<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.
Page 1 of 1

New Topic/Question
Reply



MultiQuote



|