Skip to content

Commit

Permalink
Impl HasChild method for WalkerNode (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddddddO committed Nov 5, 2023
1 parent 1ab9fb2 commit 85520a1
Show file tree
Hide file tree
Showing 6 changed files with 224 additions and 182 deletions.
187 changes: 102 additions & 85 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -720,11 +720,12 @@ func main() {

callback2 := func(wn *gtree.WalkerNode) error {
fmt.Println("WalkerNode's methods called...")
fmt.Printf("\tName : %s\n", wn.Name())
fmt.Printf("\tBranch : %s\n", wn.Branch())
fmt.Printf("\tRow : %s\n", wn.Row())
fmt.Printf("\tLevel : %d\n", wn.Level())
fmt.Printf("\tPath : %s\n", wn.Path())
fmt.Printf("\tName : %s\n", wn.Name())
fmt.Printf("\tBranch : %s\n", wn.Branch())
fmt.Printf("\tRow : %s\n", wn.Row())
fmt.Printf("\tLevel : %d\n", wn.Level())
fmt.Printf("\tPath : %s\n", wn.Path())
fmt.Printf("\tHasChild : %t\n", wn.HasChild())
return nil
}

Expand All @@ -734,59 +735,68 @@ func main() {
}
// Output:
// WalkerNode's methods called...
// Name : a
// Branch :
// Row : a
// Level : 1
// Path : a
// Name : a
// Branch :
// Row : a
// Level : 1
// Path : a
// HasChild : true
// WalkerNode's methods called...
// Name : i
// Branch : ├──
// Row : ├── i
// Level : 2
// Path : a/i
// Name : i
// Branch : ├──
// Row : ├── i
// Level : 2
// Path : a/i
// HasChild : true
// WalkerNode's methods called...
// Name : u
// Branch : │ └──
// Row : │ └── u
// Level : 3
// Path : a/i/u
// Name : u
// Branch : │ └──
// Row : │ └── u
// Level : 3
// Path : a/i/u
// HasChild : true
// WalkerNode's methods called...
// Name : k
// Branch : │ └──
// Row : │ └── k
// Level : 4
// Path : a/i/u/k
// Name : k
// Branch : │ └──
// Row : │ └── k
// Level : 4
// Path : a/i/u/k
// HasChild : false
// WalkerNode's methods called...
// Name : kk
// Branch : └──
// Row : └── kk
// Level : 2
// Path : a/kk
// Name : kk
// Branch : └──
// Row : └── kk
// Level : 2
// Path : a/kk
// HasChild : true
// WalkerNode's methods called...
// Name : t
// Branch : └──
// Row : └── t
// Level : 3
// Path : a/kk/t
// Name : t
// Branch : └──
// Row : └── t
// Level : 3
// Path : a/kk/t
// HasChild : false
// WalkerNode's methods called...
// Name : e
// Branch :
// Row : e
// Level : 1
// Path : e
// Name : e
// Branch :
// Row : e
// Level : 1
// Path : e
// HasChild : true
// WalkerNode's methods called...
// Name : o
// Branch : └──
// Row : └── o
// Level : 2
// Path : e/o
// Name : o
// Branch : └──
// Row : └── o
// Level : 2
// Path : e/o
// HasChild : true
// WalkerNode's methods called...
// Name : g
// Branch : └──
// Row : └── g
// Level : 3
// Path : e/o/g
// Name : g
// Branch : └──
// Row : └── g
// Level : 3
// Path : e/o/g
// HasChild : false
}
```

Expand Down Expand Up @@ -1146,11 +1156,12 @@ func main() {

callback2 := func(wn *gtree.WalkerNode) error {
fmt.Println("WalkerNode's methods called...")
fmt.Printf("\tName : %s\n", wn.Name())
fmt.Printf("\tBranch : %s\n", wn.Branch())
fmt.Printf("\tRow : %s\n", wn.Row())
fmt.Printf("\tLevel : %d\n", wn.Level())
fmt.Printf("\tPath : %s\n", wn.Path())
fmt.Printf("\tName : %s\n", wn.Name())
fmt.Printf("\tBranch : %s\n", wn.Branch())
fmt.Printf("\tRow : %s\n", wn.Row())
fmt.Printf("\tLevel : %d\n", wn.Level())
fmt.Printf("\tPath : %s\n", wn.Path())
fmt.Printf("\tHasChild : %t\n", wn.HasChild())
return nil
}

Expand All @@ -1160,41 +1171,47 @@ func main() {
}
// Output:
// WalkerNode's methods called...
// Name : root
// Branch :
// Row : root
// Level : 1
// Path : root
// Name : root
// Branch :
// Row : root
// Level : 1
// Path : root
// HasChild : true
// WalkerNode's methods called...
// Name : child 1
// Branch : ├──
// Row : ├── child 1
// Level : 2
// Path : root/child 1
// Name : child 1
// Branch : ├──
// Row : ├── child 1
// Level : 2
// Path : root/child 1
// HasChild : true
// WalkerNode's methods called...
// Name : child 2
// Branch : │ └──
// Row : │ └── child 2
// Level : 3
// Path : root/child 1/child 2
// Name : child 2
// Branch : │ └──
// Row : │ └── child 2
// Level : 3
// Path : root/child 1/child 2
// HasChild : true
// WalkerNode's methods called...
// Name : child 3
// Branch : │ ├──
// Row : │ ├── child 3
// Level : 4
// Path : root/child 1/child 2/child 3
// Name : child 3
// Branch : │ ├──
// Row : │ ├── child 3
// Level : 4
// Path : root/child 1/child 2/child 3
// HasChild : false
// WalkerNode's methods called...
// Name : child 4
// Branch : │ └──
// Row : │ └── child 4
// Level : 4
// Path : root/child 1/child 2/child 4
// Name : child 4
// Branch : │ └──
// Row : │ └── child 4
// Level : 4
// Path : root/child 1/child 2/child 4
// HasChild : false
// WalkerNode's methods called...
// Name : child 5
// Branch : └──
// Row : └── child 5
// Level : 2
// Path : root/child 5
// Name : child 5
// Branch : └──
// Row : └── child 5
// Level : 2
// Path : root/child 5
// HasChild : false
}
```

Expand Down
110 changes: 60 additions & 50 deletions example/like_cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,12 @@ func sampleWalker() error {

callback2 := func(wn *gtree.WalkerNode) error {
fmt.Println("WalkerNode's methods called...")
fmt.Printf("\tName : %s\n", wn.Name())
fmt.Printf("\tBranch : %s\n", wn.Branch())
fmt.Printf("\tRow : %s\n", wn.Row())
fmt.Printf("\tLevel : %d\n", wn.Level())
fmt.Printf("\tPath : %s\n", wn.Path())
fmt.Printf("\tName : %s\n", wn.Name())
fmt.Printf("\tBranch : %s\n", wn.Branch())
fmt.Printf("\tRow : %s\n", wn.Row())
fmt.Printf("\tLevel : %d\n", wn.Level())
fmt.Printf("\tPath : %s\n", wn.Path())
fmt.Printf("\tHasChild : %t\n", wn.HasChild())
return nil
}

Expand All @@ -127,59 +128,68 @@ func sampleWalker() error {
}
// Output:
// WalkerNode's methods called...
// Name : a
// Branch :
// Row : a
// Level : 1
// Path : a
// Name : a
// Branch :
// Row : a
// Level : 1
// Path : a
// HasChild : true
// WalkerNode's methods called...
// Name : i
// Branch : ├──
// Row : ├── i
// Level : 2
// Path : a/i
// Name : i
// Branch : ├──
// Row : ├── i
// Level : 2
// Path : a/i
// HasChild : true
// WalkerNode's methods called...
// Name : u
// Branch : │ └──
// Row : │ └── u
// Level : 3
// Path : a/i/u
// Name : u
// Branch : │ └──
// Row : │ └── u
// Level : 3
// Path : a/i/u
// HasChild : true
// WalkerNode's methods called...
// Name : k
// Branch : │ └──
// Row : │ └── k
// Level : 4
// Path : a/i/u/k
// Name : k
// Branch : │ └──
// Row : │ └── k
// Level : 4
// Path : a/i/u/k
// HasChild : false
// WalkerNode's methods called...
// Name : kk
// Branch : └──
// Row : └── kk
// Level : 2
// Path : a/kk
// Name : kk
// Branch : └──
// Row : └── kk
// Level : 2
// Path : a/kk
// HasChild : true
// WalkerNode's methods called...
// Name : t
// Branch : └──
// Row : └── t
// Level : 3
// Path : a/kk/t
// Name : t
// Branch : └──
// Row : └── t
// Level : 3
// Path : a/kk/t
// HasChild : false
// WalkerNode's methods called...
// Name : e
// Branch :
// Row : e
// Level : 1
// Path : e
// Name : e
// Branch :
// Row : e
// Level : 1
// Path : e
// HasChild : true
// WalkerNode's methods called...
// Name : o
// Branch : └──
// Row : └── o
// Level : 2
// Path : e/o
// Name : o
// Branch : └──
// Row : └── o
// Level : 2
// Path : e/o
// HasChild : true
// WalkerNode's methods called...
// Name : g
// Branch : └──
// Row : └── g
// Level : 3
// Path : e/o/g
// Name : g
// Branch : └──
// Row : └── g
// Level : 3
// Path : e/o/g
// HasChild : false

fmt.Println("\nWalker Sample...end")
fmt.Println()
Expand Down

0 comments on commit 85520a1

Please sign in to comment.