Documentation ¶
Index ¶
- type FilterFunc
- type FilterVisitor
- type LeafVisitor
- type Node
- func (n *Node) Accept(v VisitorIFace) interface{}
- func (n *Node) AddChild(c NodeIFace) NodeIFace
- func (n *Node) GetAncestors() []NodeIFace
- func (n *Node) GetAncestorsAndSelf() []NodeIFace
- func (n *Node) GetChildren() []NodeIFace
- func (n *Node) GetDepth() int
- func (n *Node) GetHeight() int
- func (n *Node) GetParent() NodeIFace
- func (n *Node) GetSiblings() []NodeIFace
- func (n *Node) GetSiblingsAndSelf() []NodeIFace
- func (n *Node) GetSize() int
- func (n *Node) GetValue() interface{}
- func (n *Node) IsChild() bool
- func (n *Node) IsLeaf() bool
- func (n *Node) IsRoot() bool
- func (n *Node) RemoveAllChildren() NodeIFace
- func (n *Node) RemoveChild(c NodeIFace) NodeIFace
- func (n *Node) SetChildren(c ...NodeIFace) NodeIFace
- func (n *Node) SetParent(p NodeIFace) NodeIFace
- func (n *Node) SetValue(v interface{}) NodeIFace
- type NodeIFace
- type PostOrderVisitor
- type PreOrderVisitor
- type VisitorIFace
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FilterVisitor ¶
type FilterVisitor struct { VisitorIFace // contains filtered or unexported fields }
FilterVisitor is a visitor that filters nodes
func (*FilterVisitor) Visit ¶
func (v *FilterVisitor) Visit(n NodeIFace) interface{}
Visit filters nodes (pre-order traversal) that match the filter and returns []NodeIFace
type LeafVisitor ¶
type LeafVisitor struct {
VisitorIFace
}
LeafVisitor returns the leaves of a tree
func (*LeafVisitor) Visit ¶
func (v *LeafVisitor) Visit(n NodeIFace) interface{}
Visit returns []NodeIFace of leaves on the tree
type Node ¶
type Node struct { NodeIFace // contains filtered or unexported fields }
Node is a Tree Node
func (*Node) Accept ¶
func (n *Node) Accept(v VisitorIFace) interface{}
func (*Node) GetAncestors ¶
func (*Node) GetAncestorsAndSelf ¶
func (*Node) GetChildren ¶
func (*Node) GetSiblings ¶
func (*Node) GetSiblingsAndSelf ¶
func (*Node) RemoveAllChildren ¶
func (*Node) RemoveChild ¶
func (*Node) SetChildren ¶
type NodeIFace ¶
type NodeIFace interface { //SetValue sets the value of this node and returns this node SetValue(v interface{}) NodeIFace //GetValue returns the value of this node GetValue() interface{} //AddChild adds a child to the set of children for this node and returns this node AddChild(NodeIFace) NodeIFace //RemoveChild removes the child node matching the input parameter and returns this node RemoveChild(NodeIFace) NodeIFace //RemoveAllChildren removes all child nodes of this node (and their children) and returns this node RemoveAllChildren() NodeIFace //GetChildren returns all child nodes of this node GetChildren() []NodeIFace //SetChildren replaces all child nodes of this node with new ones and returns this node SetChildren(...NodeIFace) NodeIFace //SetParent sets the parent of this node and returns this node SetParent(NodeIFace) NodeIFace //GetParent returns the parent node of this node or nil if none GetParent() NodeIFace //GetAncestors retrieves all ancestors of node excluding current node GetAncestors() []NodeIFace //GetAncestorsAndSelf retrieves all ancestors of node as well as the node itself GetAncestorsAndSelf() []NodeIFace //GetSiblings retrieves all neighboring nodes (children of same parent), excluding the current node GetSiblings() []NodeIFace //GetSiblingsAndSelf returns all neighboring nodes (children of same parent), including the current node GetSiblingsAndSelf() []NodeIFace //IsRoot returns true if the node is the root, false otherwise IsRoot() bool //IsChild returns true if the node is a child, false otherwise IsChild() bool //IsLeaf returns true if the node is a leaf node, false otherwise IsLeaf() bool //GetDepth returns the distance from the current node to the root GetDepth() int //GetHeight returns the height of the tree whose root is this node GetHeight() int //GetSize returns the number of nodes in the tree rooted at this node GetSize() int //Accept Accept method for the visitor pattern (see http://en.wikipedia.org/wiki/Visitor_pattern) Accept(v VisitorIFace) interface{} }
NodeIFace an interface for a Tree Node
type PostOrderVisitor ¶
type PostOrderVisitor struct {
VisitorIFace
}
PostOrderVisitor walks a tree in post-order
func (*PostOrderVisitor) Visit ¶
func (v *PostOrderVisitor) Visit(n NodeIFace) interface{}
Visit returns []NodeIFace in post order
type PreOrderVisitor ¶
type PreOrderVisitor struct {
VisitorIFace
}
PreOrderVisitor walks a tree in pre-order
func (*PreOrderVisitor) Visit ¶
func (v *PreOrderVisitor) Visit(n NodeIFace) interface{}
Visit returns []NodeIFace in pre order
type VisitorIFace ¶
type VisitorIFace interface { //Visit visits each node starting at given node Visit(NodeIFace) interface{} }
VisitorIFace Visitor interface for Nodes
func NewFilterVisitor ¶
func NewFilterVisitor(filter FilterFunc) VisitorIFace
NewFilterVisitor returns a FilterVisitor
func NewLeafVisitor ¶
func NewLeafVisitor() VisitorIFace
func NewPostOrderVisitor ¶
func NewPostOrderVisitor() VisitorIFace
func NewPreOrderVisitor ¶
func NewPreOrderVisitor() VisitorIFace
Click to show internal directories.
Click to hide internal directories.