/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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; } }
/// <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; }
/// <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; }
/// <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; }
/// <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; }