github.com/chain5j/chain5j-pkg@v1.0.7/collection/maps/treemap/v2/debug_test.go (about)

     1  package treemap
     2  
     3  import "fmt"
     4  
     5  //nolint:unused,deadcode
     6  func graphvizNodes[Key, Value any](
     7  	node *node[Key, Value],
     8  ) string {
     9  	res := ""
    10  	if node.isBlack {
    11  		res += fmt.Sprintf("%v\n", node.key)
    12  	} else {
    13  		res += fmt.Sprintf("%v [fillcolor=lightpink]\n", node.key)
    14  	}
    15  	if node.left != nil {
    16  		res += graphvizNodes(node.left)
    17  	}
    18  	if node.right != nil {
    19  		res += graphvizNodes(node.right)
    20  	}
    21  	return res
    22  }
    23  
    24  //nolint:unused,deadcode
    25  func graphvizEdges[Key, Value any](
    26  	node *node[Key, Value],
    27  ) string {
    28  	res := ""
    29  	if node.left != nil {
    30  		res += fmt.Sprintf("%v:sw -> %v\n", node.key, node.left.key)
    31  		res += graphvizEdges(node.left)
    32  	}
    33  	if node.right != nil {
    34  		res += fmt.Sprintf("%v:se -> %v\n", node.key, node.right.key)
    35  		res += graphvizEdges(node.right)
    36  	}
    37  	return res
    38  }
    39  
    40  //nolint:unused,deadcode
    41  //noinspection GoUnusedFunction
    42  func graphviz[Key, Value any](
    43  	node *node[Key, Value],
    44  ) string {
    45  	return "digraph {\nnode [style=filled]\n" + graphvizNodes(node) + graphvizEdges(node) + "}\n"
    46  }