@Override public int getInt(int id) { assert id < _idToValueMap.size(); return _idToValueMap.get(id); }
@Override public String getString(int id) { assert id < _idToValueMap.size(); return (Integer.valueOf(_idToValueMap.getInt(id)).toString()); } }
/** * Return an estimated selectivity for bitmaps for the dimension values given by dimValueIndexes. * * @param bitmapIndex bitmap index * @param bitmaps bitmaps to extract, by index * @param totalNumRows number of rows in the column associated with this bitmap index * * @return estimated selectivity */ public static double estimateSelectivity( final BitmapIndex bitmapIndex, final IntList bitmaps, final long totalNumRows ) { long numMatchedRows = 0; for (int i = 0; i < bitmaps.size(); i++) { final ImmutableBitmap bitmap = bitmapIndex.getBitmap(bitmaps.getInt(i)); numMatchedRows += bitmap.size(); } return Math.min(1., (double) numMatchedRows / totalNumRows); }
@Override public int put(int value) { int id = _valueToIdMap.get(value); if (id == INVALID_KEY) { id = _idToValueMap.size(); _valueToIdMap.put(value, id); _idToValueMap.add(value); } return id; }
private static int[] filterInts(IntSet intSet, int[] source) { IntList intList = new IntArrayList(); for (int value : source) { if (intSet.contains(value)) { intList.add(value); } } if (intList.size() == source.length) { return source; } else { return intList.toIntArray(); } }
list.size(), chunkFactor, numBytes,
@Test(expected = IndexOutOfBoundsException.class) public void testEmptyRangeIntList() { final IntList list = IntListUtils.fromTo(10, 10); assertEquals(0, list.size()); list.getInt(0); }
ByteBufUtils.writeVarInt(buf, 0); // Palette size -> 0 -> Use the global palette } else { ByteBufUtils.writeVarInt(buf, palette.size()); // Palette size
@Test public void testRemove() { int limit = 100; IntList values = new IntArrayList(new int[] { 1, 20, 1000, 2, 3, 30, 40, 10, 11, 12, 13, 300, 400, 500, 600 }); ByteBuffer myBuffer = ByteBuffer.allocate(1000000); ByteBufferMinMaxOffsetHeap heap = new ByteBufferMinMaxOffsetHeap(myBuffer, limit, Ordering.natural(), null); for (Integer value : values) { heap.addOffset(value); Assert.assertTrue(heap.isIntact()); } heap.removeOffset(12); Assert.assertTrue(heap.isIntact()); Collections.sort(values); values.rem(12); List<Integer> actual = new ArrayList<>(); for (int i = 0; i < values.size(); i++) { int min = heap.removeMin(); actual.add(min); } Assert.assertEquals(values, actual); }
@Override public int size() { return positions.size(); } }
@Override public int size() { return indices.size(); }
int bitsPerBlock = VariableValueArray.calculateNeededBits(palette.size()); if (bitsPerBlock < 4) { bitsPerBlock = 4;
for (int i = 0; i < values.size(); i++) { int min = heap.removeMin(); actual.add(min);
encoded = palette.indexOf(value); if (encoded == -1) { encoded = palette.size(); palette.add(value); if (encoded > data.getLargestPossibleValue()) {
@Override public RatingMatrixEntry get(int index) { Preconditions.checkElementIndex(index, indices.size()); return data.getEntry(index); }
@Test public void testEmptyList() { IntList list = new IntIntervalList(0); assertTrue(list.isEmpty()); assertEquals(0, list.size()); assertFalse(list.iterator().hasNext()); }
@Test public void testEmptyRange() { IntList list = new IntIntervalList(5, 5); assertTrue(list.isEmpty()); assertEquals(0, list.size()); assertFalse(list.iterator().hasNext()); }
@Test public void testBroaderInterval() { IntList list = new IntIntervalList(5); assertFalse(list.isEmpty()); assertEquals(5, list.size()); for (int i = 0; i < 5; i++) { assertEquals(i, list.getInt(i)); } try { list.getInt(5); fail("getInt(5) should throw"); } catch (IndexOutOfBoundsException e) { /* no-op */ } } }
@Test public void testSimpleListAccess() { IntList list = new IntIntervalList(1); assertFalse(list.isEmpty()); assertEquals(1, list.size()); assertEquals(0, list.getInt(0)); try { list.getInt(1); fail("getInt(1) should throw"); } catch (IndexOutOfBoundsException e) { /* no-op */ } IntListIterator iter = list.iterator(); assertTrue(iter.hasNext()); assertFalse(iter.hasPrevious()); assertEquals(0, iter.nextInt()); assertFalse(iter.hasNext()); assertTrue(iter.hasPrevious()); assertEquals(0, iter.previousInt()); }
@Test public void testSimpleIntervalAccess() { IntList list = new IntIntervalList(42, 43); assertFalse(list.isEmpty()); assertEquals(1, list.size()); assertEquals(42, list.getInt(0)); try { list.getInt(1); fail("getInt(1) should throw"); } catch (IndexOutOfBoundsException e) { /* no-op */ } IntListIterator iter = list.iterator(); assertTrue(iter.hasNext()); assertFalse(iter.hasPrevious()); assertEquals(42, iter.nextInt()); assertFalse(iter.hasNext()); assertTrue(iter.hasPrevious()); assertEquals(42, iter.previousInt()); }