public void IntersectionTest()
        {
            Set<int> a = new Set<int>();
            for(int i = 0; i < 16; i += 2)
                a.Add(i);

            Set<int> b = new Set<int>();
            for(int i = 0; i < 16; i += 3)
                b.Add(i);

            Set<int> inter = a.Intersect(b);

            Assert.AreEqual(3, inter.Count, "A01");
            Assert.AreEqual(0, inter[0], "A02");
            Assert.AreEqual(6, inter[1], "A03");
            Assert.AreEqual(12, inter[2], "A04");
        }
예제 #2
0
 /// <summary>
 /// Performs an "intersection" of the two sets, where only the elements
 /// that are present in both sets remain.  That is, the element is included only if it exists in
 /// both <c>a</c> and <c>b</c>.  Neither input object is modified by the operation.
 /// The result object is a <c>Clone()</c> of one of the input objects (<c>a</c> if it is not <c>null</c>) containing the
 /// elements from the intersect operation.
 /// </summary>
 /// <param name="a">A set of elements.</param>
 /// <param name="b">A set of elements.</param>
 /// <returns>The intersection of the two input sets.  <c>null</c> if both sets are <c>null</c>.</returns>
 public static Set Intersect(Set a, Set b)
 {
     if (a == null && b == null)
     {
         return(null);
     }
     else if (a == null)
     {
         Set resultSet = (Set)((Set)b).Clone();
         resultSet.Clear();
         return(resultSet);
     }
     else if (b == null)
     {
         Set resultSet = (Set)((Set)a).Clone();
         resultSet.Clear();
         return(resultSet);
     }
     else
     {
         return(a.Intersect(b));
     }
 }
예제 #3
0
		/// <summary>
		/// Performs an "intersection" of the two sets, where only the elements
		/// that are present in both sets remain.  That is, the element is included only if it exists in
		/// both <c>a</c> and <c>b</c>.  Neither input object is modified by the operation.
		/// The result object is a <c>Clone()</c> of one of the input objects (<c>a</c> if it is not <c>null</c>) containing the
		/// elements from the intersect operation. 
		/// </summary>
		/// <param name="a">A set of elements.</param>
		/// <param name="b">A set of elements.</param>
		/// <returns>The intersection of the two input sets.  <c>null</c> if both sets are <c>null</c>.</returns>
		public static Set Intersect(Set a, Set b)
		{
			if(a == null && b == null)
				return null;
			else if(a == null)
			{
				Set resultSet = (Set)((Set)b).Clone();
				resultSet.Clear();
				return resultSet;
			}
			else if(b == null)
			{
				Set resultSet = (Set)((Set)a).Clone();
				resultSet.Clear();
				return resultSet;
			}
			else
				return a.Intersect(b);
		}
		// Returns set of packages required by all configs
		public Set<SystemPackage> GetCommonRequiredPackages ()
		{
			if (commonPackages != null)
				return commonPackages;

			commonPackages = new Set<SystemPackage> ();
			int i = 0;
			foreach (Set<SystemPackage> pkgSet in referencedPackagesByConfig.Values) {
				if (i == 0) {
					// Use the first set as the starting one
					foreach (SystemPackage p in pkgSet)
						commonPackages.Add (p);
					i ++;
					continue;
				}

				commonPackages.Intersect (pkgSet);
				if (commonPackages.Count == 0)
					break;
			}
			return commonPackages;
		}
예제 #5
0
 static Set<Term> IntersectWithAny(Set<Term> s1 , Set<Term> s2)
 {
     if (s1.Contains(Any.Value))
         return s2;
     else if (s2.Contains(Any.Value))
         return s1;
     else
         return s1.Intersect(s2);
 }