Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6586631
Votes 0
Synopsis Use toLongArray in the specification of BitSet.hashCode
Category java:classes_util
Reported Against
Release Fixed 7(b20), 6-open(b01) (Bug ID:2152592)
State 10-Fix Delivered, bug
Priority: 3-Medium
Related Bugs
Submit Date 29-JUL-2007
Description
BitSet.hashCode()'s slightly bizarre specification can be made more normal
by using the new public toLongArray method.


     /**
-     * Returns a hash code value for this bit set. The hash code
-     * depends only on which bits have been set within this
-     * {@code BitSet}. The algorithm used to compute it may
-     * be described as follows.
-     *
-     * <p>Suppose the bits in the {@code BitSet} were to be stored
-     * in an array of {@code long} integers called, say,
-     * {@code words}, in such a manner that bit {@code k} is
-     * set in the {@code BitSet} (for nonnegative values of
-     * {@code k}) if and only if the expression
-     * <pre>{@code ((k>>6) < words.length) && ((words[k>>6] & (1L << (bit & 0x3F))) != 0)}</pre>
-     * is true. Then the following definition of the {@code hashCode}
-     * method would be a correct implementation of the actual algorithm:
+     * Returns the hash code value for this bit set. The hash code depends
+     * only on which bits are set within this {@code BitSet}.
+     *
+     * <p>The hash code is defined to be the result of the following
+     * calculation:
      *  <pre> {@code
      * public int hashCode() {
      *      long h = 1234;
-     *      for (int i = words.length; --i >= 0; ) {
+     *     long[] words = toLongArray();
+     *     for (int i = words.length; --i >= 0; )
      *           h ^= words[i] * (i + 1);
-     *      }
      *      return (int)((h >> 32) ^ h);
      * }}</pre>
-     * Note that the hash code values change if the set of bits is altered.
+     * Note that the hash code changes if the set of bits is altered.
      *
-     * @return a hash code value for this bit set
+     * @return the hash code value for this bit set
      */
     public int hashCode() {
Posted Date : 2007-07-29 22:01:44.0

BitSet.hashCode()'s slightly bizarre specification can be made more normal
by using the new public toLongArray method.


     /**
-     * Returns a hash code value for this bit set. The hash code
-     * depends only on which bits have been set within this
-     * {@code BitSet}. The algorithm used to compute it may
-     * be described as follows.
-     *
-     * <p>Suppose the bits in the {@code BitSet} were to be stored
-     * in an array of {@code long} integers called, say,
-     * {@code words}, in such a manner that bit {@code k} is
-     * set in the {@code BitSet} (for nonnegative values of
-     * {@code k}) if and only if the expression
-     * <pre>{@code ((k>>6) < words.length) && ((words[k>>6] & (1L << (bit & 0x3F))) != 0)}</pre>
-     * is true. Then the following definition of the {@code hashCode}
-     * method would be a correct implementation of the actual algorithm:
+     * Returns the hash code value for this bit set. The hash code depends
+     * only on which bits are set within this {@code BitSet}.
+     *
+     * <p>The hash code is defined to be the result of the following
+     * calculation:
      *  <pre> {@code
      * public int hashCode() {
      *      long h = 1234;
-     *      for (int i = words.length; --i >= 0; ) {
+     *     long[] words = toLongArray();
+     *     for (int i = words.length; --i >= 0; )
      *           h ^= words[i] * (i + 1);
-     *      }
      *      return (int)((h >> 32) ^ h);
      * }}</pre>
-     * Note that the hash code values change if the set of bits is altered.
+     * Note that the hash code changes if the set of bits is altered.
      *
-     * @return a hash code value for this bit set
+     * @return the hash code value for this bit set
      */
     public int hashCode() {
Posted Date : 2007-07-29 22:01:44.0
Work Around
N/A
Evaluation
A fine idea.
Posted Date : 2007-07-29 22:01:44.0
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang