perfect hash? (nope)

General FreeBASIC programming questions.
Post Reply
dafhi
Posts: 1472
Joined: Jun 04, 2005 9:51

perfect hash? (nope)

Post by dafhi »

false alarm.
forgot to update test utility with new formula. used an old fomula which hits all buckets but pattern-ish output

old post:
think i found a perfect hash! it misses no buckets which means ..
1. might be making use of the ginormous period, or
2. flat distr. .. (i think this is the case)

will test later. for anyone interested ..

Code: Select all

'' update 2:  added '+1' in the algorithm, and a s() function returning a standard 'rnd' single
type statelit    as ulongint
  
  
  namespace dsi_hash ''

dim as statelit a, b

dim as ulongint mulC = &b10000000001000000001000000010000001000001000010001001011

sub reset
  a = 0
  b = 0
end sub

function valu( i as ulongint = 0) as statelit
  b += (a xor (i+1))
  a += (b * mulc) shr 1
  return a
End function

function s( i as ulongint = 0) as single
  return valu(i) / (cast(statelit, -1) + 1)
end function

function ini( i as ulongint = 0) as statelit
  reset
  return valu(i)
End function

End Namespace ' -- dsi_hash --
Post Reply