python模拟处理java的hashCode,使用ctypes模块简化处理逻辑。
import ctypes
def hashCode(value):
h = 0
for c in value:
h = ctypes.c_int32(31 * h + ord(c)).value
return h + 31
print("output:"+hashCode("helloworld"))
# output: -1524582881
python模拟处理java的hashCode,使用ctypes模块简化处理逻辑。
import ctypes
def hashCode(value):
h = 0
for c in value:
h = ctypes.c_int32(31 * h + ord(c)).value
return h + 31
print("output:"+hashCode("helloworld"))
# output: -1524582881