Ejemplo n.º 1
0
 @Override
 public Container iand(RunContainer x) {
   // could probably be replaced with return iand(x.toBitmapOrArrayContainer());
   final int card = x.getCardinality();
   if (card <= ArrayContainer.DEFAULT_MAX_SIZE) {
     // no point in doing it in-place
     ArrayContainer answer = new ArrayContainer(card);
     answer.cardinality = 0;
     for (int rlepos = 0; rlepos < x.nbrruns; ++rlepos) {
       int runStart = Util.toIntUnsigned(x.getValue(rlepos));
       int runEnd = runStart + Util.toIntUnsigned(x.getLength(rlepos));
       for (int runValue = runStart; runValue <= runEnd; ++runValue) {
         if (this.contains(
             (short)
                 runValue)) { // it looks like contains() should be cheap enough if accessed
                              // sequentially
           answer.content[answer.cardinality++] = (short) runValue;
         }
       }
     }
     return answer;
   }
   int start = 0;
   for (int rlepos = 0; rlepos < x.nbrruns; ++rlepos) {
     int end = Util.toIntUnsigned(x.getValue(rlepos));
     Util.resetBitmapRange(this.bitmap, start, end);
     start = end + Util.toIntUnsigned(x.getLength(rlepos)) + 1;
   }
   Util.resetBitmapRange(this.bitmap, start, Util.maxLowBitAsInteger() + 1);
   computeCardinality();
   if (getCardinality() > ArrayContainer.DEFAULT_MAX_SIZE) return this;
   else return toArrayContainer();
 }
Ejemplo n.º 2
0
 @Override
 public ArrayContainer and(final ArrayContainer value2) {
   final ArrayContainer answer = new ArrayContainer(value2.content.length);
   for (int k = 0; k < value2.getCardinality(); ++k)
     if (this.contains(value2.content[k]))
       answer.content[answer.cardinality++] = value2.content[k];
   return answer;
 }
Ejemplo n.º 3
0
 @Override
 public Container ixor(BitmapContainer b2) {
   int newCardinality = 0;
   for (int k = 0; k < this.bitmap.length; ++k) {
     newCardinality += Long.bitCount(this.bitmap[k] ^ b2.bitmap[k]);
   }
   if (newCardinality > ArrayContainer.DEFAULT_MAX_SIZE) {
     for (int k = 0; k < this.bitmap.length; ++k) {
       this.bitmap[k] = this.bitmap[k] ^ b2.bitmap[k];
     }
     this.cardinality = newCardinality;
     return this;
   }
   ArrayContainer ac = new ArrayContainer(newCardinality);
   Util.fillArrayXOR(ac.content, this.bitmap, b2.bitmap);
   ac.cardinality = newCardinality;
   return ac;
 }
Ejemplo n.º 4
0
 @Override
 public Container xor(BitmapContainer value2) {
   int newCardinality = 0;
   for (int k = 0; k < this.bitmap.length; ++k) {
     newCardinality += Long.bitCount(this.bitmap[k] ^ value2.bitmap[k]);
   }
   if (newCardinality > ArrayContainer.DEFAULT_MAX_SIZE) {
     final BitmapContainer answer = new BitmapContainer();
     for (int k = 0; k < answer.bitmap.length; ++k) {
       answer.bitmap[k] = this.bitmap[k] ^ value2.bitmap[k];
     }
     answer.cardinality = newCardinality;
     return answer;
   }
   ArrayContainer ac = new ArrayContainer(newCardinality);
   Util.fillArrayXOR(ac.content, this.bitmap, value2.bitmap);
   ac.cardinality = newCardinality;
   return ac;
 }
Ejemplo n.º 5
0
 @Override
 public Container xor(final ArrayContainer value2) {
   final BitmapContainer answer = clone();
   for (int k = 0; k < value2.getCardinality(); ++k) {
     final int index = Util.toIntUnsigned(value2.content[k]) >>> 6;
     answer.cardinality +=
         1 - 2 * ((answer.bitmap[index] & (1l << value2.content[k])) >>> value2.content[k]);
     answer.bitmap[index] = answer.bitmap[index] ^ (1l << value2.content[k]);
   }
   if (answer.cardinality <= ArrayContainer.DEFAULT_MAX_SIZE) return answer.toArrayContainer();
   return answer;
 }
Ejemplo n.º 6
0
 @Override
 public Container ixor(final ArrayContainer value2) {
   for (int k = 0; k < value2.getCardinality(); ++k) {
     final int index = Util.toIntUnsigned(value2.content[k]) >>> 6;
     this.cardinality +=
         1 - 2 * ((this.bitmap[index] & (1l << value2.content[k])) >>> value2.content[k]);
     this.bitmap[index] ^= (1l << value2.content[k]);
   }
   if (this.cardinality <= ArrayContainer.DEFAULT_MAX_SIZE) {
     return this.toArrayContainer();
   }
   return this;
 }
Ejemplo n.º 7
0
 /**
  * Copies the data to an array container
  *
  * @return the array container
  */
 public ArrayContainer toArrayContainer() {
   ArrayContainer ac = new ArrayContainer(cardinality);
   ac.loadData(this);
   return ac;
 }
Ejemplo n.º 8
0
 @Override
 public Container iand(final ArrayContainer b2) {
   return b2.and(this); // no inplace possible
 }
Ejemplo n.º 9
0
 @Override
 public boolean intersects(ArrayContainer value2) {
   for (int k = 0; k < value2.getCardinality(); ++k)
     if (this.contains(value2.content[k])) return true;
   return false;
 }