zpxshl
V2EX  ›  问与答

1.7 的 hashmap 在扩容时为什么需要重新计算 entry.hash 呢?

  •  
  •   zpxshl · Aug 3, 2021 · 1210 views
    This topic created in 1746 days ago, the information mentioned may be changed or developed.

    网上讲 1.7 和 1.8 的区别都会说到这里,但是不管 1.7 和 1.8,entry.hash 都是固定的(和 length 无关),为什么 1.7 在扩容时需要重新计算呢? 另外网上的文章还讲到,1.8 做了一个优化,通过判断 hash 的第 n 位是 0 是 1,决定扩容后的位置。但是 1.7 直接 hash & (length -1) 得出扩容位置,也没啥区别呀,都是一个&操作...

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3026 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 06:45 · PVG 14:45 · LAX 23:45 · JFK 02:45
    ♥ Do have faith in what you're doing.