使用字符串类型的键存储哈希值的最佳结构

发布于 2025-01-04 13:48:51 字数 311 浏览 4 评论 0原文

我是哈希领域的初学者。我正在编写一个程序来索引字符串键。为此,我对 varachar(512) 键的前 3 个字符进行哈希处理,然后获取数字形式的哈希值。我打算使用该数值来索引我的数据。我允许发生冲突,也就是说,如果两个字符串的前三个字符相同,那么它们可能具有相同的哈希值。

现在,如果某个查询要查找特定的字符串键,我将首先对其进行哈希处理,然后在查找表中查找其哈希值。

我需要为此目的存储一个查找表吗?或者我可以动态计算它的哈希值然后执行搜索吗?

如果是的话,如果我们考虑性能和优化作为主要标准,哪种结构会更好,我正在使用 C++。

谢谢你!

I am beginner in the field of hash. I am writing a program to index string keys. For that, I hash the first 3 characters of my varachar(512) key and then get the hashed value in numeric form. I intend to index my data using that numeric value. I allow collisions to occur, that is if two strings have their first three characters same, then they might have same hash value.

Now if some query comes to look for particular string key, i will first hash it and will look in the lookup table that what's its hash value.

Do i need to store a look up table for this purpose? or can i just dynamically calculate it's hash value and then perform search?

If yes, which structure would be good if we consider performance and optimization as the main criteria, I am using C++.

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

与往事干杯 2025-01-11 13:48:51

STL 已经有了 unordered_map 并且您可以将它与用户定义的类型和自定义哈希函数一起使用。

STL already has unordered_map and you can use it with user-defined types and custom hash functions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文