整型和浮点型生成hashcode策略

xiaoxiao2021-02-27  148

/** * boolean */ public static int getBooleanHashCode(boolean f) { return f ? 1 : 0; } /** * byte、char、short、int */ public static int getToIntHashCode(int f) { return f; } /** * long */ public static int getLongHashCode(long f) { return (int) (f ^ (f >>> 32)); } /** * float */ public static int getFloatHashCode(float f) { return Float.floatToIntBits(f); } /** * double */ public static int getDoubleHashCode(double d) { return getLongHashCode(Double.doubleToLongBits(d)); }
转载请注明原文地址: https://www.6miu.com/read-13271.html

最新回复(0)