]> gcc.gnu.org Git - gcc.git/commitdiff
ByteBuffer.java (hashCode): Implemented.
authorSven de Marothy <sven@physto.se>
Tue, 21 Sep 2004 13:50:13 +0000 (15:50 +0200)
committerAndreas Tobler <andreast@gcc.gnu.org>
Tue, 21 Sep 2004 13:50:13 +0000 (15:50 +0200)
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

libjava/ChangeLog
libjava/java/nio/ByteBuffer.java
libjava/java/nio/CharBuffer.java
libjava/java/nio/DoubleBuffer.java
libjava/java/nio/FloatBuffer.java
libjava/java/nio/IntBuffer.java
libjava/java/nio/LongBuffer.java
libjava/java/nio/ShortBuffer.java

index e32ff8c4fbeff92b0587761de40b796223a0fa3a..c27d6ee96bb56a62037e4bba9c714d284bd44d30 100644 (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.
index 378e58827fa08328ed9857f78cb706c5ea9be6f3..e502e003199476d8c2eb2bfd3d7019f13f2fbb66 100644 (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;
   }
 
   /**
index 4ef257bed68380dc81191795e6741aa887b8ca66..700c56750f3a57a215128c568a67754a95322bf4 100644 (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;
   }
 
   /**
index 10055cd08d93cc9adb6d2ba1ebddb5fe9f9d6d70..dd16ee0496205ca87c2a398f9b85a4a06becfc2b 100644 (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);
   }
 
   /**
index 6d19503525f7ceb8e50c524de4b5eebebdc5027b..2ead8cbc494c8644bd1bff06b5c635ef5443f3b0 100644 (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;
   }
 
   /**
index 68a71db3b53c748f5ebe7dc3c865a4ad514e34f4..814e0414bc6cee4261c2e6a5717fd531fc153731 100644 (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;
   }
 
   /**
index c4066b1d30bca3c839212c7e17d0ca5d69edb13a..6e9ef34e8eb269e7ed43c144edd6a5ad4cd3b046 100644 (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);
   }
 
   /**
index 083039101e4e8152e7ca14af16d97e54524c8f2b..db03076b6291c5fb2b2a6f15f6416d4e0c1a29fb 100644 (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;
   }
 
   /**
This page took 0.082657 seconds and 5 git commands to generate.