@Test public void split() { final int n = 5; BitVector[] actual = new BitVector[3]; for (int i = 0; i < n; ++i) { actual[0] = BitVectorFactories.OPTIMAL.apply(i); for (int j = 0; j < n; ++j) { actual[1] = BitVectorFactories.OPTIMAL.apply(j); for (int k = 0; k < n; ++k) { actual[2] = BitVectorFactories.OPTIMAL.apply(k); for (int x = 1; x < 1 << (i + j + k); ++x) { BitVector xAsBitVector = TestUtils.createBitVector(x, i + j + k); BitVectorMath.split(xAsBitVector, actual); Assert.assertEquals(TestUtils.createBitVector(x >> (j + k), i), actual[0]); Assert.assertEquals(TestUtils.createBitVector( (x & ((1 << (j + k)) - (1 << k))) >>> k, j), actual[1]); Assert.assertEquals(TestUtils.createBitVector(x & ((1 << k) - 1), k), actual[2]); } } } } }
public static void split(BitVector bs, BitVector[] result) { int sum = 0; for (BitVector bv : result) { sum += bv.size(); } Preconditions.checkArgument(sum == bs.size(), "size sum does not match"); int startIndex = 0; for (int i = result.length; --i >= 0; ) { result[i].copyFromSection(bs, startIndex); startIndex += result[i].size(); } Preconditions.checkArgument(startIndex >= bs.length(), "bit length is too high"); }
BitVectorMath { public static void split(BitVector bs, BitVector[] result) { int sum = 0; for (BitVector bv : result) { sum += bv.size(); } Preconditions.checkArgument(sum == bs.size(), "size sum does not match"); int startIndex = 0; for (int i = result.length; --i >= 0; ) { result[i].copyFromSection(bs, startIndex); startIndex += result[i].size(); } Preconditions.checkArgument(startIndex >= bs.length(), "bit length is too high"); } }
BitVectorMath { public static void split(BitVector bs, BitVector[] result) { int sum = 0; for (BitVector bv : result) { sum += bv.size(); } Preconditions.checkArgument(sum == bs.size(), "size sum does not match"); int startIndex = 0; for (int i = result.length; --i >= 0; ) { result[i].copyFromSection(bs, startIndex); startIndex += result[i].size(); } Preconditions.checkArgument(startIndex >= bs.length(), "bit length is too high"); } private  BitVectorMath(); }
BitVectorMath { public static void split(BitVector bs, BitVector[] result) { int sum = 0; for (BitVector bv : result) { sum += bv.size(); } Preconditions.checkArgument(sum == bs.size(), "size sum does not match"); int startIndex = 0; for (int i = result.length; --i >= 0; ) { result[i].copyFromSection(bs, startIndex); startIndex += result[i].size(); } Preconditions.checkArgument(startIndex >= bs.length(), "bit length is too high"); } private  BitVectorMath(); static void split(BitVector bs, BitVector[] result); }
BitVectorMath { public static void split(BitVector bs, BitVector[] result) { int sum = 0; for (BitVector bv : result) { sum += bv.size(); } Preconditions.checkArgument(sum == bs.size(), "size sum does not match"); int startIndex = 0; for (int i = result.length; --i >= 0; ) { result[i].copyFromSection(bs, startIndex); startIndex += result[i].size(); } Preconditions.checkArgument(startIndex >= bs.length(), "bit length is too high"); } private  BitVectorMath(); static void split(BitVector bs, BitVector[] result);  }