Changes to HashMap after Android 5.0

Source: Internet
Author: User

Previously found on Android 5.0 on the machine on the hashmap inside the data removed and the Android 5.0 under the same machine, resulting in an interface problem in the project (the interface is cached, the request parameter order changes will result in some data can not be taken), Then went to check the Android 5.0 and Android 4.4 about HashMap source, use meld to see the differences can see sure Google to HashMap implementation has been modified.

Android 5.0 source on the left, Android 4.4 on the right






As you can see from the source, Android 5.0 uses the following algorithm to calculate key hashcode.

    private static int Secondaryhash (int h) {        //Spread bits to regularize both segment and index locations,        //using Variant of Single-word wang/jenkins hash.        H + = (h << +  ) ^ 0xffffcd7d;        H ^= (h >>>);        H + = (h <<   3);        H ^= (H >>>  6);        H + = (h <<   2) + (h << +);        Return h ^ (h >>>);    }

The hashcode algorithm for computing key in Android 4.4 is obviously different from Android 5.0, so this also results in a different order of the same data on both systems after get. If there is a sequential need for stored data, then the TreeMap built with the red-black tree will be OK.

    static int Secondaryhash (Object key) {        int hash = Key.hashcode ();        Hash ^= (hash >>>) ^ (hash >>>);        Hash ^= (Hash >>> 7) ^ (hash >>> 4);        return hash;    }


Reprint Please specify source: http://blog.csdn.net/l2show/article/details/46970507


Changes to HashMap after Android 5.0

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.