使用 gperf 生成的完美哈希函数安全吗?
我现在正在考虑使用 gperf 生成的哈希函数来替换我们的旧函数,但我不知道它是否安全,以及这是否会增加我们的维护成本。
可靠性和系统复杂性是我们首先考虑的因素。
有人在大型项目中使用过 gperf 生成的哈希函数吗?
在我的项目中使用它安全吗?
顺便说一句,我们的项目是一个 C++ 项目,运行在 64 位 Linux 机器上。
提前致谢!
I'm now considering using gperf generated hash function to replace our old one, but I had no idea if it's safe or not, and will that add our maintaining cost.
The reliability and system complexity is our first consideration.
Is there someone who had used gperf generated hash function in big project?
Is safe to use it in my project?
BTW, our project is a C++ project, runs on a 64-bit Linux machine.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我自己从来不需要使用 API,但是,
在 这篇 文章中,似乎是 90 年代末,他们表明 GPERF 已用于 TAO、gnu 缩进和少数其他应用程序。
它已经发布了一段时间,并且很可能会被彻底淘汰。
这是一篇有趣的开发人员作品文章。
Never had to use the API myself, but,
in this write-up, which seems to be from the late 90s, they show that GPERF has been used in TAO, gnu indent, and a handful of other applications.
It's been out for a while, and likely to be well shaken out.
Here's an interesting developer works writeup.
众所周知,gperf 工作得非常好。就目前而言,是的,它是“安全的”。
复杂性通常约为读取 2 个字符、进行 2 次表查找和 1 次字符串比较。可靠性为100%。如果出现问题,您会收到一条错误消息,否则它将起作用。
维护成本在“低”和“不存在”之间,您需要弄清楚如何编写输入文件一次,然后通过gperf运行它一次,并编译它。这是每个 10-20 岁的编译器都能理解的简单 C 代码。每当你想查找一个值时,调用查找函数即可,这就是所有要做的事情。
如果您更改它,您将需要再次通过 gperf 运行输入文件,显然......否则就是这样。如果您的按键列表没有改变,您就不需要再做任何事情。我已经在几个项目中使用了 gperf,并且非常满意。
gperf is known to work very well. Insofar, yes it is "safe".
Complexity is usually on the order of reading 2 characters, doing 2 table lookups, and one string compare. Reliability is 100%. If something went wrong, you get an error message, otherwise it will work.
Maintenance cost is between "low" and "non-existen", you need to figure out how to write the input file once, then run it through gperf once, and compile it. It's simple C code that every 10-20 year old compiler can grok. Call the lookup function whenever you want to lookup a value, that's all there is to do.
You'll need to run the input file through gperf again if you change it, obviously... otherwise that's just it. If your list of keys does not change, you never need to do anything again. I've used gperf in several projects to full satisfaction.