Perl 的完美哈希函数(如 gperf)?
我将使用键:值存储并希望在 Perl 中创建不可碰撞的哈希值。是否有 Perl 模块或函数可以用来生成不可碰撞的哈希函数或表(可能类似于
I'm going to be using a key:value store and would like to create non-collidable hashes in Perl. Is there a Perl module, or function that I can use to generate a non-collidable hash function or table (maybe something like gperf)? I already know my range of input values.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找不到纯粹的 Perl 解决方案,最接近的是 Reini Urban 的考试在类型系统中使用完美哈希。如果您要在 XS 中执行此操作,CMPH(C 最小完美哈希库) 可能比 gperf 更合适。 CMPH 似乎针对重要的密钥大小和运行时生成进行了优化。
在 Perl 中运行时生成完美哈希函数的成本可能会淹没使用它的价值。为了获得好处,您需要对其进行编译和缓存。因此,编写一个在 XS 编译时从固定键列表生成函数的 XS 模块可能是最好的方法。
出于好奇,您的数据有多大以及该集合包含多少个键?
I can't find a pure Perl solution, closest is Reini Urban's examinations of using perfect hashes with a type system. If you were to do it in XS, the CMPH (C Minimal Perfect Hashing Library) might be more apropos than gperf. CMPH seems to be optimized for non-trivial key sizes and run-time generation.
The cost of generating a perfect hash function at runtime in Perl might swamp the value of using it. In order to gain benefit, you'd want it compiled and cached. So again, writing an XS module which generates the function from a fixed key list at XS compile time might be the best way to go.
Out of curiosity, how big is your data and how many keys does the set contain?
您可能对朱迪感兴趣。它不是一个哈希表实现,但它被认为是一个非常有效的关联数组实现。
请注意,Perl 的哈希值经过很好的调整,当存储桶开始变大时,它们会自动重新哈希。
You might be interested in Judy. It's not a hash table implementation, but it's supposedly a very efficient associative array implementation.
Mind you, Perl's hashes are very well tuned, and they automatically get rehashed when a bucket starts growing large.