List of usage examples for org.apache.lucene.util LongBitSet flip
public void flip(long startIndex, long endIndex)
From source file:org.apache.solr.legacy.TestLegacyNumericUtils.java
License:Apache License
/** Note: The neededBounds Iterable must be unsigned (easier understanding what's happening) */ private void assertLongRangeSplit(final long lower, final long upper, int precisionStep, final boolean useBitSet, final Iterable<Long> expectedBounds, final Iterable<Integer> expectedShifts) { // Cannot use FixedBitSet since the range could be long: final LongBitSet bits = useBitSet ? new LongBitSet(upper - lower + 1) : null; final Iterator<Long> neededBounds = (expectedBounds == null) ? null : expectedBounds.iterator(); final Iterator<Integer> neededShifts = (expectedShifts == null) ? null : expectedShifts.iterator(); LegacyNumericUtils.splitLongRange(new LegacyNumericUtils.LongRangeBuilder() { @Override/*w ww .j a va 2 s .co m*/ public void addRange(long min, long max, int shift) { assertTrue("min, max should be inside bounds", min >= lower && min <= upper && max >= lower && max <= upper); if (useBitSet) for (long l = min; l <= max; l++) { assertFalse("ranges should not overlap", bits.getAndSet(l - lower)); // extra exit condition to prevent overflow on MAX_VALUE if (l == max) break; } if (neededBounds == null || neededShifts == null) return; // make unsigned longs for easier display and understanding min ^= 0x8000000000000000L; max ^= 0x8000000000000000L; //System.out.println("0x"+Long.toHexString(min>>>shift)+"L,0x"+Long.toHexString(max>>>shift)+"L)/*shift="+shift+"*/,"); assertEquals("shift", neededShifts.next().intValue(), shift); assertEquals("inner min bound", neededBounds.next().longValue(), min >>> shift); assertEquals("inner max bound", neededBounds.next().longValue(), max >>> shift); } }, precisionStep, lower, upper); if (useBitSet) { // after flipping all bits in the range, the cardinality should be zero bits.flip(0, upper - lower + 1); assertEquals("The sub-range concenated should match the whole range", 0, bits.cardinality()); } }