Tree - SeqAn API Documentation

# Spec Tree
A tree.

Extends | Graph
All Extended | Graph
All Impl'd | AssignableConcept, ContainerConcept, DestructibleConcept
Defined in | <seqan/graph_types.h>
Signature | `template <[typename TCargo[, typename TSpec]]> class Graph<Tree<TCargo, TSpec> >;`

## Template Parameters

`TCargo` | The cargo type that can be attached to the edges. Default: `void`.
`TSpec` | Specializing type. Default: `Default`.

## Member Function Overview

### Member Functions Inherited From AssignableConcept

- `operator=`

## Interface Function Overview

- `TVertexDescriptor(g, parent[, cargo]);`
  Adds a new child vertex to a parent vertex, optionally with an edge cargo.
- `void assignRoot(t, v);`
  Assign a new root vertex to the tree.
- `TVertexDescriptor childVertex(g, e);`
  Returns the child vertex of an edge.
- `void collectLeaves(g, v, group);`
  Returns all leaves underneath a given vertex.
- `void createRoot(t);`
  Creates the root for the tree.
- `TVertexDescriptor getRoot(t);`
  Gets the root of the tree.
- `bool isLeaf(g, v);`
  Tests whether a given vertex is a leaf or not.
- `bool isRoot(t, v);`
  Tests whether a given vertex is the root or not.
- `TSize numChildren(g, v);`
  Number of children of a given tree vertex.
- `TSize numTreeEdges(g);`
  Number of tree edges.
- `TVertexDescriptor childVertex(g, e);, TVertexDescriptor childVertex(g, v);`
  Returns the parent vertex of an edge.
- `void removeAllChildren(g, parent);`
  Removes all children from the tree given a parent.
- `void removeChidl(g, parent, child);`
  Removes a child from the tree given a parent.
- `TVertexDescriptor root(t);`
  Gets reference to the root of the tree.

### Interface Functions Inherited From Graph

- `addEdge`
- `addEdges`
- `addVertex`
- `assignEdgeMap`
- `assignVertexMap`
- `clear`
- `clearEdges`
- `clearVertices`
- `degree`
- `empty`
- `findEdge`
- `getAdjacencyMatrix`
- `getNil`
- `getVertexAdjacencyVector`
- `inDegree`
- `numEdges`
- `numVertices`
- `outDegree`
- `removeEdge`
- `removeInEdges`
- `removeOutEdges`
- `removeVertex`
- `resizeEdgeMap`
- `resizeVertexMap`
- `sourceVertex`
- `targetVertex`
- `transpose`
- `write`

### Interface Functions Inherited From AssignableConcept

- `assign`
- `set`
- `move`

### Interface Functions Inherited From ContainerConcept

- `begin`
- `end`
- `length`
- `empty`
- `swap`
- `writeValue`
- `write`
- `getObjectId`
- `moveValue`
- `append`
- `appendValue`
- `shrinkToFit`
- `directionIterator`

## Interface Metafunction Overview

### Interface Metafunctions Inherited From Graph

- `Cargo`
- `EdgeDescriptor`
- `EdgeIdHandler`
- `EdgeType`
- `Size`
- `VertexIdHandler`

### Interface Metafunctions Inherited From ContainerConcept

- `DefaultGetIteratorSpec`
- `DefaultIteratorSpec`
- `Difference`
- `DirectionIterator`
- `GetValue`
- `Iterator`
- `Position`
- `Reference`
- `Size`
- `Value`

## Detailed Description

A Tree has a distinct root and directed edges. The source vertex of each edge is the parent vertex, the target vertex of each edge is the child. Trees provide fast access to child vertices and the parent.

## Interface Functions Detail

### `TVertexDescriptor(g, parent[, cargo]);`

Adds a new child vertex to a parent vertex, optionally with an edge cargo.

#### Parameters

`g` | The Tree to append the vertex and edge to.
`parent` | Descriptor of the parent vertex.
`cargo` | The cargo to attach to the edge.

#### Returns

`TVertexDescriptor` | Vertex descriptor of the added vertex.

#### Data Races

If not stated otherwise, concurrent invocation is not guaranteed to be thread-safe.

### `void assignRoot(t, v);`

Assign a new root vertex to the tree.

#### Parameters

`t` | The Tree to assign the root for.
`v` | A vertex descriptor.

#### Data Races

If not stated otherwise, concurrent invocation is not guaranteed to be thread-safe.

### `TVertexDescriptor childVertex(g, e);`

Returns the child vertex of an edge.

