(评论)
(comments)

原始链接: https://news.ycombinator.com/item?id=43931925

Hacker News上的讨论主要围绕“自适应哈希”(Adaptive Hashing)技术如何优化哈希表性能展开。评论员tptacek指出,“自适应哈希”这个术语以前曾用于像Bcrypt这样的算法,这些算法故意放慢哈希速度以增强安全性。这引发了关于目标相反的算法却共享相同名称的幽默讨论。 随后,谈话涉及到快速排序算法(Quicksort),这也是另一个例子,但鲜为人知。一位用户称赞了自适应哈希的实现,因为它消除了其代码中的性能hack。 一个关键点是,自适应哈希的实现仅使用字符串的前两个和后两个字符进行哈希,这并非理想。用户建议根据冲突率动态调整哈希字符数量,以提高哈希表增长时的质量。

相关文章
  • (评论) 2025-05-08
  • (评论) 2025-05-08
  • (评论) 2025-05-11
  • (评论) 2025-05-10
  • (评论) 2025-05-09

  • 原文
    Hacker News new | past | comments | ask | show | jobs | submit login
    Adaptive Hashing (quotenil.com)
    52 points by varjag 1 day ago | hide | past | favorite | 8 comments










    Fun fact! A previous use of the term "adaptive hash" was as a descriptor for things like Bcrypt, which have the exact opposite goal (to consistently be as slow as possible regardless of advances in hardware).


    So we just flip a sign in Bcrypt! Or flip a decision Boolean? Or a sort order?

    Regardless it will be easy. Apply the inverse operation of the “introduce more slowness” operation.

    Unfortunately, I have seen some software in my day, and I don’t think it will work. Just really perverse stuff.



    "tptacek's law: given enough time, diametrically opposed algorithms will have the same name"


    Yes! See: quicksort.


    Huh? What's the other "quicksort" ? Tony's famous Quicksort I'm aware of, and while you should not use this algorithm this century† in its pure form it's still in the core of good sorts, you just need other ingredients too.

    So what's the diametrically opposed algorithms with the same name ?

    † Don't tell C++ programmers, some of their standard libraries only stopped shipping quicksort as the default algorithm during the Biden administration.



    Let me comment as an SBCL user: This is outstanding work, and I can now remove a lot of performance hacks from my code because the default hash tables became equally fast!

    Also, this technique eliminates a number of worst-case scenarios and inefficiencies, which is a boon for any hash table user.



    > For string keys, hash only the first and last 2 characters. For list keys, only hash the first 4 elements.

    I would think it make some sense to change these constants as the collision chain grows, thereby improving the hash quality of keys and avoiding collisions as the table gets larger and larger



    > If too many collisions, double the limit.






    Consider applying for YC's Summer 2025 batch! Applications are open till May 13


    Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact



    Search:
    联系我们 contact @ memedata.com