English 中文(简体)
这是否适当利用了植树功能?
原标题:Is this an appropriate use of python s built-in hash function?

我需要比较高质量的数据,以便平等。 我需要比较一下每秒钟的很多奶粉。 每一物体的长度相同,可能而且可能只在不知的位置上略有不同。

Timings below show that using == operator is very fast if there is a difference near the start of the data, and significantly slower if differences are located towards the end.

>>> import os
>>> s = os.urandom(1600*1200 - 1)
>>> Aimg = b"A" + s
>>> Bimg = b"B" + s
>>> img1 = s + b"1"
>>> img2 = s + b"2"
>>> %timeit Aimg == Bimg
61.8 ns ± 0.484 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
>>> %timeit img1 == img2
159 µs ± 2.83 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)

在我使用的情况下,差异可能位于中间或末端的斜线上(案文:这是不压缩的形象数据)。 我寻找一种办法,加快使用洗衣或制片。 使用md5的速度较慢,但沙尔建筑在<代码>hash上确实加快了事情。

>>> %timeit img1 == img2
160 µs ± 5.96 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)
>>> %timeit hash(img1) == hash(img2) and img1 == img2
236 ns ± 5.91 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

对该散列的技术细节感兴趣的是,在<代码>hash(a)=h(b)时,<代码>a = b 是 极有可能<>? 如果散射碰撞是相当少见的,则法尔阳性反应是可以接受的,其意图是加快对平均案例的比较。

最佳回答

灰色洗.功能的设计是为了速度,将地图绘制成64倍的空间。 由于birthday 悖,这意味着你有可能在大约50亿个条目上发生碰撞(可能是较早的,因为散射功能不是密码)。 此外,<代码>hash的准确定义可上至于实施,可以是结构的,也可以是特定机器的。 不要使用它,你想要的是多种机器的同样结果。

md5是作为加密的散射功能设计的;即使输入中略有扰动,产出也完全改变。 它还把128个轨道空间地图上,除非你特别寻找一个空间,否则你不可能完全发生碰撞。

如果你能够处理碰撞(即,对所有成员在桶内平等进行测试,可能的话,采用像MD5或SHA2这样的加密算法,那么,斯达尔赫功能是完全严厉的。

还有一点: 为节约空间,如果你把数据写到磁盘上,你就应当以双亲形式储存。 (i.e. struct. Pack ( !q , hash (abc )hashlib.md5(abc ).digest()。

作为副注:is 等于=。 页: 1

问题回答

暂无回答




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签