/// <summary> /// Deserialize a container from binary format, as written by the Serialize method minus the first 32 bits giving the cardinality. /// </summary> /// <param name="reader">The reader to deserialize from.</param> /// <returns>The first container represented by reader.</returns> public static BitsetContainer Deserialize(BinaryReader reader, int cardinality) { BitsetContainer container = new BitsetContainer(); container.cardinality = cardinality; for(int i = 0; i < container.bitmap.Length; i++) { container.bitmap[i] = reader.ReadInt64(); } return container; }
public override Container and(BitsetContainer value2) { int newCardinality = 0; for (int k = 0; k < this.bitmap.Length; ++k) { newCardinality += Utility.longBitCount( this.bitmap[k] & value2.bitmap[k] ); } if (newCardinality > ArrayContainer.DEFAULT_MAX_SIZE) { BitsetContainer answer = new BitsetContainer(); 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); Utility.fillArrayAND(ref ac.content, this.bitmap, value2.bitmap); ac.cardinality = newCardinality; return ac; }
public override Container ior(BitsetContainer x) { this.cardinality = 0; for (int k = 0; k < this.bitmap.Length; ++k) { long w = this.bitmap[k] | x.bitmap[k]; this.bitmap[k] = w; this.cardinality += Utility.longBitCount(w); } return this; }
/// <summary> /// Performs an intersection with another BitsetContainer. Depending on /// the cardinality of the result, this will either modify the container /// in place or return a new ArrayContainer. /// </summary> /// <param name="other">the other BitsetContainer to intersect</param> public override Container iand(BitsetContainer other) { int newCardinality = 0; for (int k = 0; k < bitmap.Length; ++k) { newCardinality += Utility.longBitCount( bitmap[k] & other.bitmap[k] ); } if (newCardinality > ArrayContainer.DEFAULT_MAX_SIZE) { for (int k = 0; k < bitmap.Length; ++k) { bitmap[k] = bitmap[k] & other.bitmap[k]; } cardinality = newCardinality; return this; } ArrayContainer ac = new ArrayContainer(newCardinality); Utility.fillArrayAND(ref ac.content, bitmap, other.bitmap); ac.cardinality = newCardinality; return ac; }
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; } }
public void loadData(BitsetContainer bitsetContainer) { this.cardinality = bitsetContainer.cardinality; bitsetContainer.fillArray(content); }
/// <summary> /// Returns the elements of this ArrayContainer that are not in the /// other BitSetContainer. Modifies the current container in place. /// </summary> /// <param name="x">the BitSetContainer to compare against</param> /// <returns>A new container with the differences</returns> public override Container iandNot(BitsetContainer x) { int pos = 0; for (int k = 0; k < cardinality; ++k) { ushort v = this.content[k]; if (!x.contains(v)) this.content[pos++] = v; } this.cardinality = pos; return this; }
/// <summary> /// Returns the elements of this ArrayContainer that are not in the /// other BitSetContainer. /// </summary> /// <param name="x">the BitSetContainer to compare against</param> /// <returns>A new container with the differences</returns> public override Container andNot(BitsetContainer x) { var answer = new ArrayContainer(content.Length); int pos = 0; for (int k = 0; k < cardinality; ++k) { ushort val = this.content[k]; if (!x.contains(val)) answer.content[pos++] = val; } answer.cardinality = pos; 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 abstract Container Or(BitsetContainer x);
/// <summary> /// Returns true if the current container intersects the other container. /// </summary> /// <param name="x">Other container</param> /// <returns>Whether they intersect</returns> public abstract bool Intersects(BitsetContainer x);
/// <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 abstract Container IAnd(BitsetContainer x);
public override Container or(BitsetContainer x) { return(x.or((ArrayContainer)this)); }
public void loadData(BitsetContainer bitsetContainer) { this.cardinality = bitsetContainer.cardinality; bitsetContainer.fillArray(content); }
public void LoadData(BitsetContainer bitsetContainer) { this.Cardinality = bitsetContainer.Cardinality; bitsetContainer.FillArray(Content); }
/// <summary> /// Computes the in-place bitwise OR of this container with another /// (union). 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 IOr(BitsetContainer x) { return x.Or(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(BitsetContainer other) { int pos = 0; for (int k = 0; k < Cardinality; k++) { ushort v = Content[k]; if (other.Contains(v)) { Content[pos++] = v; } } Cardinality = pos; return this; }
public override Container and(BitsetContainer x) { return x.and(this); }
/// <summary> /// Computes the bitwise ANDNOT of this container with another /// (difference). This container as well as the provided container are /// left unaffected. /// </summary> /// <param name="x">Other container</param> /// <returns>A new container with the result</returns> public abstract Container AndNot(BitsetContainer x);
/// <summary> /// Performs an in-place intersection with a BitsetContainer. /// </summary> /// <param name="other">the BitsetContainer to intersect</param> public override Container iand(BitsetContainer other) { int pos = 0; for (int k = 0; k < cardinality; k++) { ushort v = content[k]; if (other.contains(v)) content[pos++] = v; } cardinality = pos; return this; }
/// <summary> /// Performs an intersection with another BitsetContainer. Depending on /// the cardinality of the result, this will either modify the container /// in place or return a new ArrayContainer. /// </summary> /// <param name="other">the other BitsetContainer to intersect</param> public override Container IAnd(BitsetContainer other) { int newCardinality = 0; for (int k = 0; k < Bitmap.Length; ++k) { newCardinality += Utility.LongBitCount(Bitmap[k] & other.Bitmap[k]); } if (newCardinality > ArrayContainer.DEFAULT_MAX_SIZE) { for (int k = 0; k < Bitmap.Length; ++k) { Bitmap[k] = Bitmap[k] & other.Bitmap[k]; } Cardinality = newCardinality; return this; } ArrayContainer ac = new ArrayContainer(newCardinality); Utility.FillArrayAND(ref ac.Content, Bitmap, other.Bitmap); ac.Cardinality = newCardinality; return ac; }
public override Container ior(BitsetContainer x) { return x.or(this); }
/// <summary> /// Returns the elements of this BitsetContainer that are not in the /// other BitsetContainer. Depending on the cardinality of the result, /// this will either modify the container in place or return a new ArrayContainer. /// </summary> /// <param name="x">the other BitsetContainer</param> /// <returns>The current container, modified the differences</returns> public override Container IAndNot(BitsetContainer x) { int newCardinality = 0; for (int k = 0; k < this.Bitmap.Length; ++k) { newCardinality += Utility.LongBitCount(this.Bitmap[k] & (~x.Bitmap[k])); } if (newCardinality > ArrayContainer.DEFAULT_MAX_SIZE) { for (int k = 0; k < this.Bitmap.Length; ++k) { this.Bitmap[k] = this.Bitmap[k] & (~x.Bitmap[k]); } this.Cardinality = newCardinality; return this; } ArrayContainer ac = new ArrayContainer(newCardinality); Utility.FillArrayANDNOT(ac.Content, this.Bitmap, x.Bitmap); ac.Cardinality = newCardinality; return ac; }
public override Container or(BitsetContainer x) { return x.or((ArrayContainer) this); }
/// <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(BitsetContainer x) { BitsetContainer answer = new BitsetContainer(); answer.Cardinality = 0; for (int k = 0; k < answer.Bitmap.Length; ++k) { long w = this.Bitmap[k] | x.Bitmap[k]; answer.Bitmap[k] = w; answer.Cardinality += Utility.LongBitCount(w); } return answer; }
public BitsetContainer toBitsetContainer() { BitsetContainer bc = new BitsetContainer(); bc.loadData(this); return bc; }
public void LoadData(BitsetContainer bitsetContainer) { Cardinality = bitsetContainer.Cardinality; bitsetContainer.FillArray(Content); }
public override bool intersects(BitsetContainer x) { throw new NotImplementedException(); }
/// <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(BitsetContainer x) { return(x.And(this)); }
public override Container or(BitsetContainer value2) { BitsetContainer answer = new BitsetContainer(); answer.cardinality = 0; for (int k = 0; k < answer.bitmap.Length; ++k) { long w = this.bitmap[k] | value2.bitmap[k]; answer.bitmap[k] = w; answer.cardinality += Utility.longBitCount(w); } return answer; }
/// <summary> /// Returns true if the current container intersects the other container. /// </summary> /// <param name="x">Other container</param> /// <returns>Whether they intersect</returns> public override bool Intersects(BitsetContainer x) { throw new NotImplementedException(); }
/// <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(BitsetContainer x) { return(x.Or(this)); }
public override Container Or(BitsetContainer x) { throw new NotImplementedException(); }