- hash = function(input)
- input = tostring(input);
- local h = 0
- local len = string.len(input)
- local max = 2147483647
- local min = -2147483648
- local cycle = 4294967296
- for i=1, len do
- h = 31 * h + string.byte(string.sub(input, i, i));
- while h > max do
- h = h - cycle
- end
- while h < min do
- h = h + cycle
- end
- end
- return h
- end
来源: http://www.phpxs.com/code/1005739/