Exemplo n.º 1
0
        /// <summary>
        /// Set differences a passed-in CustomSet with the current CustomSet.
        /// </summary>
        /// <param name="s">A CustomSet.</param>
        /// <returns>A new CustomSet whose elements are the set difference of <b>s</b> and <b>this</b>.</returns>
        /// <remarks><b>s</b> and <b>this</b> must be "similar" CustomSets.</remarks>
        public virtual CustomSet Difference(CustomSet s)
        {
            if (!AreSimilar(s))
            {
                throw new ArgumentException("Attempting to apply set difference to two dissimilar sets.  Set difference can only occur between two sets with the same universe.");
            }

            // do a bit-wise XOR and then an AND to achieve set difference
            CustomSet result = (CustomSet)Clone();

            result.data.Xor(s.data).And(this.data);

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Intersects a passed-in CustomSet with the current CustomSet.
        /// </summary>
        /// <param name="s">A CustomSet.</param>
        /// <returns>A new CustomSet whose elements are the intersection of <b>s</b> and <b>this</b>.</returns>
        /// <remarks><b>s</b> and <b>this</b> must be "similar" CustomSets.</remarks>
        public virtual CustomSet Intersection(CustomSet s)
        {
            if (!AreSimilar(s))
            {
                throw new ArgumentException("Attempting to intersect two dissimilar sets.  Intersection can only occur between two sets with the same universe.");
            }

            // do a bit-wise AND to intersect this.data and s.data
            CustomSet result = (CustomSet)Clone();

            result.data.And(s.data);

            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Intersects a set of integers with the current CustomSet.
        /// </summary>
        /// <param name="list">An variable number of integers.</param>
        /// <returns>A new CustomSet, which is the intersection of the <b>this</b> CustomSet and the passed-in integers.</returns>
        public virtual CustomSet Intersection(params int[] list)
        {
            CustomSet result = new CustomSet(this.lowerBound, this.upperBound);

            for (int i = 0; i < list.Length; i++)
            {
                // only add the element to result if its in this.data
                int val = list[i];
                if (val >= this.lowerBound && val <= this.upperBound)
                {
                    if (this.data.Get(val - this.lowerBound))
                    {
                        result.data.Set(val - this.lowerBound, true);
                    }
                }
            }

            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Unions a set of integers with the current CustomSet.
        /// </summary>
        /// <param name="list">An variable number of integers.</param>
        /// <returns>A new CustomSet, which is the union of the <b>this</b> CustomSet and the passed-in integers.</returns>
        public virtual CustomSet Union(params int[] list)
        {
            // create a deep copy of this
            CustomSet result = (CustomSet)Clone();

            // For each integer passed in, if it's within the bounds add it to the results's BitArray.
            for (int i = 0; i < list.Length; i++)
            {
                int val = list[i];
                if (val >= this.lowerBound && val <= this.upperBound)
                {
                    result.data.Set(val - this.lowerBound, true);
                }
                else
                {
                    throw new ArgumentException("Attempting to add an element with value " + val.ToString() + " that is outside of the set's universe.  Value must be between " + this.lowerBound.ToString() + " and " + this.upperBound.ToString());
                }
            }

            return(result);              // return the new CustomSet
        }
Exemplo n.º 5
0
        /// <summary>
        /// Determins if this set is a proper superset of the integers passed-in.
        /// </summary>
        /// <param name="list">A variable number of integers.</param>
        /// <returns><b>True</b> if <b>this</b> is a proper superset of the passed-in integers; <b>False</b> otherwise.</returns>
        public virtual bool ProperSuperset(params int[] list)
        {
            CustomSet temp = new CustomSet(this.lowerBound, this.upperBound, list);

            return(ProperSuperset(temp));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Set differences a set of integers with the current CustomSet.
        /// </summary>
        /// <param name="list">An variable number of integers.</param>
        /// <returns>A new CustomSet, which is the set difference of the <b>this</b> CustomSet and the passed-in integers.</returns>
        public virtual CustomSet Difference(params int[] list)
        {
            CustomSet result = new CustomSet(this.lowerBound, this.upperBound, list);

            return(Difference(result));
        }
Exemplo n.º 7
0
 /// <summary>
 /// Determines if two CustomSets are "compatible."  Specifically, it checks to ensure that the CustomSets
 /// share the same lower and upper bounds.
 /// </summary>
 /// <param name="s">The custom set to compare.</param>
 /// <returns><b>True</b> if the CustomSets share the same bounds, <b>False</b> otherwise.</returns>
 protected virtual bool AreSimilar(CustomSet s)
 {
     return(this.lowerBound == s.lowerBound && this.upperBound == s.upperBound);
 }