using System; using System.Collections.Generic; using System.Linq; namespace AutoGroupGenerator { /// /// Represents a strongly connected component (SCC) in the AutoGroupGenerator asset dependency graph. /// /// A SuperNode is an abstraction that groups together asset nodes which are /// mutually dependent on each other, forming a dependency cycle. In graph terms, /// a set of nodes is considered strongly connected if every node in the set /// can be reached from every other node by following dependency edges. /// /// SuperNodes are used internally by AutoGroupGenerator to resolve cyclic dependencies by /// collapsing such cycles into a single logical node during graph analysis. /// This allows the system to reason about dependencies, ordering, and grouping /// in a deterministic way without being blocked by dependency loops. /// /// SuperNodes are not user-facing and are not intended to be created or manipulated /// directly. They exist solely as an implementation detail of AutoGroupGenerator’s graph processing /// pipeline and are handled automatically by the system. /// [Serializable] public class SuperNode : IEquatable { #region Static Methods /// /// Creates a containing a single asset node. /// /// The asset node that will be the only member of the super node. /// A super node containing the provided node as its sole entry. public static SuperNode FromSingle(AssetNode node) => new SuperNode(new[] { node }); #endregion #region Fields private readonly HashSet _nodes; #endregion #region Properties /// /// Gets the asset nodes contained in this super node. /// public IReadOnlyCollection Nodes => _nodes; #endregion #region Methods /// /// Initializes a new instance of the class. /// /// The asset nodes to include in the strongly connected component. public SuperNode(IEnumerable nodes) { _nodes = new HashSet(nodes ?? Enumerable.Empty()); } /// /// Determines whether another super node has the same member nodes. /// /// The other super node. /// True when both super nodes contain the same nodes. public bool Equals(SuperNode other) { if (other == null) { return false; } return _nodes.SetEquals(other._nodes); } /// /// Determines whether another object is equal to this super node. /// /// The other object. /// True when the object is an equal . public override bool Equals(object obj) { return obj is SuperNode other && Equals(other); } /// /// Returns a hash code for this super node. /// /// The hash code. public override int GetHashCode() { unchecked { int hash = 17; foreach (var node in _nodes.OrderBy(n => n.Guid.ToString())) { hash = hash* 31 + node.GetHashCode(); } return hash; } } /// /// Returns a string representation of the super node. /// /// A human-readable string of contained nodes. public override string ToString() { return $"SuperNode[{string.Join(", ", _nodes)}]"; } /// /// Determines whether the super node contains the specified asset node. /// /// The asset node to look for within the super node membership. /// True when the node is present in the super node collection. public bool Contains(AssetNode node) => _nodes.Contains(node); #endregion } }