Example #1
0
        /// <summary>
        /// Recursively print the signature into the buffer.
        /// </summary>
        /// <param name="buffer">the string buffer to print into</param>
        /// <param name="node">the current node of the signature</param>
        /// <param name="parent">the parent node, or null</param>
        /// <param name="arcs">the list of already visited arcs</param>
        private void Print(StringBuilder buffer, DAG.Node node, DAG.Node parent, List <DAG.Arc> arcs)
        {
            int vertexIndex = GetOriginalVertexIndex(node.vertexIndex);

            // print out any symbol for the edge in the input graph
            if (parent != null)
            {
                int parentVertexIndex = GetOriginalVertexIndex(parent.vertexIndex);
                buffer.Append(GetEdgeLabel(vertexIndex, parentVertexIndex));
            }

            // print out the text that represents the node itself
            buffer.Append(AbstractVertexSignature.StartNodeSymbolChar);
            buffer.Append(GetVertexSymbol(vertexIndex));
            int color = dag.ColorFor(node.vertexIndex);

            if (color != -1)
            {
                buffer.Append(',').Append(color);
            }
            buffer.Append(AbstractVertexSignature.EndNodeSymbolChar);

            // Need to sort the children here, so that they are printed in an order
            // according to their invariants.
            node.children.Sort(dag.nodeComparator);

            // now print the sorted children, surrounded by branch symbols
            bool addedBranchSymbol = false;

            foreach (var child in node.children)
            {
                DAG.Arc arc = new DAG.Arc(node.vertexIndex, child.vertexIndex);
                if (arcs.Contains(arc))
                {
                    continue;
                }
                else
                {
                    if (!addedBranchSymbol)
                    {
                        buffer.Append(AbstractVertexSignature.StartBranchSymbolChar);
                        addedBranchSymbol = true;
                    }
                    arcs.Add(arc);
                    Print(buffer, child, node, arcs);
                }
            }
            if (addedBranchSymbol)
            {
                buffer.Append(AbstractVertexSignature.EndBranchSymbolChar);
            }
        }