哪个更快:“基数树”或“b树”

发布于 2024-09-15 13:34:24 字数 75 浏览 5 评论 0原文

对于处理语言,如常规字典单词,基数树或常规 B 树哪个读取速度更快?有没有更快的方法,例如带有 Bucket & 的字典?散列?

For processing language, as in regular dictionary words, which would be faster at reading, a radix tree, or a regular b-tree? Is there a faster method, such as a dictionary with buckets & hashing?

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

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

发布评论

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

评论(1

简单 2024-09-22 13:34:24

与往常一样,您需要在应用程序上下文中进行基准测试才能确定。

然而,我预计在这种情况下,实现良好的哈希表可能会被证明是最快的。这基本上需要:

  • 一次扫描字符串以计算哈希值,通常使用非常快速的操作,例如位移位/异或
  • 一次基于哈希值的哈希表查找
  • 一次字符串比较以确认您拥有正确的单词
  • 一些额外的处理存在哈希冲突的情况 - 但是您可以调整哈希表大小以最小化这种情况。

基数树也会非常快,由于需要遍历多个级别的树节点,因此只会有一点额外的开销。如果您的树相对稀疏,则查找可能只需要向下进行少量级别即可找到唯一的答案。基数树的一个优点是,如果没有可能的匹配项,它会很早就告诉您(例如,以“qq”开头的树的空分支)

二叉树可能是最慢的,因为它平均需要搜索通过相当多级别的树节点。然而对于大多数用途来说它仍然足够快。

As always, you will need to benchmark in your application context to be sure.

However, I expect that in this case a well-implemented hash table will probably prove to be fastest. This basically requires:

  • One scan through the string to calculate the hash value, typically using very fast operations such as bit shifting / XORs
  • One hash table lookup based on the hash value
  • One string comparison to confirm you have the right word
  • A little extra processing in the case that there is a hash collision - however you can tune your hashtable size to minimise this

A radix tree will also be very fast, there is just a little bit of extra overhead due to the need to traverse multiple levels of tree nodes. If your tree is relatively sparse, it's likely that may lookups will only need to go down a small number of levels to find a unique answer. One advantage of the radix tree is that it will tell you very early if you have no possible matches (e.g. an empty branch for the tree starting with "qq")

A binary tree will probably be the slowest since it will on average have to search through quite a few levels of tree nodes. However it will still be fast enough for most purposes.

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