Is this a misuse of sync.Pool? How would a Go programmer re-write the ugly `t.left =` `self.left =` ?
package main import ( "fmt" "sync" ) type Node struct { left, right *Node } var pool = sync.Pool { New: func() interface{} { return &Node{} }, } func bottomUpTree(depth int) *Node { if depth <= 0 { return pool.Get().(*Node) } var t = pool.Get().(*Node) t.left = bottomUpTree(depth-1) t.right = bottomUpTree(depth-1) return t } func (self *Node) itemCheck() int { if self.left == nil { return 1 } var check = 1 + self.left.itemCheck() + self.right.itemCheck() pool.Put(self.left) self.left = nil pool.Put(self.right) self.right = nil return check } func main() { const stretchDepth = 22 check := bottomUpTree(stretchDepth).itemCheck() fmt.Printf("stretch tree of depth %v\t check: %v\n", stretchDepth, check) } -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.