using System.Collections.Generic; using System.Linq; using Microsoft.Msagl.Core.DataStructures; using Microsoft.Msagl.Core.GraphAlgorithms; namespace Microsoft.Msagl.Layout.Layered { /// /// This class holds assorted data associated with the graph under layout: list of anchors, /// edges sorted by their sources,targets etc /// #if TEST_MSAGL public #else internal #endif class Database { /// /// maps middles of multiple strings to their buckets /// Set multipleMiddles = new Set(); #if TEST_MSAGL /// /// The layer to visualize. Is set to zero after each display /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")] public int[] nodesToShow; //set it to the layer index to display. The /// /// /// public #else internal #endif Set MultipleMiddles { get { return multipleMiddles; } } /// /// This table keeps multi edges /// Dictionary> multiedges = new Dictionary>(); internal IEnumerable AllIntEdges { get { foreach (List l in Multiedges.Values) foreach (IntEdge e in l) yield return e; } } internal Anchor[] anchors; /// /// Anchors of the nodes /// #if TEST_MSAGL [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")] public #else internal #endif Anchor[] Anchors { get { return anchors; } set { anchors = value; } } internal void AddFeedbackSet(IEnumerable edges) { foreach (IEdge e in edges) { IntPair ip = new IntPair(e.Source, e.Target); IntPair ipr = new IntPair(e.Target, e.Source); //we shuffle reversed edges into the other multiedge List listToShuffle = multiedges[ip]; foreach (IntEdge er in listToShuffle) er.Revert(); if (multiedges.ContainsKey(ipr)) multiedges[ipr].AddRange(listToShuffle); else multiedges[ipr] = listToShuffle; multiedges.Remove(ip); } } internal IEnumerable> RegularMultiedges { get { foreach (KeyValuePair> kv in Multiedges) if (kv.Key.x != kv.Key.y) yield return kv.Value; } } #if TEST_MSAGL /// /// /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Multiedges")] public #else internal #endif Dictionary> Multiedges { get { return this.multiedges; } } internal List GetMultiedge(int source, int target) { return GetMultiedge(new IntPair(source, target)); } internal List GetMultiedge(IntPair ip) { if (multiedges.ContainsKey(ip)) return multiedges[ip]; return new List(); } internal void RegisterOriginalEdgeInMultiedges(IntEdge edge) { IntPair ip = new IntPair(edge.Source, edge.Target); List o; if (multiedges.ContainsKey(ip) == false) multiedges[ip] = o = new List(); else o = multiedges[ip]; o.Add(edge); } internal IEnumerable SkeletonEdges() { return from kv in Multiedges where kv.Key.x != kv.Key.y select kv.Value[0]; } } }