Jump to content




help hash


  • You cannot reply to this topic
3 replies to this topic

#1 SpencerBeige

  • Members
  • 263 posts

Posted 24 February 2015 - 04:00 PM

can anyone turn:
    uint32_t hash, i;
    for(hash = i = 0; i < len; ++i)
    {
	    hash += key[i];
	    hash += (hash << 10);
	    hash ^= (hash >> 6);
    }
    hash += (hash << 3);
    hash ^= (hash >> 11);
    hash += (hash << 15);
    return hash;
into lua? its the 'jenkin's hash, which im going to use in a program, but i just...cant'

the reason i cant is im not good in this language. i'd give the first person to do it, a virtual cookie

#2 GopherAtl

  • Members
  • 888 posts

Posted 24 February 2015 - 04:09 PM

Guessing that key is a string? if so...

local function jenkins(key)
  local hash, i=0,0
  for i = 1,  #key do
    hash = hash + string.byte(key,i)
    hash = (hash  + hash*1024)%0x100000000
    hash = bit.bxor(hash,math.floor(hash/64))
  end
  hash =(hash+hash*8)%0x100000000
  hash=bit.bxor(hash,math.floor(hash/2048))
  hash = (hash + hash*32767)%0x100000000
  return hash
end

:edit: rapid-fire series of edits as I was having a derpy moment there

Edited by GopherAtl, 24 February 2015 - 04:15 PM.


#3 SpencerBeige

  • Members
  • 263 posts

Posted 24 February 2015 - 04:10 PM

thanks!

#4 SpencerBeige

  • Members
  • 263 posts

Posted 24 February 2015 - 04:33 PM

[content removed]

Edited by slow-coder, 24 February 2015 - 04:35 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users