@Test public void testGetBar() { EquiDepthStreamHistogram histo = new EquiDepthStreamHistogram(10); Bar bar = histo.getBar(bytesB); assertTrue(Arrays.equals(bytesB, bar.getLeftBoundInclusive())); assertEquals(1, histo.bars.size()); assertTrue(bar == histo.getBar(bytesB)); assertTrue(bar == histo.getBar(bytesA)); assertTrue(bar == histo.getBar(bytesC)); assertEquals(1, histo.bars.size()); assertArrayEquals(bytesA, bar.getLeftBoundInclusive()); assertArrayEquals(bytesC, bar.getRightBoundExclusive()); histo.bars = new ArrayList<Bar>(); histo.bars.add(b_c); histo.bars.add(c_d); assertEquals(b_c, histo.getBar(bytesB)); assertEquals(c_d, histo.getBar(bytesC)); assertTrue(histo.getBar(bytesA) == b_c); assertTrue(histo.getBar(bytesE) == c_d); assertArrayEquals(bytesA, b_c.getLeftBoundInclusive()); assertArrayEquals(bytesE, c_d.getRightBoundExclusive()); }
@VisibleForTesting Bar getBar(byte[] value) { Bar searchKey = new Bar(value, value); int searchIdx = Collections.binarySearch(this.bars, searchKey); if (searchIdx < 0) { byte[] newBound = Bytes.copy(value); if (this.bars.size() == 0) { Bar firstBar = new Bar(newBound, newBound); bars.add(firstBar); return firstBar; } int expectedIndex = Math.abs(searchIdx + 1); if (expectedIndex == bars.size()) { Bar lastBar = bars.get(expectedIndex - 1); lastBar.setRightBoundExclusive(newBound); return lastBar; } else { Bar nextBar = bars.get(expectedIndex); nextBar.setLeftBoundInclusive(newBound); return nextBar; } } else { return bars.get(searchIdx); } }
EquiDepthStreamHistogram { @VisibleForTesting Bar getBar(byte[] value) { Bar searchKey = new Bar(value, value); int searchIdx = Collections.binarySearch(this.bars, searchKey); if (searchIdx < 0) { byte[] newBound = Bytes.copy(value); if (this.bars.size() == 0) { Bar firstBar = new Bar(newBound, newBound); bars.add(firstBar); return firstBar; } int expectedIndex = Math.abs(searchIdx + 1); if (expectedIndex == bars.size()) { Bar lastBar = bars.get(expectedIndex - 1); lastBar.setRightBoundExclusive(newBound); return lastBar; } else { Bar nextBar = bars.get(expectedIndex); nextBar.setLeftBoundInclusive(newBound); return nextBar; } } else { return bars.get(searchIdx); } } }
EquiDepthStreamHistogram { @VisibleForTesting Bar getBar(byte[] value) { Bar searchKey = new Bar(value, value); int searchIdx = Collections.binarySearch(this.bars, searchKey); if (searchIdx < 0) { byte[] newBound = Bytes.copy(value); if (this.bars.size() == 0) { Bar firstBar = new Bar(newBound, newBound); bars.add(firstBar); return firstBar; } int expectedIndex = Math.abs(searchIdx + 1); if (expectedIndex == bars.size()) { Bar lastBar = bars.get(expectedIndex - 1); lastBar.setRightBoundExclusive(newBound); return lastBar; } else { Bar nextBar = bars.get(expectedIndex); nextBar.setLeftBoundInclusive(newBound); return nextBar; } } else { return bars.get(searchIdx); } } EquiDepthStreamHistogram(int numBuckets);  EquiDepthStreamHistogram(int numBuckets, int expansionFactor); }
EquiDepthStreamHistogram { @VisibleForTesting Bar getBar(byte[] value) { Bar searchKey = new Bar(value, value); int searchIdx = Collections.binarySearch(this.bars, searchKey); if (searchIdx < 0) { byte[] newBound = Bytes.copy(value); if (this.bars.size() == 0) { Bar firstBar = new Bar(newBound, newBound); bars.add(firstBar); return firstBar; } int expectedIndex = Math.abs(searchIdx + 1); if (expectedIndex == bars.size()) { Bar lastBar = bars.get(expectedIndex - 1); lastBar.setRightBoundExclusive(newBound); return lastBar; } else { Bar nextBar = bars.get(expectedIndex); nextBar.setLeftBoundInclusive(newBound); return nextBar; } } else { return bars.get(searchIdx); } } EquiDepthStreamHistogram(int numBuckets);  EquiDepthStreamHistogram(int numBuckets, int expansionFactor); void addValue(byte[] value); List<Bucket> computeBuckets(); long getTotalCount(); }
EquiDepthStreamHistogram { @VisibleForTesting Bar getBar(byte[] value) { Bar searchKey = new Bar(value, value); int searchIdx = Collections.binarySearch(this.bars, searchKey); if (searchIdx < 0) { byte[] newBound = Bytes.copy(value); if (this.bars.size() == 0) { Bar firstBar = new Bar(newBound, newBound); bars.add(firstBar); return firstBar; } int expectedIndex = Math.abs(searchIdx + 1); if (expectedIndex == bars.size()) { Bar lastBar = bars.get(expectedIndex - 1); lastBar.setRightBoundExclusive(newBound); return lastBar; } else { Bar nextBar = bars.get(expectedIndex); nextBar.setLeftBoundInclusive(newBound); return nextBar; } } else { return bars.get(searchIdx); } } EquiDepthStreamHistogram(int numBuckets);  EquiDepthStreamHistogram(int numBuckets, int expansionFactor); void addValue(byte[] value); List<Bucket> computeBuckets(); long getTotalCount();  }