PatchSet 5179 
Date: 2004/09/17 19:28:08
Author: dalibor
Branch: HEAD
Tag: (none) 
Log:
resynced with GNU Classpath: Implemented hashCode for nio buffers

2004-09-17  Dalibor Topic  <[EMAIL PROTECTED]>

        * libraries/javalib/java/nio/ByteBuffer.java,
        libraries/javalib/java/nio/CharBuffer.java,
        libraries/javalib/java/nio/DoubleBuffer.java,
        libraries/javalib/java/nio/FloatBuffer.java,
        libraries/javalib/java/nio/IntBuffer.java,
        libraries/javalib/java/nio/LongBuffer.java,
        libraries/javalib/java/nio/ShortBuffer.java:
        Resynced with GNU Classpath.

        2004-09-17  Sven de Marothy <[EMAIL PROTECTED]>

        * java/nio/ByteBuffer.java:
        (hashCode): Implemented.
        * java/nio/CharBuffer.java:
        * java/nio/DoubleBuffer.java:
        * java/nio/FloatBuffer.java:
        * java/nio/LongBuffer.java:
        * java/nio/IntBuffer.java:
        * java/nio/ShortBuffer.java:
        Likewise.

Members: 
        ChangeLog:1.2734->1.2735 
        libraries/javalib/java/nio/ByteBuffer.java:1.12->1.13 
        libraries/javalib/java/nio/CharBuffer.java:1.12->1.13 
        libraries/javalib/java/nio/DoubleBuffer.java:1.10->1.11 
        libraries/javalib/java/nio/FloatBuffer.java:1.10->1.11 
        libraries/javalib/java/nio/IntBuffer.java:1.10->1.11 
        libraries/javalib/java/nio/LongBuffer.java:1.10->1.11 
        libraries/javalib/java/nio/ShortBuffer.java:1.10->1.11 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2734 kaffe/ChangeLog:1.2735
--- kaffe/ChangeLog:1.2734      Fri Sep 17 18:48:38 2004
+++ kaffe/ChangeLog     Fri Sep 17 19:28:08 2004
@@ -1,3 +1,26 @@
+2004-09-17  Dalibor Topic  <[EMAIL PROTECTED]>
+
+       * libraries/javalib/java/nio/ByteBuffer.java,
+       libraries/javalib/java/nio/CharBuffer.java,
+       libraries/javalib/java/nio/DoubleBuffer.java,
+       libraries/javalib/java/nio/FloatBuffer.java,
+       libraries/javalib/java/nio/IntBuffer.java,
+       libraries/javalib/java/nio/LongBuffer.java,
+       libraries/javalib/java/nio/ShortBuffer.java:
+       Resynced with GNU Classpath.
+
+       2004-09-17  Sven de Marothy <[EMAIL PROTECTED]>
+
+        * java/nio/ByteBuffer.java:
+        (hashCode): Implemented.
+        * java/nio/CharBuffer.java:
+        * java/nio/DoubleBuffer.java:
+        * java/nio/FloatBuffer.java:
+        * java/nio/LongBuffer.java:
+        * java/nio/IntBuffer.java:
+        * java/nio/ShortBuffer.java:
+        Likewise.
+
 2004-09-17  Michael Franz <[EMAIL PROTECTED]>,
            Timothy S. Stack <[EMAIL PROTECTED]>
 
Index: kaffe/libraries/javalib/java/nio/ByteBuffer.java
diff -u kaffe/libraries/javalib/java/nio/ByteBuffer.java:1.12 
kaffe/libraries/javalib/java/nio/ByteBuffer.java:1.13
--- kaffe/libraries/javalib/java/nio/ByteBuffer.java:1.12       Sat Aug 14 17:32:07 
2004
+++ kaffe/libraries/javalib/java/nio/ByteBuffer.java    Fri Sep 17 19:28:10 2004
@@ -260,11 +260,27 @@
 
   /**
    * 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: kaffe/libraries/javalib/java/nio/CharBuffer.java
diff -u kaffe/libraries/javalib/java/nio/CharBuffer.java:1.12 
kaffe/libraries/javalib/java/nio/CharBuffer.java:1.13
--- kaffe/libraries/javalib/java/nio/CharBuffer.java:1.12       Sat Aug 14 17:59:28 
2004
+++ kaffe/libraries/javalib/java/nio/CharBuffer.java    Fri Sep 17 19:28:10 2004
@@ -297,11 +297,25 @@
 
   /**
    * 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: kaffe/libraries/javalib/java/nio/DoubleBuffer.java
diff -u kaffe/libraries/javalib/java/nio/DoubleBuffer.java:1.10 
kaffe/libraries/javalib/java/nio/DoubleBuffer.java:1.11
--- kaffe/libraries/javalib/java/nio/DoubleBuffer.java:1.10     Sat Aug 14 17:59:28 
2004
+++ kaffe/libraries/javalib/java/nio/DoubleBuffer.java  Fri Sep 17 19:28:11 2004
@@ -243,11 +243,27 @@
 
   /**
    * 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: kaffe/libraries/javalib/java/nio/FloatBuffer.java
diff -u kaffe/libraries/javalib/java/nio/FloatBuffer.java:1.10 
kaffe/libraries/javalib/java/nio/FloatBuffer.java:1.11
--- kaffe/libraries/javalib/java/nio/FloatBuffer.java:1.10      Sat Aug 14 17:59:28 
2004
+++ kaffe/libraries/javalib/java/nio/FloatBuffer.java   Fri Sep 17 19:28:11 2004
@@ -243,11 +243,27 @@
 
   /**
    * 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: kaffe/libraries/javalib/java/nio/IntBuffer.java
diff -u kaffe/libraries/javalib/java/nio/IntBuffer.java:1.10 
kaffe/libraries/javalib/java/nio/IntBuffer.java:1.11
--- kaffe/libraries/javalib/java/nio/IntBuffer.java:1.10        Sat Aug 14 17:59:28 
2004
+++ kaffe/libraries/javalib/java/nio/IntBuffer.java     Fri Sep 17 19:28:11 2004
@@ -243,11 +243,27 @@
 
   /**
    * 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: kaffe/libraries/javalib/java/nio/LongBuffer.java
diff -u kaffe/libraries/javalib/java/nio/LongBuffer.java:1.10 
kaffe/libraries/javalib/java/nio/LongBuffer.java:1.11
--- kaffe/libraries/javalib/java/nio/LongBuffer.java:1.10       Sat Aug 14 17:59:28 
2004
+++ kaffe/libraries/javalib/java/nio/LongBuffer.java    Fri Sep 17 19:28:11 2004
@@ -243,11 +243,27 @@
 
   /**
    * 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: kaffe/libraries/javalib/java/nio/ShortBuffer.java
diff -u kaffe/libraries/javalib/java/nio/ShortBuffer.java:1.10 
kaffe/libraries/javalib/java/nio/ShortBuffer.java:1.11
--- kaffe/libraries/javalib/java/nio/ShortBuffer.java:1.10      Sat Aug 14 17:59:28 
2004
+++ kaffe/libraries/javalib/java/nio/ShortBuffer.java   Fri Sep 17 19:28:11 2004
@@ -243,11 +243,27 @@
 
   /**
    * 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;
   }
 
   /**

_______________________________________________
kaffe mailing list
[EMAIL PROTECTED]
http://kaffe.org/cgi-bin/mailman/listinfo/kaffe

Reply via email to