Index: java/nio/ByteBuffer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/nio/ByteBuffer.java,v
retrieving revision 1.22
diff -u -r1.22 ByteBuffer.java
--- java/nio/ByteBuffer.java 13 Aug 2004 23:41:47 -0000 1.22
+++ java/nio/ByteBuffer.java 16 Sep 2004 12:02:03 -0000
@@ -260,11 +260,27 @@
/**
* Calculates a hash code for this buffer.
+ *
+ * This is done with int
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. 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;
}
/**
Index: java/nio/CharBuffer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/nio/CharBuffer.java,v
retrieving revision 1.22
diff -u -r1.22 CharBuffer.java
--- java/nio/CharBuffer.java 13 Aug 2004 23:41:47 -0000 1.22
+++ java/nio/CharBuffer.java 16 Sep 2004 12:02:03 -0000
@@ -297,11 +297,25 @@
/**
* Calculates a hash code for this buffer.
+ *
+ * This is done with int 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. Note that the hashcode is dependent
+ * on buffer content, and therefore is not useful if the buffer
+ * content may change.
*/
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;
}
/**
Index: java/nio/DoubleBuffer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/nio/DoubleBuffer.java,v
retrieving revision 1.17
diff -u -r1.17 DoubleBuffer.java
--- java/nio/DoubleBuffer.java 13 Aug 2004 23:41:47 -0000 1.17
+++ java/nio/DoubleBuffer.java 16 Sep 2004 12:02:04 -0000
@@ -243,11 +243,27 @@
/**
* 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);
}
/**
Index: java/nio/FloatBuffer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/nio/FloatBuffer.java,v
retrieving revision 1.17
diff -u -r1.17 FloatBuffer.java
--- java/nio/FloatBuffer.java 13 Aug 2004 23:41:47 -0000 1.17
+++ java/nio/FloatBuffer.java 16 Sep 2004 12:02:04 -0000
@@ -243,11 +243,27 @@
/**
* Calculates a hash code for this buffer.
+ *
+ * This is done with int
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 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;
}
/**
Index: java/nio/IntBuffer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/nio/IntBuffer.java,v
retrieving revision 1.17
diff -u -r1.17 IntBuffer.java
--- java/nio/IntBuffer.java 13 Aug 2004 23:41:47 -0000 1.17
+++ java/nio/IntBuffer.java 16 Sep 2004 12:02:04 -0000
@@ -243,11 +243,27 @@
/**
* Calculates a hash code for this buffer.
+ *
+ * This is done with int
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. 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;
}
/**
Index: java/nio/LongBuffer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/nio/LongBuffer.java,v
retrieving revision 1.17
diff -u -r1.17 LongBuffer.java
--- java/nio/LongBuffer.java 13 Aug 2004 23:41:47 -0000 1.17
+++ java/nio/LongBuffer.java 16 Sep 2004 12:02:04 -0000
@@ -243,11 +243,27 @@
/**
* 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. 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 = get(position()) + 31;
+ long multiplier = 1;
+ for (int i = position()+1; i < limit(); i++)
+ {
+ multiplier *= 31;
+ hashCode += (get(i) + 30)*multiplier;
+ }
+ return ((int)hashCode);
}
/**
Index: java/nio/ShortBuffer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/nio/ShortBuffer.java,v
retrieving revision 1.18
diff -u -r1.18 ShortBuffer.java
--- java/nio/ShortBuffer.java 13 Aug 2004 23:41:47 -0000 1.18
+++ java/nio/ShortBuffer.java 16 Sep 2004 12:02:04 -0000
@@ -243,11 +243,27 @@
/**
* Calculates a hash code for this buffer.
+ *
+ * This is done with int
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. 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;
}
/**