Skip to content

Commit

Permalink
Added tip edge function to tree
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericlemoine committed Oct 5, 2016
1 parent 3de9c40 commit 169b6bc
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tree/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,31 @@ func (t *Tree) edgesRecur(edge *Edge, edges *[]*Edge) {
}
}

// Returns all the tip edges of the tree (do it recursively)
func (t *Tree) TipEdges() []*Edge {
edges := make([]*Edge, 0, 2000)
for _, e := range t.Root().br {
if e.Right().Tip() {
edges = append(edges, e)
}
t.tipEdgesRecur(e, &edges)
}
return edges
}

func (t *Tree) tipEdgesRecur(edge *Edge, edges *[]*Edge) {
if len(edge.right.neigh) > 1 {
for _, child := range edge.right.br {
if child.left == edge.right {
if child.Right().Tip() {
*edges = append((*edges), child)
}
t.tipEdgesRecur(child, edges)
}
}
}
}

// Returns all the nodes of the tree (do it recursively)
func (t *Tree) Nodes() []*Node {
nodes := make([]*Node, 0, 2000)
Expand Down

0 comments on commit 169b6bc

Please sign in to comment.