GetCardinality() public method

Computes the distinct number of short values in the container. Can be expected to run in constant time.
public GetCardinality ( ) : int
return int
Ejemplo n.º 1
0
        /// <summary>
        /// Computes the bitwise AND of this container with another
        /// (intersection). 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 And(ArrayContainer value2)
        {
            ArrayContainer value1          = this;
            int            desiredCapacity = Math.Min(value1.GetCardinality(), value2.GetCardinality());
            ArrayContainer answer          = new ArrayContainer(desiredCapacity);

            answer.Cardinality = Utility.UnsignedIntersect2by2(value1.Content, value1.GetCardinality(), value2.Content, value2.GetCardinality(), answer.Content);
            return(answer);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Computes the in-place bitwise AND of this container with another
 /// (intersection). The current container is generally modified, whereas
 /// the provided container (x) is unaffected. May generate a new container.
 /// </summary>
 /// <param name="x">Other container</param>
 /// <returns>Aggregated container</returns>
 public override Container IAnd(ArrayContainer other)
 {
     Cardinality = Utility.UnsignedIntersect2by2(Content,
                                                 GetCardinality(),
                                                 other.Content,
                                                 other.GetCardinality(),
                                                 Content);
     return(this);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Returns the elements of this ArrayContainer that are not in the
 /// other ArrayContainer.
 /// </summary>
 /// <param name="x">the other ArrayContainer</param>
 /// <returns>The modified container</returns>
 public override Container IAndNot(ArrayContainer x)
 {
     this.Cardinality = Utility.UnsignedDifference(this.Content,
                                                   this.GetCardinality(),
                                                   x.Content,
                                                   x.GetCardinality(),
                                                   this.Content);
     return(this);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns the elements of this ArrayContainer that are not in the
        /// other ArrayContainer.
        /// </summary>
        /// <param name="x">the other ArrayContainer</param>
        /// <returns>A new container with the differences</returns>
        public override Container AndNot(ArrayContainer x)
        {
            int desiredCapacity = this.GetCardinality();
            var answer          = new ArrayContainer(desiredCapacity);

            // Compute the cardinality of the new container
            answer.Cardinality = Utility.UnsignedDifference(this.Content,
                                                            desiredCapacity,
                                                            x.Content,
                                                            x.GetCardinality(),
                                                            answer.Content);
            return(answer);
        }
Ejemplo n.º 6
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;
     }
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Returns the elements of this ArrayContainer that are not in the
 /// other ArrayContainer.
 /// </summary>
 /// <param name="x">the other ArrayContainer</param>
 /// <returns>The modified container</returns>
 public override Container IAndNot(ArrayContainer x)
 {
     this.Cardinality = Utility.UnsignedDifference(this.Content,
                                                   this.GetCardinality(),
                                                   x.Content,
                                                   x.GetCardinality(),
                                                   this.Content);
     return this;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Computes the in-place bitwise AND of this container with another
 /// (intersection). The current container is generally modified, whereas
 /// the provided container (x) is unaffected. May generate a new container.
 /// </summary>
 /// <param name="x">Other container</param>
 /// <returns>Aggregated container</returns>
 public override Container IAnd(ArrayContainer other)
 {
     Cardinality = Utility.UnsignedIntersect2by2(Content,
                                                 GetCardinality(),
                                                 other.Content,
                                                 other.GetCardinality(),
                                                 Content);
     return this;
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Returns the elements of this ArrayContainer that are not in the
        /// other ArrayContainer.
        /// </summary>
        /// <param name="x">the other ArrayContainer</param>
        /// <returns>A new container with the differences</returns>
        public override Container AndNot(ArrayContainer x)
        {
            int desiredCapacity = this.GetCardinality();
            var answer = new ArrayContainer(desiredCapacity);

            // Compute the cardinality of the new container
            answer.Cardinality = Utility.UnsignedDifference(this.Content,
                                                            desiredCapacity,
                                                            x.Content,
                                                            x.GetCardinality(),
                                                            answer.Content);
            return answer;
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Computes the bitwise AND of this container with another
 /// (intersection). 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 And(ArrayContainer value2)
 {
     ArrayContainer value1 = this;
     int desiredCapacity = Math.Min(value1.GetCardinality(), value2.GetCardinality());
     ArrayContainer answer = new ArrayContainer(desiredCapacity);
     answer.Cardinality = Utility.UnsignedIntersect2by2(value1.Content,
                                                        value1.GetCardinality(),
                                                        value2.Content,
                                                        value2.GetCardinality(),
                                                        answer.Content);
     return answer;
 }