@Test public void rotateEmptyBitSet() { BitSet bs = new BitSet(); BitSetMath.rotate(bs, 10, 1); Assert.assertTrue(bs.isEmpty()); BitSetMath.rotate(bs, 1, 10); Assert.assertTrue(bs.isEmpty()); BitSetMath.rotate(bs, 1, -10); Assert.assertTrue(bs.isEmpty()); BitSetMath.rotate(bs, 10, -1); Assert.assertTrue(bs.isEmpty()); BitSetMath.rotate(bs, 0, 10); Assert.assertTrue(bs.isEmpty()); BitSetMath.rotate(bs, 0, -10); Assert.assertTrue(bs.isEmpty()); BitSetMath.rotate(bs, 0, 0); Assert.assertTrue(bs.isEmpty()); }
public static void rotate(BitSet bs, int n, int count) { int gcd = MathUtils.gcd(n, count); if (gcd != 0) { if (gcd == n) { return; } int m = n / gcd; for (int i = 0; i < gcd; ++i) { boolean previous = bs.get(i); int jTimesCount = 0; for (int j = 1; j <= m; ++j) { jTimesCount += count; int index = i - jTimesCount % n; if (index < 0) { index += n; } boolean current = bs.get(index); if (previous ^ current) { bs.set(index, previous); previous = current; } assert (j < m) ^ (jTimesCount % n == 0); } } } }
BitSetMath { public static void rotate(BitSet bs, int n, int count) { int gcd = MathUtils.gcd(n, count); if (gcd != 0) { if (gcd == n) { return; } int m = n / gcd; for (int i = 0; i < gcd; ++i) { boolean previous = bs.get(i); int jTimesCount = 0; for (int j = 1; j <= m; ++j) { jTimesCount += count; int index = i - jTimesCount % n; if (index < 0) { index += n; } boolean current = bs.get(index); if (previous ^ current) { bs.set(index, previous); previous = current; } assert (j < m) ^ (jTimesCount % n == 0); } } } } }
BitSetMath { public static void rotate(BitSet bs, int n, int count) { int gcd = MathUtils.gcd(n, count); if (gcd != 0) { if (gcd == n) { return; } int m = n / gcd; for (int i = 0; i < gcd; ++i) { boolean previous = bs.get(i); int jTimesCount = 0; for (int j = 1; j <= m; ++j) { jTimesCount += count; int index = i - jTimesCount % n; if (index < 0) { index += n; } boolean current = bs.get(index); if (previous ^ current) { bs.set(index, previous); previous = current; } assert (j < m) ^ (jTimesCount % n == 0); } } } } private  BitSetMath(); }
BitSetMath { public static void rotate(BitSet bs, int n, int count) { int gcd = MathUtils.gcd(n, count); if (gcd != 0) { if (gcd == n) { return; } int m = n / gcd; for (int i = 0; i < gcd; ++i) { boolean previous = bs.get(i); int jTimesCount = 0; for (int j = 1; j <= m; ++j) { jTimesCount += count; int index = i - jTimesCount % n; if (index < 0) { index += n; } boolean current = bs.get(index); if (previous ^ current) { bs.set(index, previous); previous = current; } assert (j < m) ^ (jTimesCount % n == 0); } } } } private  BitSetMath(); static int increment(BitSet i); static void rotate(BitSet bs, int n, int count); static void extractBitRange(BitSet chi, int from, int to, BitSet r); static void grayCode(BitSet i); static void grayCodeInverse(BitSet i); static void copy(BitSet from, BitSet to); static long littleEndianBitSetToNonNegativeLong(BitSet bs); static void nonNegativeLongToLittleEndianBitSet(long value, BitSet bs); }
BitSetMath { public static void rotate(BitSet bs, int n, int count) { int gcd = MathUtils.gcd(n, count); if (gcd != 0) { if (gcd == n) { return; } int m = n / gcd; for (int i = 0; i < gcd; ++i) { boolean previous = bs.get(i); int jTimesCount = 0; for (int j = 1; j <= m; ++j) { jTimesCount += count; int index = i - jTimesCount % n; if (index < 0) { index += n; } boolean current = bs.get(index); if (previous ^ current) { bs.set(index, previous); previous = current; } assert (j < m) ^ (jTimesCount % n == 0); } } } } private  BitSetMath(); static int increment(BitSet i); static void rotate(BitSet bs, int n, int count); static void extractBitRange(BitSet chi, int from, int to, BitSet r); static void grayCode(BitSet i); static void grayCodeInverse(BitSet i); static void copy(BitSet from, BitSet to); static long littleEndianBitSetToNonNegativeLong(BitSet bs); static void nonNegativeLongToLittleEndianBitSet(long value, BitSet bs);  }