コード例 #1
0
 @Override
 public MappeableContainer or(final MappeableArrayContainer value2) {
   final MappeableArrayContainer value1 = this;
   final int totalCardinality = value1.getCardinality() + value2.getCardinality();
   if (totalCardinality > DEFAULT_MAX_SIZE) { // it could be a bitmap!
     final MappeableBitmapContainer bc = new MappeableBitmapContainer();
     if (!BufferUtil.isBackedBySimpleArray(bc.bitmap))
       throw new RuntimeException("Should not happen. Internal bug.");
     long[] bitArray = bc.bitmap.array();
     if (BufferUtil.isBackedBySimpleArray(value2.content)) {
       short[] sarray = value2.content.array();
       for (int k = 0; k < value2.cardinality; ++k) {
         final int i = BufferUtil.toIntUnsigned(sarray[k]) >>> 6;
         bitArray[i] |= (1l << sarray[k]);
       }
     } else
       for (int k = 0; k < value2.cardinality; ++k) {
         short v2 = value2.content.get(k);
         final int i = BufferUtil.toIntUnsigned(v2) >>> 6;
         bitArray[i] |= (1l << v2);
       }
     if (BufferUtil.isBackedBySimpleArray(this.content)) {
       short[] sarray = this.content.array();
       for (int k = 0; k < this.cardinality; ++k) {
         final int i = BufferUtil.toIntUnsigned(sarray[k]) >>> 6;
         bitArray[i] |= (1l << sarray[k]);
       }
     } else
       for (int k = 0; k < this.cardinality; ++k) {
         final int i = BufferUtil.toIntUnsigned(this.content.get(k)) >>> 6;
         bitArray[i] |= (1l << this.content.get(k));
       }
     bc.cardinality = 0;
     int len = bc.bitmap.limit();
     for (int index = 0; index < len; ++index) {
       bc.cardinality += Long.bitCount(bitArray[index]);
     }
     if (bc.cardinality <= DEFAULT_MAX_SIZE) return bc.toArrayContainer();
     return bc;
   }
   final MappeableArrayContainer answer = new MappeableArrayContainer(totalCardinality);
   if (BufferUtil.isBackedBySimpleArray(value1.content)
       && BufferUtil.isBackedBySimpleArray(value2.content))
     answer.cardinality =
         org.roaringbitmap.Util.unsignedUnion2by2(
             value1.content.array(),
             value1.getCardinality(),
             value2.content.array(),
             value2.getCardinality(),
             answer.content.array());
   else
     answer.cardinality =
         BufferUtil.unsignedUnion2by2(
             value1.content,
             value1.getCardinality(),
             value2.content,
             value2.getCardinality(),
             answer.content.array());
   return answer;
 }
コード例 #2
0
  @Override
  public MappeableArrayContainer and(final MappeableArrayContainer value2) {

    MappeableArrayContainer value1 = this;
    final int desiredCapacity = Math.min(value1.getCardinality(), value2.getCardinality());
    MappeableArrayContainer answer = new MappeableArrayContainer(desiredCapacity);
    if (BufferUtil.isBackedBySimpleArray(this.content)
        && BufferUtil.isBackedBySimpleArray(value2.content))
      answer.cardinality =
          org.roaringbitmap.Util.unsignedIntersect2by2(
              value1.content.array(),
              value1.getCardinality(),
              value2.content.array(),
              value2.getCardinality(),
              answer.content.array());
    else
      answer.cardinality =
          BufferUtil.unsignedIntersect2by2(
              value1.content,
              value1.getCardinality(),
              value2.content,
              value2.getCardinality(),
              answer.content.array());
    return answer;
  }
コード例 #3
0
  @Override
  public MappeableArrayContainer iandNot(final MappeableArrayContainer value2) {
    if (!BufferUtil.isBackedBySimpleArray(this.content))
      throw new RuntimeException("Should not happen. Internal bug.");
    if (BufferUtil.isBackedBySimpleArray(value2.content))
      this.cardinality =
          org.roaringbitmap.Util.unsignedDifference(
              this.content.array(),
              this.getCardinality(),
              value2.content.array(),
              value2.getCardinality(),
              this.content.array());
    else
      this.cardinality =
          BufferUtil.unsignedDifference(
              this.content,
              this.getCardinality(),
              value2.content,
              value2.getCardinality(),
              this.content.array());

    return this;
  }