您现在的位置是:主页 > news > 网站数据库怎么建/安卓优化大师历史版本

网站数据库怎么建/安卓优化大师历史版本

admin2025/5/1 1:35:44news

简介网站数据库怎么建,安卓优化大师历史版本,广平企业做网站推广,做网站后都需要什么Python中的built-in function ^{}主要用于对集合(如dict和set)中的键进行散列。或多或少,only required property是比较相等的对象必须具有相同的哈希值。 在Python的默认CPython实现中,对于类型为str、bytes或datetime的对象&…

网站数据库怎么建,安卓优化大师历史版本,广平企业做网站推广,做网站后都需要什么Python中的built-in function ^{}主要用于对集合(如dict和set)中的键进行散列。或多或少,only required property是比较相等的对象必须具有相同的哈希值。 在Python的默认CPython实现中,对于类型为str、bytes或datetime的对象&…

Python中的built-in function ^{}主要用于对集合(如dict和set)中的键进行散列。或多或少,only required property是比较相等的对象必须具有相同的哈希值。

在Python的默认CPython实现中,对于类型为str、bytes或datetime的对象,使用难以反转的散列函数(SipHash),并且使用散列随机化since Python 3.3来防止散列溢出攻击。这意味着散列在Python调用之间发生变化。因此,如果您试图反转hash()以使用该散列恢复字符串,请忘记它。

16>})。function used如下(暂时忽略负数):对于一个整数n,hash是由hash(n)=n mod p给出的,其中p是一个大素数sys.hash_info.modulus=261-1。

这被推广到所有有限有理数如下:对于一个有理数n=p/q,hash是hash(p/q)=(p/q)mod p,除法被解释为模p。换言之,如果p/q是最低形式(或至少去掉p的公共因子),则通过计算q mod p的逆得到hash(p/q),将其与p相乘,取结果的模p。

对于负数,hash(-n)=-hash(n)。

(关于特殊值有几个更详细的信息:如果n是浮点无穷大,或者如果q没有逆,即是p的倍数,则使用sys.hash_info.inf,如果n是NaN,则使用sys.hash_info.nan)。此外,hash值从不为-1。)

这使得反转这个hash函数成为一个很好的练习。对于给定的非负值h,其中0≤h<P整数n具有has h(n)=h,如果且仅当n mod p是h,即如果n的形式(h+kP)是某个整数k。

一个(IEEE 754 double-precision)浮点数,尾数为52位m,指数位为11位e,表示有理数

(252+m)/252×2e-1023

如果hash是h,那么我们有同余条件:

(252+m)(2e-1023-52)selecth mod p

(252+m)选择((21023+52-e)×h)mod p

m∏(21023+52-e×h-252)模式p

对m的唯一限制是0≤m<252。因此,对于e的211=2048个可能值中的每一个,我们可以计算相应的m,并验证它是否导致有效的浮点数。

所以这里有一个(Python 3)函数,对于给定的h产生所有int和float值n,这样hash(n)就是h。import sys

def invert(h):

if h == -1: return [] # -1 gets coerced to -2 so no value has hash -1

if h < 0:

sign = -1

h = -h

else:

sign = 1

M = sys.float_info.mant_dig - 1 # = 52 = Bits available for mantissa

E = (sys.float_info.max_exp - sys.float_info.min_exp + 1) # = 1023 = bias

B = sys.float_info.radix # = 2, base of the floating point values

P = sys.hash_info.modulus # = 2^61 - 1 = the prime used as hash modulus

if not (0 <= h == int(h) < P):

return []

for e in range((E + 1) * 2):

# Want m such that (B^M + m) * B^(e-M-E) = h mod P

m = (h * B**(M+E-e) - B**M) % P

if m >= B**M: continue # Happens with probability (1-B**M/P)

f = (B**M + m) * B**(e-M-E)

if f == int(f): continue # We'll see this later as an integer

assert hash(f) == h

yield sign * f

# Special values if any

if h == sys.hash_info.inf:

yield sign * float('inf')

if h == sys.hash_info.nan:

yield float('nan')

# Now the integers

k = 0

while True:

yield sign * (h + k * P)

k += 1

示例用法:num = 0

for n in invert(314159265):

print(hash(n), n)

num += 1

if num > 25: break

输出:314159265 2.1332628416727795e-304

314159265 4.918969210286518e-286

314159265 1.1342370766076572e-267

314159265 2.6153726338867434e-249

314159265 6.030638704336553e-231

314159265 1.390570609748797e-212

314159265 3.2064375193072873e-194

314159265 7.393541538375207e-176

314159265 1.7048346069593532e-157

314159265 3.9310809603228e-139

314159265 9.064455551013383e-121

314159265 2.0901211464632472e-102

314159265 4.81949123398199e-84

314159265 1.111299016984405e-65

314159265 2.5624810694595406e-47

314159265 5.908679060255712e-29

314159265 1.3624486304777972e-10

314159265 314159265

314159265 2305843009527853216

314159265 4611686018741547167

314159265 6917529027955241118

314159265 9223372037168935069

314159265 11529215046382629020

314159265 13835058055596322971

314159265 16140901064810016922

314159265 18446744074023710873

等等