Changed SubArrayMinTest to use Integer.bitCount

This changes SubArrayMinTest to use the library method Integer.bitCount rather than a hand-rolled bit counting implementation.
This commit is contained in:
Bill Jacobs
2016-06-24 14:46:37 -07:00
parent 91b5ae633a
commit 5e23bd9c81
2 changed files with 1 additions and 6 deletions

View File

@@ -27,12 +27,7 @@ public class SubArrayMinTest {
sam = new SubArrayMin();
for (int i = 0; i < 1000; i++) {
// Taken from http://stackoverflow.com/a/109025
int value1 = i - ((i >>> 1) & 0x55555555);
int value2 = (value1 & 0x33333333) + ((value1 >>> 2) & 0x33333333);
int setBitCount = (((value2 + (value2 >>> 4)) & 0x0f0f0f0f) * 0x01010101) >>> 24;
sam.add(-setBitCount);
sam.add(-Integer.bitCount(i));
}
assertEquals(0, sam.min(0, 1));
assertEquals(-4, sam.min(0, 30));