Skip to content

Use static hashCode() methods #353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions gencsource.sh
Original file line number Diff line number Diff line change
Expand Up @@ -874,17 +874,17 @@ $(if [[ "${CLASS[$k]}" != "" && "${CLASS[$v]}" != "" ]]; then\
"#else\n"\
\
"#if KEY_CLASS_Float\n"\
"#define KEY2JAVAHASH_NOT_NULL(x) it.unimi.dsi.fastutil.HashCommon.float2int(x)\n"\
"#define KEY2INTHASH(x) it.unimi.dsi.fastutil.HashCommon.mix( it.unimi.dsi.fastutil.HashCommon.float2int(x) )\n"\
"#define KEY2LONGHASH(x) it.unimi.dsi.fastutil.HashCommon.mix( (long)( it.unimi.dsi.fastutil.HashCommon.float2int(x) ) )\n"\
"#define KEY2JAVAHASH_NOT_NULL(x) Float.hashCode(x)\n"\
"#define KEY2INTHASH(x) it.unimi.dsi.fastutil.HashCommon.mix( Float.hashCode(x) )\n"\
"#define KEY2LONGHASH(x) it.unimi.dsi.fastutil.HashCommon.mix( (long)( Float.hashCode(x) ) )\n"\
"#define INT(x) (x)\n"\
"#elif KEY_CLASS_Double\n"\
"#define KEY2JAVAHASH_NOT_NULL(x) it.unimi.dsi.fastutil.HashCommon.double2int(x)\n"\
"#define KEY2INTHASH(x) (int)it.unimi.dsi.fastutil.HashCommon.mix( Double.doubleToRawLongBits(x) )\n"\
"#define KEY2LONGHASH(x) it.unimi.dsi.fastutil.HashCommon.mix( Double.doubleToRawLongBits(x) )\n"\
"#define KEY2JAVAHASH_NOT_NULL(x) Double.hashCode(x)\n"\
"#define KEY2INTHASH(x) (int)it.unimi.dsi.fastutil.HashCommon.mix( Double.doubleToLongBits(x) )\n"\
"#define KEY2LONGHASH(x) it.unimi.dsi.fastutil.HashCommon.mix( Double.doubleToLongBits(x) )\n"\
"#define INT(x) (int)(x)\n"\
"#elif KEY_CLASS_Long\n"\
"#define KEY2JAVAHASH_NOT_NULL(x) it.unimi.dsi.fastutil.HashCommon.long2int(x)\n"\
"#define KEY2JAVAHASH_NOT_NULL(x) Long.hashCode(x)\n"\
"#define KEY2INTHASH(x) (int)it.unimi.dsi.fastutil.HashCommon.mix( (x) )\n"\
"#define KEY2LONGHASH(x) it.unimi.dsi.fastutil.HashCommon.mix( (x) )\n"\
"#define INT(x) (int)(x)\n"\
Expand Down Expand Up @@ -936,7 +936,7 @@ $(if [[ "${CLASS[$k]}" != "" && "${CLASS[$v]}" != "" ]]; then\
\
"#if VALUE_CLASS_Float || VALUE_CLASS_Double || VALUE_CLASS_Long\n"\
"#define VALUE_NULL (0)\n"\
"#define VALUE2JAVAHASH(x) it.unimi.dsi.fastutil.HashCommon.${TYPE[$v]}2int(x)\n"\
"#define VALUE2JAVAHASH(x) ${TYPE_CAP[$v]}.hashCode(x)\n"\
"#elif VALUE_CLASS_Boolean\n"\
"#define VALUE_NULL (false)\n"\
"#define VALUE2JAVAHASH(x) (x ? 1231 : 1237)\n"\
Expand Down
15 changes: 9 additions & 6 deletions src/it/unimi/dsi/fastutil/HashCommon.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,30 +123,33 @@ public static long invMix(long x) {
*
* @param f a float.
* @return the same code as {@link Float#hashCode() new Float(f).hashCode()}.
* @deprecated Use {@link Float#hashCode(float)} instead.
*/

@Deprecated
public static int float2int(final float f) {
return Float.floatToRawIntBits(f);
return Float.hashCode(f);
}

/** Returns the hash code that would be returned by {@link Double#hashCode()}.
*
* @param d a double.
* @return the same code as {@link Double#hashCode() new Double(f).hashCode()}.
* @deprecated Use {@link Double#hashCode(double)} instead.
*/

@Deprecated
public static int double2int(final double d) {
final long l = Double.doubleToRawLongBits(d);
return (int)(l ^ (l >>> 32));
return Double.hashCode(d);
}

/** Returns the hash code that would be returned by {@link Long#hashCode()}.
*
* @param l a long.
* @return the same code as {@link Long#hashCode() new Long(f).hashCode()}.
* @deprecated Use {@link Long#hashCode(long)} instead.
*/
@Deprecated
public static int long2int(final long l) {
return (int)(l ^ (l >>> 32));
return Long.hashCode(l);
}

/** Returns the least power of two greater than or equal to the specified value.
Expand Down