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
This commit is contained in:
Sven de Marothy 2004-09-21 15:50:13 +02:00 committed by Andreas Tobler
parent c6847e25b9
commit 9413382eec
8 changed files with 134 additions and 14 deletions

View file

@ -243,11 +243,27 @@ public abstract class DoubleBuffer extends Buffer
/**
* Calculates a hash code for this buffer.
*
* This is done with <code>long</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 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);
}
/**