public void TestSetUnion(Set<string> setFirst, Set<string> setSecond, Set<string> resultSet)
 {
     setFirst.Union(setSecond);
     var iteratorFirst = setFirst.GetEnumerator();
     var resultIterator = resultSet.GetEnumerator();
     while (iteratorFirst.MoveNext() && resultIterator.MoveNext())
     {
         Assert.AreEqual(iteratorFirst.Current, resultIterator.Current);
     }
 }
예제 #2
0
 /// <summary>
 /// Performs a "union" of two sets, where all the elements
 /// in both are present.  That is, the element is included if it is in either <c>a</c> or <c>b</c>.
 /// The return value is a <c>Clone()</c> of one of the sets (<c>a</c> if it is not <c>null</c>) with elements of the other set
 /// added in.  Neither of the input sets is modified by the operation.
 /// </summary>
 /// <param name="a">A set of elements.</param>
 /// <param name="b">A set of elements.</param>
 /// <returns>A set containing the union of the input sets.  <c>null</c> if both sets are <c>null</c>.</returns>
 public static Set Union(Set a, Set b)
 {
     if (a == null && b == null)
     {
         return(null);
     }
     else if (a == null)
     {
         return((Set)b.Clone());
     }
     else if (b == null)
     {
         return((Set)a.Clone());
     }
     else
     {
         return(a.Union(b));
     }
 }
		/**
		 * returns a set of projects that a combine contains and a set of projects
		 * that are referenced from combine projects but not part of the combine
		 */
		void GetAllProjects (SolutionFolder folder, SolutionConfiguration config, out Set<SolutionFolderItem> projects, out Set<SolutionFolderItem> references)
		{
			List<SolutionFolderItem> subitems = new List<SolutionFolderItem> ();
			GetSubItems (subitems, folder);

			projects = (Set<SolutionFolderItem>) combineProjects [folder];
			if (projects != null) {
				references = (Set<SolutionFolderItem>) combineReferences [folder];
				return;
			}

			projects = new Set<SolutionFolderItem>();
			references = new Set<SolutionFolderItem>();
			
			foreach (SolutionFolderItem item in subitems) 
			{
				if (item is SolutionItem)
				{
					SolutionItem entry = (SolutionItem) item;
					if (!config.BuildEnabledForItem (entry))
						continue;
					projects.Add (entry);
					references.Union (entry.GetReferencedItems (config.Selector));
				}
				else if (item is SolutionFolder) 
				{
					Set<SolutionFolderItem> subProjects;
					Set<SolutionFolderItem> subReferences;
					GetAllProjects ((SolutionFolder)item, config, out subProjects, out subReferences);
					projects.Union (subProjects);
					references.Union (subReferences);
				}
			}
			
			references.Without (projects);
			combineProjects [folder] = projects;
			combineReferences [folder] = references;
		}
		// utility function for finding the correct order to process directories
		List<SolutionFolderItem> CalculateSubDirOrder (AutotoolsContext ctx, SolutionFolder folder, SolutionConfiguration config)
		{
			List<SolutionFolderItem> resultOrder = new List<SolutionFolderItem>();
			Set<SolutionFolderItem> dependenciesMet = new Set<SolutionFolderItem>();
			Set<SolutionFolderItem> inResult = new Set<SolutionFolderItem>();
			
			// We don't have to worry about projects built in parent combines
			dependenciesMet.Union (ctx.GetBuiltProjects ());

			bool added;
			string notMet;
			do 
			{
				added = false;
				notMet = null;
				
				List<SolutionFolderItem> items = new List<SolutionFolderItem> ();
				GetSubItems (items, folder);

				foreach (SolutionFolderItem item in items) 
				{
					Set<SolutionFolderItem> references, provides;
					
					if (inResult.Contains (item))
						continue;
					
					if (item is SolutionItem)
					{
						SolutionItem entry = (SolutionItem) item;
						if (!config.BuildEnabledForItem (entry))
							continue;
						
						references = new Set<SolutionFolderItem> ();
						provides = new Set<SolutionFolderItem>();
						references.Union (entry.GetReferencedItems (config.Selector));
						provides.Add (entry);
					}
					else if (item is SolutionFolder) {
						GetAllProjects ((SolutionFolder) item, config, out provides, out references);
					}
					else
						continue;
	
					if (dependenciesMet.ContainsSet (references) ) 
					{
						resultOrder.Add (item);
						dependenciesMet.Union(provides);
						inResult.Add(item);
						added = true;
					} 
					else notMet = item.Name;
				}
			} while (added);

			if (notMet != null) 
				throw new Exception("Impossible to find a solution order that satisfies project references for '" + notMet + "'");

			return resultOrder;
		}
예제 #5
0
		/// <summary>
		/// Performs a "union" of two sets, where all the elements
		/// in both are present.  That is, the element is included if it is in either <c>a</c> or <c>b</c>.
		/// The return value is a <c>Clone()</c> of one of the sets (<c>a</c> if it is not <c>null</c>) with elements of the other set
		/// added in.  Neither of the input sets is modified by the operation.
		/// </summary>
		/// <param name="a">A set of elements.</param>
		/// <param name="b">A set of elements.</param>
		/// <returns>A set containing the union of the input sets.  <c>null</c> if both sets are <c>null</c>.</returns>
		public static Set Union(Set a, Set b)
		{
			if (a == null && b == null)
				return null;
			else if(a == null)
				return (Set)b.Clone();
			else if(b == null)
				return (Set)a.Clone();
			else
				return a.Union(b);
		}