用于非加密用途的最快散列? [英] Fastest hash for non-cryptographic uses?

查看:160
本文介绍了用于非加密用途的最快散列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我基本上准备要放入数据库的短语,它们可能格式不正确,所以我想存储一个短的哈希值(我将简单比较,如果他们存在或不,所以哈希是理想的)。

I'm essentially preparing phrases to be put into the database, they may be malformed so I want to store a short hash of them instead (I will be simply comparing if they exist or not, so hash is ideal).

我假设MD5在100,000+个请求上相当缓慢,所以我想知道什么是最好的方法来哈希短语,也许推出自己的哈希函数或使用 hash('md4','...'到底会更快吗?

I assume MD5 is fairly slow on 100,000+ requests so I wanted to know what would be the best method to hash the phrases, maybe rolling out my own hash function or using hash('md4', '...' would be faster in the end?

(),所以这将补充一点速度的查询结束,但也许还有一个更快的散列函数在MySQL我不知道那将使用PHP ..

I know MySQL has MD5(), so that would complement a bit of speed on the query end, but maybe there's further a faster hashing function in MySQL I don't know about that would work with PHP..

推荐答案

CRC32速度非常快,有一个函数: http://www.php.net/manual/en/function.crc32.php

CRC32 is pretty fast and there's a function for it: http://www.php.net/manual/en/function.crc32.php

但你应该知道CRC32将具有比MD5或甚至SHA-1哈希更多的冲突,这仅仅是因为减少的长度(32比特相比于128比特或160比特)。但是如果你只是想检查一个存储的字符串是否损坏,你会很好的CRC32。

But you should be aware that CRC32 will have more collisions than MD5 or even SHA-1 hashes, simply because of the reduced length (32 bits compared to 128 bits respectively 160 bits). But if you just want to check whether a stored string is corrupted, you'll be fine with CRC32.

这篇关于用于非加密用途的最快散列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