#### Parameters

`g` | The Tree to query.
`e` | The edge descriptor of the edge to query.

#### Returns

`TVertexDescriptor` | The descriptor of the child vertex.

#### Data Races

If not stated otherwise, concurrent invocation is not guaranteed to be thread-safe.

### `void collectLeaves(g, v, group);`

Returns all leaves underneath a given vertex.

#### Parameters

`g` | The Tree to collect the leaves for.
`v` | The root of the subtree to query the leaves of.
`group` | A String of leaf vertex descriptors.

#### Data Races

If not stated otherwise, concurrent invocation is not guaranteed to be thread-safe.

### `void createRoot(t);`

Creates the root for the tree.

#### Parameters

`t` | The Tree to create the root for.

#### Data Races

If not stated otherwise, concurrent invocation is not guaranteed to be thread-safe.

### `TVertexDescriptor getRoot(t);`

Gets the root of the tree.

#### Parameters

`t` | The Tree to query for its root.

#### Returns

`TVertexDescriptor` | The root's vertex descriptor.

#### Data Races

If not stated otherwise, concurrent invocation is not guaranteed to be thread-safe.

### `bool isLeaf(g, v);`

Tests whether a given vertex is a leaf or not.

#### Parameters

`g` | The Tree to query.
`v` | The descriptor of the vertex to query for.

#### Data Races

If not stated otherwise, concurrent invocation is not guaranteed to be thread-safe.

### `bool isRoot(t, v);`

Tests whether a given vertex is the root or not.

#### Parameters

`a` | The Tree to query.
`t` | The descriptor of the vertex to query.

#### Returns

`bool` | true if v is the root and false otherwise.

#### Data Races

If not stated otherwise, concurrent invocation is not guaranteed to be thread-safe.

### `TSize numChildren(g, v);`

Number of children of a given tree vertex.

#### Parameters

`g` | The Tree to query.
`v` | The descriptor of the vertex to count the children of.

#### Returns

`TSize` | The number of children.

#### Data Races

If not stated otherwise, concurrent invocation is not guaranteed to be thread-safe.

### `TSize numTreeEdges(g);`

Number of tree edges.

#### Parameters

`g` | The tree to query.

#### Returns

`TSize` | The number of tree edges. Faster than numEdges for trees.

#### Data Races

If not stated otherwise, concurrent invocation is not guaranteed to be thread-safe.

### `TVertexDescriptor childVertex(g, e); TVertexDescriptor childVertex(g, v);`

Returns the parent vertex of an edge.

#### Parameters

`g` | The Tree to query.
`e` | The edge descriptor of the edge to query.
`v` | The descriptor of the vertex to query.

#### Returns

`TVertexDescriptor` | The descriptor of the child vertex.

#### Data Races

If not stated otherwise, concurrent invocation is not guaranteed to be thread-safe.

### `void removeAllChildren(g, parent);`

Removes all children from the tree given a parent.

#### Parameters

`g` | The Tree to modify.
`parent` | Descriptor of the vertex to remove children of.

#### Data Races

If not stated otherwise, concurrent invocation is not guaranteed to be thread-safe.

### `void removeChidl(g, parent, child);`

Removes a child from the tree given a parent.

#### Parameters

`g` | The Tree to remove the vertex from.
`parent` | The descriptor of the parent vertex.
`child` | The descriptor of the child vertex.

#### Data Races

If not stated otherwise, concurrent invocation is not guaranteed to be thread-safe.

### `TVertexDescriptor root(t);`

Gets reference to the root of the tree.

#### Parameters

`t` | The Tree to query for its root.

#### Returns

`TVertexDescriptor` | Reference to the root's vertex descriptor.

#### Data Races

If not stated otherwise, concurrent invocation is not guaranteed to be thread-safe.

