diff options
author | Sven de Marothy <sven@physto.se> | 2004-09-21 15:50:13 +0200 |
---|---|---|
committer | Andreas Tobler <andreast@gcc.gnu.org> | 2004-09-21 15:50:13 +0200 |
commit | 9413382eec489236a06827e7dbff33975b249bb1 (patch) | |
tree | adb823d7896f1493d35bab1cf7e20fb7b557415c /libjava/java/nio/FloatBuffer.java | |
parent | c6847e25b997c686563a537de5fb9eaa34568730 (diff) | |
download | gcc-9413382eec489236a06827e7dbff33975b249bb1.zip gcc-9413382eec489236a06827e7dbff33975b249bb1.tar.gz gcc-9413382eec489236a06827e7dbff33975b249bb1.tar.bz2 |
ByteBuffer.java (hashCode): Implemented.
2004-09-21 Sven de Marothy <sven@physto.se>
* 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.
From-SVN: r87804
Diffstat (limited to 'libjava/java/nio/FloatBuffer.java')
-rw-r--r-- | libjava/java/nio/FloatBuffer.java | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/libjava/java/nio/FloatBuffer.java b/libjava/java/nio/FloatBuffer.java index 6d19503..2ead8cb 100644 --- a/libjava/java/nio/FloatBuffer.java +++ b/libjava/java/nio/FloatBuffer.java @@ -243,11 +243,27 @@ public abstract class FloatBuffer extends Buffer /** * Calculates a hash code for this buffer. + * + * This is done with <code>int</code> arithmetic, + * where ** represents exponentiation, by this formula:<br> + * <code>s[position()] + 31 + (s[position()+1] + 30)*31**1 + ... + + * (s[limit()-1]+30)*31**(limit()-1)</code>. + * Where s is the buffer data, in Float.floatToIntBits() 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 */ public int hashCode () { - // FIXME: Check what SUN calculates here. - return super.hashCode (); + int hashCode = Float.floatToIntBits(get(position())) + 31; + int multiplier = 1; + for (int i = position() + 1; i < limit(); ++i) + { + multiplier *= 31; + hashCode += (Float.floatToIntBits(get(i)) + 30)*multiplier; + } + return hashCode; } /** |