Assets/Plugins/Unity.DSPGraph/Runtime/DSPGraphImplementation.cs
/// <summary>
/// Determine whether a path exists in the graph from source to destination
/// </summary>
Determine whether a path exists in the graph from source to destination
Determine whether a path exists in the graph from source to destination
private bool ContainsPath(DSPNode source, DSPNode destination)
        {
            if (source.Equals(destination))
                return true;
            var connections = Connections;
            var nodes = Nodes;
            var outputConnectionIndex = source.OutputConnectionIndex;
            while (outputConnectionIndex != DSPConnection.InvalidIndex)
            {
                var outgoingConnection = connections[outputConnectionIndex];
                if (ContainsPath(nodes[outgoingConnection.InputNodeIndex], destination))
                    return true;
                outputConnectionIndex = outgoingConnection.NextOutputConnectionIndex;
            }
            return false;
        }
private bool ContainsPath ( DSPNode source , DSPNode destination ) { if ( source . Equals ( destination ) ) return true ; var connections = Connections ; var nodes = Nodes ; var outputConnectionIndex = source . OutputConnectionIndex ; while ( outputConnectionIndex != DSPConnection . InvalidIndex ) { var outgoingConnection = connections [ outputConnectionIndex ] ; if ( ContainsPath ( nodes [ outgoingConnection . InputNodeIndex ] , destination ) ) return true ; outputConnectionIndex = outgoingConnection . NextOutputConnectionIndex ; } return false ; }
Determine whether a path exists in the graph from source to destination
Determine whether a path exists in the graph from source to destination
// Base case: if source == destination, there exists a path from source to destination // Check all output connections from source for a path to destination // All outgoing connections from source have been tested, no path exists
source
DSPNode
destination
DSPNode