public override Container or(ArrayContainer value2)
        {
            ArrayContainer value1           = this;
            int            totalCardinality = value1.getCardinality() + value2.getCardinality();

            if (totalCardinality > DEFAULT_MAX_SIZE)
            {
                // it could be a bitmap!
                BitsetContainer bc = new BitsetContainer();
                for (int k = 0; k < value2.cardinality; ++k)
                {
                    ushort v = value2.content[k];
                    int    i = v >> 6;
                    bc.bitmap[i] |= (1L << v);
                }
                for (int k = 0; k < this.cardinality; ++k)
                {
                    ushort v = this.content[k];
                    int    i = v >> 6;
                    bc.bitmap[i] |= (1L << v);
                }
                bc.cardinality = 0;
                foreach (long k in bc.bitmap)
                {
                    bc.cardinality += Utility.longBitCount(k);
                }
                if (bc.cardinality <= DEFAULT_MAX_SIZE)
                {
                    return(bc.toArrayContainer());
                }
                return(bc);
            }
            else
            {
                // remains an array container
                int desiredCapacity = totalCardinality; // Math.min(BitmapContainer.MAX_CAPACITY,
                                                        // totalCardinality);
                ArrayContainer answer = new ArrayContainer(desiredCapacity);
                answer.cardinality = Utility.unsignedUnion2by2(value1.content,
                                                               value1.getCardinality(), value2.content,
                                                               value2.getCardinality(), answer.content);
                return(answer);
            }
        }
示例#2
0
        /// <summary>
        /// Returns the elements of this BitsetContainer that are not in the
        /// ArrayContainer.
        /// </summary>
        /// <param name="x">the ArrayContainer to compare against</param>
        /// <returns>A new container with the differences</returns>
        public override Container andNot(ArrayContainer x)
        {
            BitsetContainer answer = (BitsetContainer)clone();
            int             c      = x.cardinality;

            for (int k = 0; k < c; ++k)
            {
                ushort v   = x.content[k];
                uint   i   = Utility.toIntUnsigned(v) >> 6;
                long   w   = answer.bitmap[i];
                long   aft = w & (~(1L << v));
                answer.bitmap[i]    = aft;
                answer.cardinality -= (int)((w ^ aft) >> v);
            }
            if (answer.cardinality <= ArrayContainer.DEFAULT_MAX_SIZE)
            {
                return(answer.toArrayContainer());
            }
            return(answer);
        }
 public override Container or(ArrayContainer value2)
 {
     ArrayContainer value1 = this;
     int totalCardinality = value1.getCardinality() + value2.getCardinality();
     if (totalCardinality > DEFAULT_MAX_SIZE) {
         // it could be a bitmap!
         BitsetContainer bc = new BitsetContainer();
         for (int k = 0; k < value2.cardinality; ++k)
         {
             ushort v = value2.content[k];
             int i = v >> 6;
             bc.bitmap[i] |= (1L << v);
         }
         for (int k = 0; k < this.cardinality; ++k)
         {
             ushort v = this.content[k];
             int i = v >> 6;
             bc.bitmap[i] |= (1L << v);
         }
         bc.cardinality = 0;
         foreach (long k in bc.bitmap)
         {
             bc.cardinality += Utility.longBitCount(k);
         }
         if (bc.cardinality <= DEFAULT_MAX_SIZE)
             return bc.toArrayContainer();
         return bc;
     } else {
         // remains an array container
         int desiredCapacity = totalCardinality; // Math.min(BitmapContainer.MAX_CAPACITY,
                                                 // totalCardinality);
         ArrayContainer answer = new ArrayContainer(desiredCapacity);
         answer.cardinality = Utility.unsignedUnion2by2(value1.content,
                 value1.getCardinality(), value2.content,
                 value2.getCardinality(), answer.content);
         return answer;
     }
 }