Skip to content

Commit

Permalink
Merge a408ea1 into 9b09cb3
Browse files Browse the repository at this point in the history
  • Loading branch information
kazuki-ma committed Nov 14, 2019
2 parents 9b09cb3 + a408ea1 commit ea7933d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/apache/datasketches/HashOperations.java
Expand Up @@ -50,7 +50,7 @@ private HashOperations() {}
public static int countPart(final long[] srcArr, final int lgArrLongs, final long thetaLong) {
int cnt = 0;
final int len = 1 << lgArrLongs;
for (int i = len; i-- > 0;) {
for (int i = len - 1; i >= 0; i--) {
final long hash = srcArr[i];
if (continueCondition(thetaLong, hash) ) {
continue;
Expand All @@ -69,7 +69,7 @@ public static int countPart(final long[] srcArr, final int lgArrLongs, final lon
public static int count(final long[] srcArr, final long thetaLong) {
int cnt = 0;
final int len = srcArr.length;
for (int i = len; i-- > 0;) {
for (int i = len - 1; i >= 0; i--) {
final long hash = srcArr[i];
if (continueCondition(thetaLong, hash) ) {
continue;
Expand Down
Expand Up @@ -136,14 +136,14 @@ void keepOnlyPositiveCounts() {
// firstProbe keeps track of this point.
// When we find the next non-empty cell, we know we are at the high end of a cluster
// Work towards the front; delete any non-positive entries.
for (int probe = firstProbe; probe-- > 0;) {
for (int probe = firstProbe - 1; probe >= 0; probe--) {
if (states[probe] > 0 && values[probe] <= 0) {
hashDelete(probe); //does the work of deletion and moving higher items towards the front.
numActive--;
}
}
//now work on the first cluster that was skipped.
for (int probe = states.length; probe-- > firstProbe;) {
for (int probe = states.length - 1; probe >= firstProbe; probe--) {
if (states[probe] > 0 && values[probe] <= 0) {
hashDelete(probe);
numActive--;
Expand All @@ -156,7 +156,7 @@ void keepOnlyPositiveCounts() {
* values are retained.
*/
void adjustAllValuesBy(final long adjustAmount) {
for (int i = values.length; i-- > 0;) {
for (int i = values.length - 1; i >= 0; i--) {
values[i] += adjustAmount;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/apache/datasketches/hash/MurmurHash3.java
Expand Up @@ -321,7 +321,7 @@ private static long mixK2(long k2) {
*/
private static long getLong(final byte[] bArr, final int index, final int rem) {
long out = 0L;
for (int i = rem; i-- > 0;) { //i= 7,6,5,4,3,2,1,0
for (int i = rem - 1; i >= 0; i--) { //i= 7,6,5,4,3,2,1,0
final byte b = bArr[index + i];
out ^= (b & 0xFFL) << (i * 8); //equivalent to |=
}
Expand All @@ -340,7 +340,7 @@ private static long getLong(final byte[] bArr, final int index, final int rem) {
*/
private static long getLong(final char[] charArr, final int index, final int rem) {
long out = 0L;
for (int i = rem; i-- > 0;) { //i= 3,2,1,0
for (int i = rem - 1; i >= 0; i--) { //i= 3,2,1,0
final char c = charArr[index + i];
out ^= (c & 0xFFFFL) << (i * 16); //equivalent to |=
}
Expand All @@ -359,7 +359,7 @@ private static long getLong(final char[] charArr, final int index, final int rem
*/
private static long getLong(final int[] intArr, final int index, final int rem) {
long out = 0L;
for (int i = rem; i-- > 0;) { //i= 1,0
for (int i = rem - 1; i >= 0; i--) { //i= 1,0
final int v = intArr[index + i];
out ^= (v & 0xFFFFFFFFL) << (i * 32); //equivalent to |=
}
Expand Down
Expand Up @@ -39,7 +39,7 @@ public class MurmurHash3AdaptorTest {
@Test
public void checkToBytesLong() {
byte[] result = hashToBytes(2L, 0L);
for (int i = 8; i-- > 0;) {
for (int i = 0; i < 8; i++) {
Assert.assertNotEquals(result[i], 0);
}
}
Expand All @@ -48,7 +48,7 @@ public void checkToBytesLong() {
public void checkToBytesLongArr() {
long[] arr = { 1L, 2L };
byte[] result = hashToBytes(arr, 0L);
for (int i = 8; i-- > 0;) {
for (int i = 0; i < 8; i++) {
Assert.assertNotEquals(result[i], 0);
}
arr = null;
Expand All @@ -64,7 +64,7 @@ public void checkToBytesLongArr() {
public void checkToBytesIntArr() {
int[] arr = { 1, 2 };
byte[] result = hashToBytes(arr, 0L);
for (int i = 8; i-- > 0;) {
for (int i = 0; i < 8; i++) {
Assert.assertNotEquals(result[i], 0);
}
arr = null;
Expand All @@ -80,7 +80,7 @@ public void checkToBytesIntArr() {
public void checkToBytesCharArr() {
char[] arr = { 1, 2 };
byte[] result = hashToBytes(arr, 0L);
for (int i = 8; i-- > 0;) {
for (int i = 0; i < 8; i++) {
Assert.assertNotEquals(result[i], 0);
}
arr = null;
Expand All @@ -96,7 +96,7 @@ public void checkToBytesCharArr() {
public void checkToBytesByteArr() {
byte[] arr = { 1, 2 };
byte[] result = hashToBytes(arr, 0L);
for (int i = 8; i-- > 0;) {
for (int i = 0; i < 8; i++) {
Assert.assertNotEquals(result[i], 0);
}
arr = null;
Expand All @@ -112,23 +112,23 @@ public void checkToBytesByteArr() {
@Test
public void checkToBytesDouble() {
byte[] result = hashToBytes(1.0, 0L);
for (int i = 8; i-- > 0;) {
for (int i = 0; i < 8; i++) {
Assert.assertNotEquals(result[i], 0);
}
result = hashToBytes(0.0, 0L);
for (int i = 8; i-- > 0;) {
for (int i = 0; i < 8; i++) {
Assert.assertNotEquals(result[i], 0);
}
result = hashToBytes( -0.0, 0L);
for (int i = 8; i-- > 0;) {
for (int i = 0; i < 8; i++) {
Assert.assertNotEquals(result[i], 0);
}
}

@Test
public void checkToBytesString() {
byte[] result = hashToBytes("1", 0L);
for (int i = 8; i-- > 0;) {
for (int i = 0; i < 8; i++) {
Assert.assertNotEquals(result[i], 0);
}
result = hashToBytes("", 0L);
Expand All @@ -144,7 +144,7 @@ public void checkToBytesString() {
@Test
public void checkToLongsLong() {
long[] result = hashToLongs(2L, 0L);
for (int i = 2; i-- > 0;) {
for (int i = 0; i < 2; i++) {
Assert.assertNotEquals(result[i], 0);
}
}
Expand All @@ -153,7 +153,7 @@ public void checkToLongsLong() {
public void checkToLongsLongArr() {
long[] arr = { 1L, 2L };
long[] result = hashToLongs(arr, 0L);
for (int i = 2; i-- > 0;) {
for (int i = 0; i < 2; i++) {
Assert.assertNotEquals(result[i], 0);
}
arr = null;
Expand All @@ -169,7 +169,7 @@ public void checkToLongsLongArr() {
public void checkToLongsIntArr() {
int[] arr = { 1, 2 };
long[] result = hashToLongs(arr, 0L);
for (int i = 2; i-- > 0;) {
for (int i = 0; i < 2; i++) {
Assert.assertNotEquals(result[i], 0);
}
arr = null;
Expand All @@ -185,7 +185,7 @@ public void checkToLongsIntArr() {
public void checkToLongsCharArr() {
char[] arr = { 1, 2 };
long[] result = hashToLongs(arr, 0L);
for (int i = 2; i-- > 0;) {
for (int i = 0; i < 2; i++) {
Assert.assertNotEquals(result[i], 0);
}
arr = null;
Expand All @@ -201,7 +201,7 @@ public void checkToLongsCharArr() {
public void checkToLongsByteArr() {
byte[] arr = { 1, 2 };
long[] result = hashToLongs(arr, 0L);
for (int i = 2; i-- > 0;) {
for (int i = 0; i < 2; i++) {
Assert.assertNotEquals(result[i], 0);
}
arr = null;
Expand All @@ -217,23 +217,23 @@ public void checkToLongsByteArr() {
@Test
public void checkToLongsDouble() {
long[] result = hashToLongs(1.0, 0L);
for (int i = 2; i-- > 0;) {
for (int i = 0; i < 2; i++) {
Assert.assertNotEquals(result[i], 0);
}
result = hashToLongs(0.0, 0L);
for (int i = 2; i-- > 0;) {
for (int i = 0; i < 2; i++) {
Assert.assertNotEquals(result[i], 0);
}
result = hashToLongs( -0.0, 0L);
for (int i = 2; i-- > 0;) {
for (int i = 0; i < 2; i++) {
Assert.assertNotEquals(result[i], 0);
}
}

@Test
public void checkToLongsString() {
long[] result = hashToLongs("1", 0L);
for (int i = 2; i-- > 0;) {
for (int i = 0; i < 2; i++) {
Assert.assertNotEquals(result[i], 0);
}
result = hashToLongs("", 0L);
Expand All @@ -248,7 +248,7 @@ public void checkToLongsString() {
@Test
public void checkModulo() {
int div = 7;
for (int i = 20; i-- > 0;) {
for (int i = 20; i > 0; i--) {
long[] out = hashToLongs(i, 9001);
int mod = modulo(out[0], out[1], div);
Assert.assertTrue((mod < div) && (mod >= 0));
Expand Down

0 comments on commit ea7933d

Please sign in to comment.