@Override long getCountAtIndex(final int index) { return counts[normalizeIndex(index, normalizingIndexOffset, countsArrayLength)]; }
@Override void incrementCountAtIndex(final int index) { int normalizedIndex = normalizeIndex(index, normalizingIndexOffset, countsArrayLength); short currentCount = counts[normalizedIndex]; short newCount = (short) (currentCount + 1); if (newCount < 0) { throw new IllegalStateException("would overflow short integer count"); } counts[normalizedIndex] = newCount; }
@Override void addToCountAtIndex(final int index, final long value) { int normalizedIndex = normalizeIndex(index, normalizingIndexOffset, countsArrayLength); long currentCount = counts[normalizedIndex]; long newCount = (currentCount + value); if ((newCount < Short.MIN_VALUE) || (newCount > Short.MAX_VALUE)) { throw new IllegalArgumentException("would overflow integer count"); } counts[normalizedIndex] = (short) newCount; }
@Override void resize(long newHighestTrackableValue) { int oldNormalizedZeroIndex = normalizeIndex(0, normalizingIndexOffset, countsArrayLength); establishSize(newHighestTrackableValue); int countsDelta = countsArrayLength - counts.length; counts = Arrays.copyOf(counts, countsArrayLength); if (oldNormalizedZeroIndex != 0) { // We need to shift the stuff from the zero index and up to the end of the array: int newNormalizedZeroIndex = oldNormalizedZeroIndex + countsDelta; int lengthToCopy = (countsArrayLength - countsDelta) - oldNormalizedZeroIndex; System.arraycopy(counts, oldNormalizedZeroIndex, counts, newNormalizedZeroIndex, lengthToCopy); Arrays.fill(counts, oldNormalizedZeroIndex, newNormalizedZeroIndex, (short) 0); } }
@Override void setCountAtIndex(int index, long value) { setCountAtNormalizedIndex(normalizeIndex(index, normalizingIndexOffset, countsArrayLength), value); }
@Override long getCountAtIndex(final int index) { return counts[normalizeIndex(index, normalizingIndexOffset, countsArrayLength)]; }
@Override void addToCountAtIndex(final int index, final long value) { int normalizedIndex = normalizeIndex(index, normalizingIndexOffset, countsArrayLength); long currentCount = counts[normalizedIndex]; long newCount = (currentCount + value); if ((newCount < Short.MIN_VALUE) || (newCount > Short.MAX_VALUE)) { throw new IllegalArgumentException("would overflow integer count"); } counts[normalizedIndex] = (short) newCount; }
@Override void incrementCountAtIndex(final int index) { int normalizedIndex = normalizeIndex(index, normalizingIndexOffset, countsArrayLength); short currentCount = counts[normalizedIndex]; short newCount = (short) (currentCount + 1); if (newCount < 0) { throw new IllegalStateException("would overflow short integer count"); } counts[normalizedIndex] = newCount; }
@Override void setCountAtIndex(int index, long value) { setCountAtNormalizedIndex(normalizeIndex(index, normalizingIndexOffset, countsArrayLength), value); }
@Override void resize(long newHighestTrackableValue) { int oldNormalizedZeroIndex = normalizeIndex(0, normalizingIndexOffset, countsArrayLength); establishSize(newHighestTrackableValue); int countsDelta = countsArrayLength - counts.length; counts = Arrays.copyOf(counts, countsArrayLength); if (oldNormalizedZeroIndex != 0) { // We need to shift the stuff from the zero index and up to the end of the array: int newNormalizedZeroIndex = oldNormalizedZeroIndex + countsDelta; int lengthToCopy = (countsArrayLength - countsDelta) - oldNormalizedZeroIndex; System.arraycopy(counts, oldNormalizedZeroIndex, counts, newNormalizedZeroIndex, lengthToCopy); Arrays.fill(counts, oldNormalizedZeroIndex, newNormalizedZeroIndex, (short) 0); } }