public void testEnsureCapacity_fail() { try { Bytes.ensureCapacity(ARRAY1, -1, 1); fail(); } catch (IllegalArgumentException expected) { } try { // notice that this should even fail when no growth was needed Bytes.ensureCapacity(ARRAY1, 1, -1); fail(); } catch (IllegalArgumentException expected) { } }
public void testEnsureCapacity() { assertSame(EMPTY, Bytes.ensureCapacity(EMPTY, 0, 1)); assertSame(ARRAY1, Bytes.ensureCapacity(ARRAY1, 0, 1)); assertSame(ARRAY1, Bytes.ensureCapacity(ARRAY1, 1, 1)); assertTrue( Arrays.equals( new byte[] {(byte) 1, (byte) 0, (byte) 0}, Bytes.ensureCapacity(ARRAY1, 2, 1))); }
public void testEnsureCapacity() { assertSame(EMPTY, Bytes.ensureCapacity(EMPTY, 0, 1)); assertSame(ARRAY1, Bytes.ensureCapacity(ARRAY1, 0, 1)); assertSame(ARRAY1, Bytes.ensureCapacity(ARRAY1, 1, 1)); assertTrue(Arrays.equals( new byte[] {(byte) 1, (byte) 0, (byte) 0}, Bytes.ensureCapacity(ARRAY1, 2, 1))); }
public void testEnsureCapacity_fail() { try { Bytes.ensureCapacity(ARRAY1, -1, 1); fail(); } catch (IllegalArgumentException expected) { } try { // notice that this should even fail when no growth was needed Bytes.ensureCapacity(ARRAY1, 1, -1); fail(); } catch (IllegalArgumentException expected) { } }
overflowValues = Bytes.ensureCapacity(overflowValues, overflows + 1, OVERFLOW_GROW_INCREMENT);
overflowValues = Bytes.ensureCapacity(overflowValues, overflows + 1, OVERFLOW_GROW_INCREMENT);
public void insert(int bucket, int value) { int delta = value - baseline; final int oldDelta = getDelta(bucket); if (delta <= oldDelta || (oldDelta == MAX_DELTA && (delta <= oldDelta + getOverflow(bucket)))) { // the old bucket value is (baseline + oldDelta) + possibly an overflow, so it's guaranteed to be >= the new value return; } if (delta > MAX_DELTA) { int overflow = delta - MAX_DELTA; if (!setOverflow(bucket, overflow)) { // grow overflows arrays if necessary overflowBuckets = Ints.ensureCapacity(overflowBuckets, overflows + 1, OVERFLOW_GROW_INCREMENT); overflowValues = Bytes.ensureCapacity(overflowValues, overflows + 1, OVERFLOW_GROW_INCREMENT); overflowBuckets[overflows] = bucket; overflowValues[overflows] = (byte) overflow; overflows++; } delta = MAX_DELTA; } setDelta(bucket, delta); if (oldDelta == 0) { --baselineCount; adjustBaselineIfNeeded(); } }
public void insert(int bucket, int value) { int delta = value - baseline; final int oldDelta = getDelta(bucket); if (delta <= oldDelta || (oldDelta == MAX_DELTA && (delta <= oldDelta + getOverflow(bucket)))) { // the old bucket value is (baseline + oldDelta) + possibly an overflow, so it's guaranteed to be >= the new value return; } if (delta > MAX_DELTA) { int overflow = delta - MAX_DELTA; if (!setOverflow(bucket, overflow)) { // grow overflows arrays if necessary overflowBuckets = Ints.ensureCapacity(overflowBuckets, overflows + 1, OVERFLOW_GROW_INCREMENT); overflowValues = Bytes.ensureCapacity(overflowValues, overflows + 1, OVERFLOW_GROW_INCREMENT); overflowBuckets[overflows] = bucket; overflowValues[overflows] = (byte) overflow; overflows++; } delta = MAX_DELTA; } setDelta(bucket, delta); if (oldDelta == 0) { --baselineCount; adjustBaselineIfNeeded(); } }