summaryrefslogtreecommitdiffstats
path: root/libjava/java/nio/ByteBuffer.java
diff options
context:
space:
mode:
authorandreast <andreast@138bc75d-0d04-0410-961f-82ee72b054a4>2004-09-21 13:50:13 +0000
committerandreast <andreast@138bc75d-0d04-0410-961f-82ee72b054a4>2004-09-21 13:50:13 +0000
commit62e8d0c9c16b08f9adf9649b5e72cb13ea2bbdf6 (patch)
treeadb823d7896f1493d35bab1cf7e20fb7b557415c /libjava/java/nio/ByteBuffer.java
parent2b573e698aa85c2c56a05e9657d12eeac27acf69 (diff)
downloadppe42-gcc-62e8d0c9c16b08f9adf9649b5e72cb13ea2bbdf6.tar.gz
ppe42-gcc-62e8d0c9c16b08f9adf9649b5e72cb13ea2bbdf6.zip
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@87804 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/java/nio/ByteBuffer.java')
-rw-r--r--libjava/java/nio/ByteBuffer.java20
1 files changed, 18 insertions, 2 deletions
diff --git a/libjava/java/nio/ByteBuffer.java b/libjava/java/nio/ByteBuffer.java
index 378e58827fa..e502e003199 100644
--- a/libjava/java/nio/ByteBuffer.java
+++ b/libjava/java/nio/ByteBuffer.java
@@ -260,11 +260,27 @@ public abstract class ByteBuffer 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. 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 = get(position()) + 31;
+ int multiplier = 1;
+ for (int i = position() + 1; i < limit(); ++i)
+ {
+ multiplier *= 31;
+ hashCode += (get(i) + 30)*multiplier;
+ }
+ return hashCode;
}
/**
OpenPOWER on IntegriCloud