github ddddddO/gtree v1.12.0

2 days ago

What's Changed

  • Bump github.com/urfave/cli/v3 from 3.4.1 to 3.5.0 by @dependabot[bot] in #325
  • Add option of allowing_duplicate_nodes by @ddddddO in #327

Tip

Specifying WithDuplicationAllowed function in NewRoot function,
which generates the Node arguments for the above functions,
allows multiple nodes with the same name to exist within the same hierarchy.

Standard Pattern and Pattern Allowing Node Duplication

package main

import (
	"os"

	"github.com/ddddddO/gtree"
)

func main() {
	rootOfStandard := gtree.NewRoot("Standard Pattern")
	addChildren(rootOfStandard)
	_ = gtree.OutputFromRoot(os.Stdout, rootOfStandard)
	// Standard Pattern
	// ├── child 1
	// │   └── child 2
	// │       ├── child 3
	// │       └── child 4
	// │           ├── child 5
	// │           └── child 6
	// │               ├── child 7
	// │               └── child 9
	// └── child 8

	rootOfAllowedDuplication := gtree.NewRoot("Pattern Allowing Node Duplication", gtree.WithDuplicationAllowed())
	addChildren(rootOfAllowedDuplication)
	_ = gtree.OutputFromRoot(os.Stdout, rootOfAllowedDuplication)
	// Pattern Allowing Node Duplication
	// ├── child 1
	// │   └── child 2
	// │       └── child 3
	// ├── child 1
	// │   └── child 2
	// │       └── child 4
	// │           ├── child 5
	// │           ├── child 6
	// │           │   └── child 7
	// │           ├── child 6
	// │           │   └── child 9
	// │           └── child 5
	// └── child 8
}

func addChildren(root *gtree.Node) {
	root.Add("child 1").Add("child 2").Add("child 3")
	var child4 *gtree.Node = root.Add("child 1").Add("child 2").Add("child 4")
	child4.Add("child 5")
	child4.Add("child 6").Add("child 7")
	child4.Add("child 6").Add("child 9")
	child4.Add("child 5")
	root.Add("child 8")
}

-> ref1(NewRoot)
-> ref2(OutputFromRoot)
-> ref3(WalkFromRoot)
-> ref4(WalkIterFromRoot)

Full Changelog: v1.11.9...v1.12.0

Don't miss a new gtree release

NewReleases is sending notifications on new releases.