实现Java字符串的Hash算法

2015-12-14 0 671
实现Java字符串的Hash算法
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

遇见资源网 lua 实现Java字符串的Hash算法 http://www.ox520.com/14702.html

上一篇:

已经没有上一篇了!

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务