c字符串比较vs哈希比较 [英] c string compare vs hash compare

查看:90
本文介绍了c字符串比较vs哈希比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要比较一个字符串到c中的多个其他常量字符串。我很好奇,这是更快,哈希字符串我要比较,并将其与所有其他常量字符串哈希或比较字符串作为字符串。先谢谢你

I need to compare a string to multiple other constant strings in c. I am curious which is faster, to hash the string I am going to compare and compare it to all the other constant string hashes or just compare the strings as strings. thank you in advance

谢谢你的答案我要做很多比较。任何人都可以给我一个好的,快速,低资源密集的算法使用?我知道的唯一哈希是MD5,我有一种感觉是过度杀死。

thank you for the answers I am going to be doing many comparisons. can anyone give me a good, fast, low resource intensive algorithm to use? The only hash I know of is MD5 and I have a feeling that is over kill.

我还想补充说,字符串可能是20或30个字符长在最大为7左右。

I also want to add that the strings are maybe 20 or 30 characters long at the max with most being around 7.

推荐答案

比较是一次还是多次?如果比较只做一次,那么你最好做一个直接的比较。如果你需要将很多字符串与这组常量字符串进行比较,那么你可以通过使用哈希值来节省时间。

Is the comparison going to be done once or many times? If the comparison is going to be done only once then you are likely better off doing a straight comparison. If you are going to need to compare very many strings to this set of constant strings, then you can probably save time in the long run by doing it with hashes.

是一个简单的问题,你可以很容易地写两个方式,看看哪些工作更好的一组代表性的输入。

This is a simple enough problem that you can easily write it both ways and see which works better for a representative set of input.

这篇关于c字符串比较vs哈希比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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