@Override public void aggregate(BitmapCounter value) { // Here we optimize for case when group only has 1 value. In such situation, no // aggregation is needed, so we just keep a reference to the first value, saving // the cost of deserialization and merging. if (sum == null) { sum = value; return; } sum.orWith(value); }
public void add(Object key, List keyList, Object value) { if (this.keyList == null) { this.keyList = keyList; } if (this.keyList != null && this.keyList.contains(key)) { BitmapCounter counter = map.computeIfAbsent(key, o -> factory.newBitmap()); counter.orWith((BitmapCounter) value); } }
public long result() { if (keyList == null || keyList.isEmpty()) { return 0; } // if any specified key not in map, the intersection must be 0 for (Object key : keyList) { if (!map.containsKey(key)) { return 0; } } BitmapCounter counter = null; for (Object key : keyList) { BitmapCounter c = map.get(key); if (counter == null) { counter = factory.newBitmap(); counter.orWith(c); } else { counter.andWith(c); } } return counter != null ? counter.getCount() : 0; } }
private BitmapAggregator createBitmapAggr(boolean lowCardinality) { BitmapCounter counter = bitmapFactory.newBitmap(); counter.orWith(lowCardinality ? bitmaps[0] : bitmaps[3]); BitmapAggregator result = new BitmapAggregator(); result.aggregate(counter); return result; }
@Test public void testBitmapCounter() { BitmapCounter counter = factory.newBitmap(10, 20, 30, 1000); assertEquals(4, counter.getCount()); assertTrue(counter.getMemBytes() > 0); BitmapCounter counter2 = factory.newBitmap(); assertEquals(0, counter2.getCount()); counter2.add(10); counter2.add(30); counter2.add(40); counter2.add(2000); assertEquals(4, counter2.getCount()); counter2.orWith(counter); assertEquals(4, counter.getCount()); assertEquals(6, counter2.getCount()); // in-place change int i = 0; int[] values = new int[(int) counter2.getCount()]; for (int value : counter2) { values[i++] = value; } assertArrayEquals(new int[]{10, 20, 30, 40, 1000, 2000}, values); counter2.clear(); assertEquals(0, counter2.getCount()); }
@Override public void aggregate(BitmapCounter value) { // Here we optimize for case when group only has 1 value. In such situation, no // aggregation is needed, so we just keep a reference to the first value, saving // the cost of deserialization and merging. if (sum == null) { sum = value; return; } sum.orWith(value); }
public void add(Object key, List keyList, Object value) { if (this.keyList == null) { this.keyList = keyList; } if (this.keyList != null && this.keyList.contains(key)) { BitmapCounter counter = map.computeIfAbsent(key, o -> factory.newBitmap()); counter.orWith((BitmapCounter) value); } }
public long result() { if (keyList == null || keyList.isEmpty()) { return 0; } // if any specified key not in map, the intersection must be 0 for (Object key : keyList) { if (!map.containsKey(key)) { return 0; } } BitmapCounter counter = null; for (Object key : keyList) { BitmapCounter c = map.get(key); if (counter == null) { counter = factory.newBitmap(); counter.orWith(c); } else { counter.andWith(c); } } return counter != null ? counter.getCount() : 0; } }