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

@ -1,3 +1,13 @@
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.
2004-09-21 Andreas Tobler <a.tobler@schweiz.ch>
* javax/security/auth/x500/X500Principal.java: Fix some merge glitches.

View file

@ -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;
}
/**

View file

@ -297,11 +297,25 @@ public abstract class CharBuffer extends Buffer
/**
* Calculates a hash code for this buffer.
*
* This is done with int 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.
*/
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;
}
/**

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);
}
/**

View file

@ -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;
}
/**

View file

@ -243,11 +243,27 @@ public abstract class IntBuffer 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;
}
/**

View file

@ -243,11 +243,27 @@ public abstract class LongBuffer 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. 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);
}
/**

View file

@ -243,11 +243,27 @@ public abstract class ShortBuffer 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;
}
/**