#### Dox Sources

    /*!
     * @class Tree
     *
     * @extends Graph
     *
     * @headerfile <seqan/graph_types.h>
     *
     * @brief A tree.
     *
     * @signature template <[typename TCargo[, typename TSpec]]> class
     *            Graph<Tree<TCargo, TSpec> >;
     *
     * @tparam TCargo The cargo type that can be attached to the edges. Default:
     *                <tt>void</tt>.
     * @tparam TSpec Specializing type. Default: <tt>Default</tt>.
     *
     * A Tree has a distinct root and directed edges. The source vertex of each edge
     * is the parent vertex, the target vertex of each edge is the child. Trees
     * provide fast access to child vertices and the parent.
     *
     * @fn Tree#assignRoot
     *
     * @brief Assign a new root vertex to the tree.
     *
     * @signature void assignRoot(t, v);
     *
     * @param[in,out] t The Tree to assign the root for.
     * @param[in] v A vertex descriptor.
     *
     * @fn Tree#createRoot
     *
     * @brief Creates the root for the tree.
     *
     * @signature void createRoot(t);
     *
     * @param[in,out] t The Tree to create the root for.
     *
     * @fn Tree#root
     *
     * @brief Gets reference to the root of the tree.
     *
     * @signature TVertexDescriptor root(t);
     *
     * @param[in] t The Tree to query for its root.
     *
     * @return TVertexDescriptor Reference to the root's vertex descriptor.
     *
     * @fn Tree#getRoot
     *
     * @brief Gets the root of the tree.
     *
     * @signature TVertexDescriptor getRoot(t);
     *
     * @param[in] t The Tree to query for its root.
     *
     * @return TVertexDescriptor The root's vertex descriptor.
     *
     * @fn Tree#isRoot
     *
     * @brief Tests whether a given vertex is the root or not.
     *
     * @signature bool isRoot(t, v);
     *
     * @param[in] a The Tree to query.
     * @param[in] t The descriptor of the vertex to query.
     *
     * @return bool true if v is the root and false otherwise.
     *
     * @fn Tree#isLeaf
     *
     * @brief Tests whether a given vertex is a leaf or not.
     *
     * @signature bool isLeaf(g, v);
     *
     * @param[in] g The Tree to query.
     * @param[in] v The descriptor of the vertex to query for.
     *
     * @fn Tree#numTreeEdges
     *
     * @brief Number of tree edges.
     *
     * @signature TSize numTreeEdges(g);
     *
     * @param[in] g The tree to query.
     *
     * @return TSize The number of tree edges. Faster than @link Graph#numEdges
     *               @endlink for trees.
     *
     * @fn Tree#numChildren
     *
     * @brief Number of children of a given tree vertex.
     *
     * @signature TSize numChildren(g, v);
     *
     * @param[in] g The Tree to query.
     * @param[in] v The descriptor of the vertex to count the children of.
     *
     * @return TSize The number of children.
     *
     * @fn Tree#addChild
     *
     * @brief Adds a new child vertex to a parent vertex, optionally with an edge
     *        cargo.
     *
     * @signature TVertexDescriptor(g, parent[, cargo]);
     *
     * @param[in,out] g The Tree to append the vertex and edge to.
     * @param[in] parent Descriptor of the parent vertex.
     * @param[in] cargo The cargo to attach to the edge.
     *
     * @return TVertexDescriptor Vertex descriptor of the added vertex.
     *
     * @fn Tree#removeChild
     *
     * @brief Removes a child from the tree given a parent.
     *
     * @signature void removeChidl(g, parent, child);
     *
     * @param[in,out] g The Tree to remove the vertex from.
     * @param[in] parent The descriptor of the parent vertex.
     * @param[in] child The descriptor of the child vertex.
     *
     * @fn Tree#removeAllChildren
     *
     * @brief Removes all children from the tree given a parent.
     *
     * @signature void removeAllChildren(g, parent);
     *
     * @param[in,out] g The Tree to modify.
     * @param[in] parent Descriptor of the vertex to remove children of.
     *
     * @fn Tree#childVertex
     *
     * @brief Returns the child vertex of an edge.
     *
     * @signature TVertexDescriptor childVertex(g, e);
     *
     * @param[in] g The Tree to query.
     * @param[in] e The edge descriptor of the edge to query.
     *
     * @return TVertexDescriptor The descriptor of the child vertex.
     *
     * @fn Tree#parentVertex
     *
     * @brief Returns the parent vertex of an edge.
     *
     * @signature TVertexDescriptor childVertex(g, e);
     * @signature TVertexDescriptor childVertex(g, v);
     *
     * @param[in] g The Tree to query.
     * @param[in] e The edge descriptor of the edge to query.
     * @param[in] v The descriptor of the vertex to query.
     *
     * @return TVertexDescriptor The descriptor of the child vertex.
     *
     * @fn Tree#collectLeaves
     *
     * @brief Returns all leaves underneath a given vertex.
     *
     * @signature void collectLeaves(g, v, group);
     *
     * @param[in] g The Tree to collect the leaves for.
     * @param[in] v The root of the subtree to query the leaves of.
     * @param[out] group A @link String @endlink of leaf vertex descriptors.
     */