Skip to content

Commit fc9a12f

Browse files
committed
Update hash32 primitive helper methods to refer to hash32x86.
Since the sign extension bug in hash32 is not relevant the javadoc can point to the hash32x86 implementation which does not have the bug. The result is the same. The unit tests have been updated to show this.
1 parent 7ade136 commit fc9a12f

2 files changed

Lines changed: 22 additions & 34 deletions

File tree

src/main/java/org/apache/commons/codec/digest/MurmurHash3.java

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,16 @@ private MurmurHash3() {
104104
* <pre>
105105
* int offset = 0;
106106
* int seed = 104729;
107-
* int hash = MurmurHash3.hash32(ByteBuffer.allocate(16)
108-
* .putLong(data1)
109-
* .putLong(data2)
110-
* .array(), offset, 16, seed);
107+
* int hash = MurmurHash3.hash32x86(ByteBuffer.allocate(16)
108+
* .putLong(data1)
109+
* .putLong(data2)
110+
* .array(), offset, 16, seed);
111111
* </pre>
112112
*
113-
* <p>Note: The sign extension bug in {@link #hash32(byte[], int, int, int)} does not affect
114-
* this result as there are no bytes left over from dividing the length by 4.<p>
115-
*
116113
* @param data1 The first long to hash
117114
* @param data2 The second long to hash
118115
* @return The 32-bit hash
119-
* @see #hash32(byte[], int, int, int)
116+
* @see #hash32x86(byte[], int, int, int)
120117
*/
121118
public static int hash32(final long data1, final long data2) {
122119
return hash32(data1, data2, DEFAULT_SEED);
@@ -128,20 +125,17 @@ public static int hash32(final long data1, final long data2) {
128125
*
129126
* <pre>
130127
* int offset = 0;
131-
* int hash = MurmurHash3.hash32(ByteBuffer.allocate(16)
132-
* .putLong(data1)
133-
* .putLong(data2)
134-
* .array(), offset, 16, seed);
128+
* int hash = MurmurHash3.hash32x86(ByteBuffer.allocate(16)
129+
* .putLong(data1)
130+
* .putLong(data2)
131+
* .array(), offset, 16, seed);
135132
* </pre>
136133
*
137-
* <p>Note: The sign extension bug in {@link #hash32(byte[], int, int, int)} does not affect
138-
* this result as there are no bytes left over from dividing the length by 4.<p>
139-
*
140134
* @param data1 The first long to hash
141135
* @param data2 The second long to hash
142136
* @param seed The initial seed value
143137
* @return The 32-bit hash
144-
* @see #hash32(byte[], int, int, int)
138+
* @see #hash32x86(byte[], int, int, int)
145139
*/
146140
public static int hash32(final long data1, final long data2, final int seed) {
147141
int hash = seed;
@@ -164,17 +158,14 @@ public static int hash32(final long data1, final long data2, final int seed) {
164158
* <pre>
165159
* int offset = 0;
166160
* int seed = 104729;
167-
* int hash = MurmurHash3.hash32(ByteBuffer.allocate(8)
168-
* .putLong(data)
169-
* .array(), offset, 8, seed);
161+
* int hash = MurmurHash3.hash32x86(ByteBuffer.allocate(8)
162+
* .putLong(data)
163+
* .array(), offset, 8, seed);
170164
* </pre>
171165
*
172-
* <p>Note: The sign extension bug in {@link #hash32(byte[], int, int, int)} does not affect
173-
* this result as there are no bytes left over from dividing the length by 4.<p>
174-
*
175166
* @param data The long to hash
176167
* @return The 32-bit hash
177-
* @see #hash32(byte[], int, int, int)
168+
* @see #hash32x86(byte[], int, int, int)
178169
*/
179170
public static int hash32(final long data) {
180171
return hash32(data, DEFAULT_SEED);
@@ -186,18 +177,15 @@ public static int hash32(final long data) {
186177
*
187178
* <pre>
188179
* int offset = 0;
189-
* int hash = MurmurHash3.hash32(ByteBuffer.allocate(8)
190-
* .putLong(data)
191-
* .array(), offset, 8, seed);
180+
* int hash = MurmurHash3.hash32x86(ByteBuffer.allocate(8)
181+
* .putLong(data)
182+
* .array(), offset, 8, seed);
192183
* </pre>
193184
*
194-
* <p>Note: The sign extension bug in {@link #hash32(byte[], int, int, int)} does not affect
195-
* this result as there are no bytes left over from dividing the length by 4.<p>
196-
*
197185
* @param data The long to hash
198186
* @param seed The initial seed value
199187
* @return The 32-bit hash
200-
* @see #hash32(byte[], int, int, int)
188+
* @see #hash32x86(byte[], int, int, int)
201189
*/
202190
public static int hash32(final long data, final int seed) {
203191
int hash = seed;

src/test/java/org/apache/commons/codec/digest/MurmurHash3Test.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public void testHash32LongLong() {
105105
for (final long j : data) {
106106
buffer.putLong(0, i);
107107
buffer.putLong(MurmurHash3.LONG_BYTES, j);
108-
Assert.assertEquals(MurmurHash3.hash32(bytes, offset, length, seed), MurmurHash3.hash32(i, j));
108+
Assert.assertEquals(MurmurHash3.hash32x86(bytes, offset, length, seed), MurmurHash3.hash32(i, j));
109109
}
110110
}
111111
}
@@ -127,7 +127,7 @@ public void testHash32LongLongSeed() {
127127
for (final long j : data) {
128128
buffer.putLong(0, i);
129129
buffer.putLong(MurmurHash3.LONG_BYTES, j);
130-
Assert.assertEquals(MurmurHash3.hash32(bytes, offset, length, seed), MurmurHash3.hash32(i, j, seed));
130+
Assert.assertEquals(MurmurHash3.hash32x86(bytes, offset, length, seed), MurmurHash3.hash32(i, j, seed));
131131
}
132132
}
133133
}
@@ -147,7 +147,7 @@ public void testHash32Long() {
147147
final long[] data = createLongTestData();
148148
for (final long i : data) {
149149
buffer.putLong(0, i);
150-
Assert.assertEquals(MurmurHash3.hash32(bytes, offset, length, seed), MurmurHash3.hash32(i));
150+
Assert.assertEquals(MurmurHash3.hash32x86(bytes, offset, length, seed), MurmurHash3.hash32(i));
151151
}
152152
}
153153

@@ -166,7 +166,7 @@ public void testHash32LongSeed() {
166166
final long[] data = createLongTestData();
167167
for (final long i : data) {
168168
buffer.putLong(0, i);
169-
Assert.assertEquals(MurmurHash3.hash32(bytes, offset, length, seed), MurmurHash3.hash32(i, seed));
169+
Assert.assertEquals(MurmurHash3.hash32x86(bytes, offset, length, seed), MurmurHash3.hash32(i, seed));
170170
}
171171
}
172172

0 commit comments

Comments
 (0)