ToArrayContainer() public method

Copies the data to an array container
public ToArrayContainer ( ) : ArrayContainer
return ArrayContainer
Esempio n. 1
0
        /// <summary>
        /// Computes the bitwise OR of this container with another (union). This
        /// container as well as the provided container are left unaffected.
        /// </summary>
        /// <param name="x">Other container</param>
        /// <returns>Aggregated container</returns>
        public override Container Or(ArrayContainer x)
        {
            ArrayContainer value1           = this;
            int            totalCardinality = value1.GetCardinality() + x.GetCardinality();

            if (totalCardinality > DEFAULT_MAX_SIZE)
            {
                // it could be a bitmap!
                BitsetContainer bc = new BitsetContainer();
                for (int k = 0; k < x.Cardinality; ++k)
                {
                    ushort v = x.Content[k];
                    int    i = v >> 6;
                    bc.Bitmap[i] |= 1L << v;
                }

                for (int k = 0; k < Cardinality; ++k)
                {
                    ushort v = 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);
            }

            // 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(), x.Content, x.GetCardinality(), answer.Content);
            return(answer);
        }
Esempio n. 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   = (uint)(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);
        }
Esempio n. 3
0
 /// <summary>
 /// Computes the bitwise OR of this container with another (union). This
 /// container as well as the provided container are left unaffected.
 /// </summary>
 /// <param name="x">Other container</param>
 /// <returns>Aggregated container</returns>
 public override Container Or(ArrayContainer x)
 {
     ArrayContainer value1 = this;
     int totalCardinality = value1.GetCardinality() + x.GetCardinality();
     if (totalCardinality > DEFAULT_MAX_SIZE)
     {
         // it could be a bitmap!
         BitsetContainer bc = new BitsetContainer();
         for (int k = 0; k < x.Cardinality; ++k)
         {
             ushort v = x.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(),
                                                        x.Content,
                                                        x.GetCardinality(),
                                                        answer.Content);
         return answer;
     }
 }