在Java中打破了一倍 [英] Hash a double in Java
问题描述
我想知道有关如何解决这个问题的任何想法。希望放弃我的哈希码的其余部分,这个类有两个?
我想知道是否有问题,我试图排列数组列表,数组和其他java中的对象我的一些类包含数组列表。
非常感谢
a href =http://docs.oracle.com/javase/7/docs/api/java/lang/Double.html#hashCode%28%29> Double.hashCode()
复杂?它基本上将 double
转换为 long
(这里没有魔法,毕竟他们都只是内存中的64位值)和计算 long
哈希很简单。 double
- > long
转换是通过 public static doubleToLongBits()
。什么是复杂的?
示例:
Double.valueOf (42.5).hashCode(); //更好地回答一切
Long.valueOf(Double.doubleToLongBits(42.5))。hashCode();
I was wondering how to hash a double in Java? I have hashed other primitive data and objects. I thought I could use the hashcode method? From what I have seen this looks quite complex. I came across something about creating a seed.
I was wondering any ideas on how to go about this. Hoping to put in with the rest of my hashcode for the class that has the double?
I was wondering if there are issues with me trying to hash arraylists, arrays and other objects in java. Some of my classes contain arraylists.
Many Thanks
Double.hashCode()
complex? It basically converts double
into a long
(no magic here, after all they both are simply 64-bit values in memory) and computing long
hash is quite simple. The double
-> long
conversion is done via public static doubleToLongBits()
. What is complex about this?
Examples:
Double.valueOf(42.5).hashCode(); //better answer to everything
Long.valueOf(Double.doubleToLongBits(42.5)).hashCode();
这篇关于在Java中打破了一倍的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!