コード例 #1
0
  @Test
  @SuppressWarnings("deprecation")
  public void testDeprecatedIteratorAnd() {

    MutableRoaringBitmap rb1 = new MutableRoaringBitmap();
    MutableRoaringBitmap rb2 = new MutableRoaringBitmap();

    List<MutableRoaringBitmap> list = new ArrayList<>();
    list.add(rb1);
    list.add(rb2);

    rb1.add(200000L, 400000L); // two normal positive ranges
    rb2.add(300000L, 500000L); // full overlap is on 300000 to 399999

    MutableRoaringBitmap result = ImmutableRoaringBitmap.and(list.iterator(), 350000L, 450000L);
    MutableRoaringBitmap resultInt = ImmutableRoaringBitmap.and(list.iterator(), 350000, 450000);

    Assert.assertTrue(result.equals(resultInt));
    Assert.assertEquals(50000, result.getCardinality());

    // empty ranges get empty result
    resultInt = ImmutableRoaringBitmap.and(list.iterator(), 300000, 200000);
    result = ImmutableRoaringBitmap.and(list.iterator(), 300000L, 200000L);
    Assert.assertTrue(result.equals(resultInt));
    Assert.assertEquals(0, resultInt.getCardinality());
  }
コード例 #2
0
  @Test
  public void testRangedAnd() {
    int length = 1000;
    int NUM_ITER = 10;
    Random random = new Random(1234); // please use deterministic tests
    for (int test = 0; test < 50; ++test) {
      final MutableRoaringBitmap rb1 = new MutableRoaringBitmap();
      final MutableRoaringBitmap rb2 = new MutableRoaringBitmap();
      Set<Integer> set1 = new HashSet<>();
      Set<Integer> set2 = new HashSet<>();
      int numBitsToSet = length / 2;
      for (int i = 0; i < numBitsToSet; i++) {
        int val1 = random.nextInt(length);
        int val2 = random.nextInt(length);

        rb1.add(val1);
        set1.add(val1);

        rb2.add(val2);
        set2.add(val2);
      }
      Set<Integer> intersectionSet = new TreeSet<>(set1);
      intersectionSet.retainAll(set2);
      for (int iter = 0; iter < NUM_ITER; iter++) {
        int rangeStart = random.nextInt(length - 1);
        // +1 to ensure rangeEnd >rangeStart, may
        int rangeLength = random.nextInt(length - rangeStart) + 1;
        int rangeEnd = rangeStart + rangeLength;
        Set<Integer> expectedResultSet = new TreeSet<>();
        for (int i = rangeStart; i < rangeEnd; i++) {
          if (intersectionSet.contains(i)) {
            expectedResultSet.add(i);
          }
        }
        List<ImmutableRoaringBitmap> list = new ArrayList<>();
        list.add(rb1);
        list.add(rb2);
        MutableRoaringBitmap result =
            ImmutableRoaringBitmap.and(list.iterator(), rangeStart, rangeEnd);
        Set<Integer> actualResultSet = new TreeSet<>();
        IntIterator intIterator = result.getIntIterator();
        while (intIterator.hasNext()) {
          actualResultSet.add(intIterator.next());
        }
        Assert.assertEquals(expectedResultSet, actualResultSet);
      }
    }
  }