Ejemplo n.º 1
0
        /// <summary>
        /// Computes the intersection between this other and the specified other.
        /// </summary>
        /// <param name="set">The other.</param>
        /// <returns>The result of the intersection operation.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="set"/> is a null reference (<c>Nothing</c> in Visual Basic).</exception>
        /// <exception cref="ArgumentException"><paramref name="set"/> is not in the same universe as this instance.</exception>
        /// <example>
        /// <code source="..\..\NGenerics.Examples\DataStructures\General\PascalSetExamples.cs" region="Intersection" lang="cs" title="The following example shows how to use the Intersection method."/>
        /// </example>
        public PascalSet Intersection(PascalSet set)
        {
            #region Validation

            Guard.ArgumentNotNull(set, "other");

            CheckIfUniverseTheSame(set);

            #endregion

            return(new PascalSet(data.And(set.data), lowerBound, upperBound));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Determines whether this set is a proper subset of the specified set.
        /// </summary>
        /// <param name="set">The set to be compared against.</param>
        /// <returns>
        ///     <c>true</c> if this is a proper subset of the specified set; otherwise, <c>false</c>.
        /// </returns>
        /// <exception cref="ArgumentNullException"><paramref name="set"/> is a null reference (<c>Nothing</c> in Visual Basic).</exception>
        /// <exception cref="ArgumentException"><paramref name="set"/> is not in the same universe as this instance.</exception>
        /// <example>
        /// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\General\PascalSetExamples.cs" region="IsProperSubsetOf" lang="cs" title="The following example shows how to use the IsProperSubsetOf method."/>
        /// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\General\PascalSetExamples.vb" region="IsProperSubsetOf" lang="vbnet" title="The following example shows how to use the IsProperSubsetOf method."/>
        /// </example>
        public bool IsProperSubsetOf(PascalSet set)
        {
            #region Validation

            Guard.ArgumentNotNull(set, "set");

            CheckIfUniverseTheSame(set);

            #endregion

            // A is a proper subset of a if the b is a subset of a and a != b
            return(IsSubsetOf(set) && !set.IsSubsetOf(this));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Computes the difference between this set and the specified set.
        /// </summary>
        /// <param name="set">The set.</param>
        /// <returns>The result of the difference operation.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="set"/> is a null reference (<c>Nothing</c> in Visual Basic).</exception>
        /// <exception cref="ArgumentException"><paramref name="set"/> is not in the same universe as this instance.</exception>
        /// <example>
        /// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\General\PascalSetExamples.cs" region="Subtract" lang="cs" title="The following example shows how to use the Subtract method."/>
        /// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\General\PascalSetExamples.vb" region="Subtract" lang="vbnet" title="The following example shows how to use the Subtract method."/>
        /// </example>
        public PascalSet Subtract(PascalSet set)
        {
            #region Validation


            Guard.ArgumentNotNull(set, "set");

            CheckIfUniverseTheSame(set);

            #endregion

            return(new PascalSet(data.Xor(set.data), lowerBound, upperBound));
        }
Ejemplo n.º 4
0
        /// <inheritdoc />
        public bool Equals(PascalSet other)
        {
            if ((other == null) || (!IsUniverseTheSame(other)))
            {
                return(false);
            }

            for (var i = 0; i < data.Length; i++)
            {
                if (data[i] != other.data[i])
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Determines whether this other is a subset of the specified other.
        /// </summary>
        /// <param name="set">The other to be compared against.</param>
        /// <returns>
        ///     <c>true</c> if this other is a subset of the specified other]; otherwise, <c>false</c>.
        /// </returns>
        /// <exception cref="ArgumentNullException"><paramref name="set"/> is a null reference (<c>Nothing</c> in Visual Basic).</exception>
        /// <exception cref="ArgumentException"><paramref name="set"/> is not in the same universe as this instance.</exception>
        /// <example>
        /// <code source="..\..\NGenerics.Examples\DataStructures\General\PascalSetExamples.cs" region="IsSubsetOf" lang="cs" title="The following example shows how to use the IsSubsetOf method."/>
        /// </example>
        public bool IsSubsetOf(PascalSet set)
        {
            #region Validation

            Guard.ArgumentNotNull(set, "other");

            CheckIfUniverseTheSame(set);

            #endregion

            for (var i = 0; i < data.Length; i++)
            {
                if (data[i] && !set.data[i])
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Determines whether [is universe the same] [the specified set].
 /// </summary>
 /// <param name="set">The set.</param>
 /// <returns>
 ///     <c>true</c> if [is universe the same] [the specified set]; otherwise, <c>false</c>.
 /// </returns>
 private bool IsUniverseTheSame(PascalSet set)
 {
     return
         ((set.lowerBound == lowerBound) &&
          (set.upperBound == upperBound));
 }