Git Product home page Git Product logo

Comments (1)

Dcwjh avatar Dcwjh commented on May 17, 2024

丙哥,读了你的HashMap.md感觉收获满满,不过有两个地方我想提一下:

  1. 文中 “因为在使用不是2的幂的数字的时候,Length-1的值是所有二进制位全为1,这种情况下,index的结果等同于HashCode后几位的值。”一句中应该是“是2的幂”,Length-1才会全是1吧。
  2. “只要输入的HashCode本身分布均匀,Hash算法的结果就是均匀的。” 这里我觉得可以加上HashMap源码中对hashCode值的一个操作。
    源码中对key的hash方法:
static final int hash(Object key) {
        int h;
        return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);
    }

其中将原32位hashcode与其右移16位后的结果做了异或,为了让高16位也参与到“让hashcode分布更均匀”中,这样更能让hashcode分布均匀吧。
(第一次提issue,如有不妥,望丙哥告知🤓

好巧,我也注意到这个点了。

from javafamily.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.