Example #1
0
        /// <summary>
        /// Returns list of indexes in sorted order
        /// </summary>
        private static int[] GetTopologicalSortOrder(IList <DependentAlias2> fields)
        {
            TopologicalSorter        g       = new TopologicalSorter(fields.Count);
            Dictionary <string, int> indexes = new Dictionary <string, int>(fields.Count, StringComparer.OrdinalIgnoreCase);

            // add vertices
            for (int i = 0; i < fields.Count; i++)
            {
                indexes[fields[i].Alias] = g.AddVertex(i);
            }

            // add edges
            for (int i = 0; i < fields.Count; i++)
            {
                var dependentFields = fields[i].DependsOn;
                if (dependentFields != null)
                {
                    foreach (var dependentField in dependentFields)
                    {
                        if (indexes.TryGetValue(dependentField, out var end))
                        {
                            g.AddEdge(i, end);
                        }
                    }
                }
            }

            return(g.Sort());
        }
Example #2
0
        private static int[] GetTopologicalSortOrder(List <DependentAlias> fields)
        {
            TopologicalSorter        g        = new TopologicalSorter(fields.Count);
            Dictionary <string, int> _indexes = new Dictionary <string, int>();

            // add vertices
            for (int i = 0; i < fields.Count; i++)
            {
                _indexes[fields[i].Alias.ToLower()] = g.AddVertex(i);
            }

            // add edges
            for (int i = 0; i < fields.Count; i++)
            {
                var dependentAlias = fields[i];
                if (dependentAlias.DependsOn != null)
                {
                    for (int j = 0; j < dependentAlias.DependsOn.Length; j++)
                    {
                        var dependentField = dependentAlias.DependsOn[j].ToLower();
                        int end;
                        if (_indexes.TryGetValue(dependentField, out end))
                        {
                            g.AddEdge(i, end);
                        }
                    }
                }
            }

            return(g.Sort());
        }
Example #3
0
		private static int[] GetTopologicalSortOrder(List<DependentAlias> fields)
		{
			TopologicalSorter g = new TopologicalSorter(fields.Count);
			Dictionary<string, int> _indexes = new Dictionary<string, int>();

			// add vertices
			for (int i = 0; i < fields.Count; i++)
			{
				_indexes[fields[i].Alias.ToLower()] = g.AddVertex(i);
			}

			// add edges
			for (int i = 0; i < fields.Count; i++)
			{
				if (fields[i].DependsOn != null)
				{
					for (int j = 0; j < fields[i].DependsOn.Length; j++)
					{
						var dependentField = fields[i].DependsOn[j].ToLower();
						if (_indexes.ContainsKey(dependentField))
						{
							g.AddEdge(i, _indexes[dependentField]);
						}
					}
				}
			}

			return g.Sort();
		}