From 62e8d0c9c16b08f9adf9649b5e72cb13ea2bbdf6 Mon Sep 17 00:00:00 2001 From: andreast Date: Tue, 21 Sep 2004 13:50:13 +0000 Subject: 2004-09-21 Sven de Marothy * java/nio/ByteBuffer.java (hashCode): Implemented. * java/nio/CharBuffer.java: Likewise. * java/nio/DoubleBuffer.java: Likewise. * java/nio/FloatBuffer.java: Likewise. * java/nio/LongBuffer.java: Likewise. * java/nio/IntBuffer.java: Likewise. * java/nio/ShortBuffer.java: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@87804 138bc75d-0d04-0410-961f-82ee72b054a4 --- libjava/java/nio/DoubleBuffer.java | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'libjava/java/nio/DoubleBuffer.java') diff --git a/libjava/java/nio/DoubleBuffer.java b/libjava/java/nio/DoubleBuffer.java index 10055cd08d9..dd16ee04962 100644 --- a/libjava/java/nio/DoubleBuffer.java +++ b/libjava/java/nio/DoubleBuffer.java @@ -243,11 +243,27 @@ public abstract class DoubleBuffer extends Buffer /** * Calculates a hash code for this buffer. + * + * This is done with long arithmetic, + * where ** represents exponentiation, by this formula:
+ * s[position()] + 31 + (s[position()+1] + 30)*31**1 + ... + + * (s[limit()-1]+30)*31**(limit()-1). + * Where s is the buffer data, in Double.doubleToLongBits() form + * Note that the hashcode is dependent on buffer content, + * and therefore is not useful if the buffer content may change. + * + * @return the hash code (casted to int) */ public int hashCode () { - // FIXME: Check what SUN calculates here. - return super.hashCode (); + long hashCode = Double.doubleToLongBits(get(position())) + 31; + long multiplier = 1; + for (int i = position() + 1; i < limit(); ++i) + { + multiplier *= 31; + hashCode += (Double.doubleToLongBits(get(i)) + 30)*multiplier; + } + return ((int)hashCode); } /** -- cgit v1.2.3