Hashtron inference: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: mior tidy) |
m (→{{header|Phix}}: (hmpf)) |
||
Line 328: | Line 328: | ||
function hashtron(integer n, s, mx) |
function hashtron(integer n, s, mx) |
||
// Mixing stage, mix input with salt using subtraction |
// Mixing stage, mix input with salt using subtraction |
||
atom m = |
atom m = (n-s) && U32 |
||
// Hashing stage, use xor shift with prime coefficients |
// Hashing stage, use xor shift with prime coefficients |
||
for p in {-2,-3,+5,+7,-11,-13,+17,-19} do |
for p in {-2,-3,+5,+7,-11,-13,+17,-19} do |
||
m = xor_bitsu(m, |
m = xor_bitsu(m,shift_bits(m,p) && U32) |
||
end for |
end for |
||
// Mixing stage 2, mix input with salt using addition |
// Mixing stage 2, mix input with salt using addition |
||
m = |
m = m+s && U32 |
||
// Modular stage using Lemire's fast alternative to modulo reduction |
// Modular stage using Lemire's fast alternative to modulo reduction |
||
Line 342: | Line 342: | ||
end function |
end function |
||
function inference(integer |
function inference(integer cmd, bits, sequence program) |
||
atom out = 0 |
atom out = 0 |
||
if length(program) then |
if length(program) then |
||
for j=0 to bits-1 do |
for j=0 to bits-1 do |
||
integer {ss, maxx} = program[1], |
integer {ss, maxx} = program[1], |
||
input = hashtron( |
input = hashtron(cmd||(j<<16), ss, maxx) |
||
for p in program from 2 do |
for p in program from 2 do |
||
maxx -= p[2] |
|||
input = hashtron(input, p[1], maxx) |
|||
input = hashtron(input, s, maxx) |
|||
end for |
end for |
||
if odd(input) then |
if odd(input) then |