-
Bug
-
Resolution: Fixed
-
P3
-
7
-
b20
-
generic
-
generic
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2152592 | OpenJDK6 | Martin Buchholz | P3 | Resolved | Fixed | b01 |
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() {
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() {
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() {
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() {
- backported by
-
JDK-2152592 Use toLongArray in the specification of BitSet.hashCode
-
- Resolved
-
- relates to
-
JDK-8323286 BitSet hashCode never changes when setting bit 127 % 128
-
- Closed
-