private static long getHashCode ( Object key ) { // identityHashCode of two objects are not guaranteed to be different. // Any additional identity information can reduce collisions. // In the most cases below, we use size of an object to be the extra identity. // Experiments show that with 100 million objects created, using identityHashCode has a collision rate around 2.5%. // However, if these 100 million objects are combined with 10 different sizes, the collision rate is around 0.1%. // The collision rate can be lower than 0.001% if there are 1000 different sizes. int extraIdentity ; if ( key == null ) { extraIdentity = 0 ; } else if ( key instanceof Block ) { extraIdentity = ( int ) ( ( Block ) key ) . getRetainedSizeInBytes ( ) ; } else if ( key instanceof Slice ) { extraIdentity = ( int ) ( ( Slice ) key ) . getRetainedSize ( ) ; } else if ( key . getClass ( ) . isArray ( ) ) { extraIdentity = getLength ( key ) ; } else if ( key instanceof AbstractMapBlock . HashTables ) { extraIdentity = ( int ) ( ( AbstractMapBlock . HashTables ) key ) . getRetainedSizeInBytes ( ) ; } else { throw new IllegalArgumentException ( format ( "Unsupported type for %s" , key ) ) ; } return ( ( ( long ) System . identityHashCode ( key ) ) << Integer . SIZE ) + extraIdentity ; }
Get the 64 - bit hash code for an object