liborigin2: tree< T, tree_node_allocator > Class Template Reference

liborigin2 29/08/2011

Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Types | Private Member Functions | Private Attributes | List of all members
tree< T, tree_node_allocator > Class Template Reference

`#include <tree.hh>`

## Classes
class | breadth_first_queued_iterator
| Breadth-first iterator, using a queue. More...
class | compare_nodes
| Comparator class for two nodes of a tree (used for sorting and searching). More...
class | fixed_depth_iterator
| Iterator which traverses only the nodes at a given depth from the root. More...
class | iterator_base
| Base class for iterators, only pointers stored, no traversal logic. More...
class | iterator_base_less
| Comparator class for iterators (compares pointer values; why doesn't this work automatically?) More...
class | leaf_iterator
| Iterator which traverses only the leaves. More...
class | post_order_iterator
| Depth-first iterator, first accessing the children, then the node itself. More...
class | pre_order_iterator
| Depth-first iterator, first accessing the node, then its children. More...
class | sibling_iterator
| Iterator which traverses only the nodes which are siblings of each other. More...

## Public Types
typedef breadth_first_queued_iterator | breadth_first_iterator
typedef pre_order_iterator | iterator
| The default iterator types throughout the tree class. More...
typedef T | value_type
| Value of the data stored at a node. More...

## Public Member Functions
template<typename iter >
iter | append_child (iter position)
| Insert empty node as last/first child of node pointed to by position. More...
template<typename iter >
iter | append_child (iter position, const T &x)
| Insert node as last/first child of node pointed to by position. More...
template<typename iter >
iter | append_child (iter position, iter other_position)
| Append the node (plus its children) at other_position as last/first child of position. More...
template<typename iter >
iter | append_children (iter position, sibling_iterator from, sibling_iterator to)
| Append the nodes in the from-to range (plus their children) as last/first children of position. More...
pre_order_iterator | begin () const
| Return iterator to the beginning of the tree. More...
sibling_iterator | begin (const iterator_base &) const
| Return sibling iterator to the first child of given node. More...
breadth_first_queued_iterator | begin_breadth_first () const
| Return breadth-first iterator to the first node at a given depth. More...
fixed_depth_iterator | begin_fixed (const iterator_base &, unsigned int) const
| Return fixed-depth iterator to the first node at a given depth from the given iterator. More...
leaf_iterator | begin_leaf () const
| Return leaf iterator to the first leaf of the tree. More...
leaf_iterator | begin_leaf (const iterator_base &top) const
| Return leaf iterator to the first leaf of the subtree at the given node. More...
post_order_iterator | begin_post () const
| Return post-order iterator to the beginning of the tree. More...
void | clear ()
| Erase all nodes of the tree. More...
void | debug_verify_consistency () const
bool | empty () const
| Check if tree is empty. More...
pre_order_iterator | end () const
| Return iterator to the end of the tree. More...
sibling_iterator | end (const iterator_base &) const
| Return sibling end iterator for children of given node. More...
breadth_first_queued_iterator | end_breadth_first () const
| Return breadth-first end iterator. More...
fixed_depth_iterator | end_fixed (const iterator_base &, unsigned int) const
| Return fixed-depth end iterator. More...
leaf_iterator | end_leaf () const
| Return leaf end iterator for entire tree. More...
leaf_iterator | end_leaf (const iterator_base &top) const
| Return leaf end iterator for the subtree at the given node. More...
post_order_iterator | end_post () const
| Return post-order end iterator of the tree. More...
template<typename iter >
bool | equal (const iter &one, const iter &two, const iter &three) const
| Compare two ranges of nodes (compares nodes as well as tree structure). More...
template<typename iter , class BinaryPredicate >
bool | equal (const iter &one, const iter &two, const iter &three, BinaryPredicate) const
template<typename iter >
bool | equal_subtree (const iter &one, const iter &two) const
template<typename iter , class BinaryPredicate >
bool | equal_subtree (const iter &one, const iter &two, BinaryPredicate) const
template<typename iter >
iter | erase (iter)
| Erase element at position pointed to by iterator, return incremented iterator. More...
void | erase_children (const iterator_base &)
| Erase all children of the node pointed to by iterator. More...
template<typename iter >
iter | flatten (iter position)
| Move all children of node at 'position' to be siblings, returns position. More...
unsigned int | index (sibling_iterator it) const
| Determine the index of a node in the range of siblings to which it belongs. More...
template<typename iter >
iter | insert (iter position, const T &x)
| Insert node as previous sibling of node pointed to by position. More...
sibling_iterator | insert (sibling_iterator position, const T &x)
| Specialisation of previous member. More...
template<typename iter >
iter | insert_after (iter position, const T &x)
| Insert node as next sibling of node pointed to by position. More...
template<typename iter >
iter | insert_subtree (iter position, const iterator_base &subtree)
| Insert node (with children) pointed to by subtree as previous sibling of node pointed to by position. More...
template<typename iter >
iter | insert_subtree_after (iter position, const iterator_base &subtree)
| Insert node (with children) pointed to by subtree as next sibling of node pointed to by position. More...
bool | is_in_subtree (const iterator_base &position, const iterator_base &begin, const iterator_base &end) const
| Determine whether node at position is in the subtrees with root in the range. More...
bool | is_valid (const iterator_base &) const
| Determine whether the iterator is an 'end' iterator and thus not actually pointing to a node. More...
iterator | lowest_common_ancestor (const iterator_base &, const iterator_base &) const
int | max_depth () const
| Determine the maximal depth of the tree. An empty tree has max_depth=-1. More...
int | max_depth (const iterator_base &) const
| Determine the maximal depth of the tree with top node at the given position. More...
void | merge (sibling_iterator, sibling_iterator, sibling_iterator, sibling_iterator, bool duplicate_leaves=false)
| Merge with other tree, creating new branches and leaves only if they are not already present. More...
template<typename iter >
iter | move_after (iter target, iter source)
| Move 'source' node (plus its children) to become the next sibling of 'target'. More...
template<typename iter >
iter | move_before (iter target, iter source)
| Move 'source' node (plus its children) to become the previous sibling of 'target'. More...
sibling_iterator | move_before (sibling_iterator target, sibling_iterator source)
template<typename iter >
iter | move_ontop (iter target, iter source)
| Move 'source' node (plus its children) to become the node at 'target' (erasing the node at 'target'). More...
template<typename iter >
iter | next_at_same_depth (iter) const
| Return iterator to the next node at a given depth. More...
template<typename iter >
iter | next_sibling (iter) const
| Return iterator to the next sibling of a node. More...
unsigned int | number_of_siblings (const iterator_base &) const
| Count the number of siblings (left and right) of node at iterator. Total nodes at this level is +1. More...
tree< T, tree_node_allocator > & | operator= (const tree< T, tree_node_allocator > &)
template<typename iter >
iter | prepend_child (iter position)
template<typename iter >
iter | prepend_child (iter position, const T &x)
template<typename iter >
iter | prepend_child (iter position, iter other_position)
template<typename iter >
iter | prepend_children (iter position, sibling_iterator from, sibling_iterator to)
template<typename iter >
iter | previous_sibling (iter) const
| Return iterator to the previous sibling of a node. More...
template<typename iter >
iter | reparent (iter position, sibling_iterator begin, sibling_iterator end)
| Move nodes in range to be children of 'position'. More...
template<typename iter >
iter | reparent (iter position, iter from)
| Move all child nodes of 'from' to be children of 'position'. More...
template<typename iter >
iter | replace (iter position, const T &x)
| Replace node at 'position' with other node (keeping same children); 'position' becomes invalid. More...
template<typename iter >
iter | replace (iter position, const iterator_base &from)
| Replace node at 'position' with subtree starting at 'from' (do not erase subtree at 'from'); see above. More...
sibling_iterator | replace (sibling_iterator orig_begin, sibling_iterator orig_end, sibling_iterator new_begin, sibling_iterator new_end)
| Replace string of siblings (plus their children) with copy of a new string (with children); see above. More...
pre_order_iterator | set_head (const T &x)
| Short-hand to insert topmost node in otherwise empty tree. More...
sibling_iterator | sibling (const iterator_base &position, unsigned int)
| Return iterator to the sibling indicated by index. More...
size_t | size () const
| Count the total number of nodes. More...
size_t | size (const iterator_base &) const
| Count the total number of nodes below the indicated node (plus one). More...
void | sort (sibling_iterator from, sibling_iterator to, bool deep=false)
| Sort (std::sort only moves values of nodes, this one moves children as well). More...
template<class StrictWeakOrdering >
void | sort (sibling_iterator from, sibling_iterator to, StrictWeakOrdering comp, bool deep=false)
tree | subtree (sibling_iterator from, sibling_iterator to) const
| Extract a new tree formed by the range of siblings plus all their children. More...
void | subtree (tree &, sibling_iterator from, sibling_iterator to) const
void | swap (sibling_iterator it)
| Exchange the node (plus subtree) with its sibling node (do nothing if no sibling present). More...
void | swap (iterator, iterator)
| Exchange two nodes (plus subtrees) More...
| tree ()
| tree (const T &)
| tree (const iterator_base &)
| tree (const tree< T, tree_node_allocator > &)
template<typename iter >
iter | wrap (iter position, const T &x)
| Replace node with a new node, making the old node a child of the new node. More...
| ~tree ()

## Static Public Member Functions
static sibling_iterator | child (const iterator_base &position, unsigned int)
| Inverse of 'index': return the n-th child of the node at position. More...
static int | depth (const iterator_base &)
| Compute the depth to the root or to a fixed other iterator. More...
static int | depth (const iterator_base &, const iterator_base &)
static unsigned int | number_of_children (const iterator_base &)
| Count the number of children of node at position. More...
template<typename iter >
static iter | parent (iter)
| Return iterator to the parent of a node. More...

## Public Attributes
tree_node * | feet
tree_node * | head

## Protected Types
typedef tree_node_< T > | tree_node

## Private Member Functions
void | copy_ (const tree< T, tree_node_allocator > &other)
void | head_initialise_ ()

## Private Attributes
tree_node_allocator | alloc_

## Member Typedef Documentation

## ◆ breadth_first_iterator

template<class T, class tree_node_allocator = std::allocator<tree_node_<T> >>

typedef breadth_first_queued_iterator tree< T, tree_node_allocator >::breadth_first_iterator

## ◆ iterator

template<class T, class tree_node_allocator = std::allocator<tree_node_<T> >>

typedef pre_order_iterator tree< T, tree_node_allocator >::iterator

The default iterator types throughout the tree class.

## ◆ tree_node

template<class T, class tree_node_allocator = std::allocator<tree_node_<T> >>

typedef tree_node_<T> tree< T, tree_node_allocator >::tree_node
| protected

## ◆ value_type

template<class T, class tree_node_allocator = std::allocator<tree_node_<T> >>

typedef T tree< T, tree_node_allocator >::value_type

Value of the data stored at a node.

## Constructor & Destructor Documentation

## ◆ tree() [1/4]

template<class T , class tree_node_allocator >

tree< T, tree_node_allocator >::tree | ( |  | ) |

## ◆ tree() [2/4]

template<class T, class tree_node_allocator >

tree< T, tree_node_allocator >::tree | ( | const T & | x | ) |

## ◆ tree() [3/4]

template<class T, class tree_node_allocator >

tree< T, tree_node_allocator >::tree | ( | const iterator_base & | other | ) |

## ◆ tree() [4/4]

template<class T, class tree_node_allocator>

tree< T, tree_node_allocator >::tree | ( | const tree< T, tree_node_allocator > & | other | ) |

## ◆ ~tree()

template<class T , class tree_node_allocator >

tree< T, tree_node_allocator >::~tree | ( |  | ) |

## Member Function Documentation

## ◆ append_child() [1/3]

template<class T , class tree_node_allocator >
template<typename iter >

iter tree< T, tree_node_allocator >::append_child | ( | iter | position | ) |

Insert empty node as last/first child of node pointed to by position.

Referenced by tree< Origin::ProjectNode >::append_child(), tree< Origin::ProjectNode >::merge(), Origin810Parser::readProjectTreeFolder(), Origin750Parser::readProjectTreeFolder(), and tree< Origin::ProjectNode >::replace().

## ◆ append_child() [2/3]

template<class T, class tree_node_allocator >
template<class iter >

iter tree< T, tree_node_allocator >::append_child | ( | iter | position,
|  | const T & | x
| ) |  |

Insert node as last/first child of node pointed to by position.

## ◆ append_child() [3/3]

template<class T, class tree_node_allocator >
template<class iter >

iter tree< T, tree_node_allocator >::append_child | ( | iter | position,
|  | iter | other_position
| ) |  |

Append the node (plus its children) at other_position as last/first child of position.

## ◆ append_children()

template<class T , class tree_node_allocator >
template<class iter >

iter tree< T, tree_node_allocator >::append_children | ( | iter | position,
|  | sibling_iterator | from,
|  | sibling_iterator | to
| ) |  |

Append the nodes in the from-to range (plus their children) as last/first children of position.

## ◆ begin() [1/2]

template<class T , class tree_node_allocator >

tree< T, tree_node_allocator >::pre_order_iterator tree< T, tree_node_allocator >::begin | ( |  | ) | const
| inline

Return iterator to the beginning of the tree.

Referenced by tree< Origin::ProjectNode >::copy_(), tree< Origin::ProjectNode >::debug_verify_consistency(), tree< Origin::ProjectNode >::empty(), tree< Origin::ProjectNode >::equal_subtree(), tree< Origin::ProjectNode >::is_in_subtree(), tree< T, tree_node_allocator >::breadth_first_queued_iterator::operator++(), Origin750Parser::readProjectTree(), tree< Origin::ProjectNode >::reparent(), tree< Origin::ProjectNode >::size(), tree< Origin::ProjectNode >::sort(), tree< Origin::ProjectNode >::subtree(), and tree< Origin::ProjectNode >::tree().

## ◆ begin() [2/2]

template<class T , class tree_node_allocator >

tree< T, tree_node_allocator >::sibling_iterator tree< T, tree_node_allocator >::begin | ( | const iterator_base & | pos | ) | const

Return sibling iterator to the first child of given node.

## ◆ begin_breadth_first()

template<class T , class tree_node_allocator >

tree< T, tree_node_allocator >::breadth_first_queued_iterator tree< T, tree_node_allocator >::begin_breadth_first | ( |  | ) | const

Return breadth-first iterator to the first node at a given depth.

## ◆ begin_fixed()

template<class T , class tree_node_allocator >

tree< T, tree_node_allocator >::fixed_depth_iterator tree< T, tree_node_allocator >::begin_fixed | ( | const iterator_base & | pos,
|  | unsigned int | dp
| ) |  | const

Return fixed-depth iterator to the first node at a given depth from the given iterator.

## ◆ begin_leaf() [1/2]

template<class T , class tree_node_allocator >

tree< T, tree_node_allocator >::leaf_iterator tree< T, tree_node_allocator >::begin_leaf | ( |  | ) | const

Return leaf iterator to the first leaf of the tree.

## ◆ begin_leaf() [2/2]

template<class T , class tree_node_allocator >

tree< T, tree_node_allocator >::leaf_iterator tree< T, tree_node_allocator >::begin_leaf | ( | const iterator_base & | top | ) | const

Return leaf iterator to the first leaf of the subtree at the given node.

## ◆ begin_post()

template<class T , class tree_node_allocator >

tree< T, tree_node_allocator >::post_order_iterator tree< T, tree_node_allocator >::begin_post | ( |  | ) | const

Return post-order iterator to the beginning of the tree.

## ◆ child()

template<class T , class tree_node_allocator >

tree< T, tree_node_allocator >::sibling_iterator tree< T, tree_node_allocator >::child | ( | const iterator_base & | position,
|  | unsigned int | num
| ) |  |
| static

Inverse of 'index': return the n-th child of the node at position.

## ◆ clear()

template<class T , class tree_node_allocator >

void tree< T, tree_node_allocator >::clear | ( |  | ) |

Erase all nodes of the tree.

Referenced by tree< Origin::ProjectNode >::copy_(), and tree< Origin::ProjectNode >::~tree().

## ◆ copy_()

template<class T, class tree_node_allocator>

void tree< T, tree_node_allocator >::copy_ | ( | const tree< T, tree_node_allocator > & | other | ) |
| private

Referenced by tree< Origin::ProjectNode >::operator=(), and tree< Origin::ProjectNode >::tree().

## ◆ debug_verify_consistency()

template<class T , class tree_node_allocator >

void tree< T, tree_node_allocator >::debug_verify_consistency | ( |  | ) | const

For debugging only: verify internal consistency by inspecting all pointers in the tree (which will also trigger a valgrind error in case something got corrupted).

## ◆ depth() [1/2]

template<class T , class tree_node_allocator >

int tree< T, tree_node_allocator >::depth | ( | const iterator_base & | it | ) |
| static

Compute the depth to the root or to a fixed other iterator.

Referenced by Origin750Parser::readProjectTree().

## ◆ depth() [2/2]

template<class T , class tree_node_allocator >

int tree< T, tree_node_allocator >::depth | ( | const iterator_base & | it,
|  | const iterator_base & | root
| ) |  |
| static

## ◆ empty()

template<class T , class tree_node_allocator >

bool tree< T, tree_node_allocator >::empty | ( |  | ) | const

Check if tree is empty.

## ◆ end() [1/2]

template<class T , class tree_node_allocator >

tree< T, tree_node_allocator >::pre_order_iterator tree< T, tree_node_allocator >::end | ( |  | ) | const
| inline

Return iterator to the end of the tree.

Referenced by tree< T, tree_node_allocator >::iterator_base::begin(), tree< Origin::ProjectNode >::begin(), tree< Origin::ProjectNode >::copy_(), tree< Origin::ProjectNode >::debug_verify_consistency(), tree< Origin::ProjectNode >::empty(), tree< Origin::ProjectNode >::equal_subtree(), tree< Origin::ProjectNode >::is_in_subtree(), tree< T, tree_node_allocator >::breadth_first_queued_iterator::operator++(), Origin750Parser::readProjectTree(), tree< Origin::ProjectNode >::reparent(), tree< Origin::ProjectNode >::size(), tree< Origin::ProjectNode >::sort(), and tree< Origin::ProjectNode >::subtree().

## ◆ end() [2/2]

template<class T , class tree_node_allocator >

tree< T, tree_node_allocator >::sibling_iterator tree< T, tree_node_allocator >::end | ( | const iterator_base & | pos | ) | const

Return sibling end iterator for children of given node.

## ◆ end_breadth_first()

template<class T , class tree_node_allocator >

tree< T, tree_node_allocator >::breadth_first_queued_iterator tree< T, tree_node_allocator >::end_breadth_first | ( |  | ) | const

Return breadth-first end iterator.

## ◆ end_fixed()

template<class T , class tree_node_allocator >

tree< T, tree_node_allocator >::fixed_depth_iterator tree< T, tree_node_allocator >::end_fixed | ( | const iterator_base & | pos,
|  | unsigned int | dp
| ) |  | const

Return fixed-depth end iterator.

## ◆ end_leaf() [1/2]

template<class T , class tree_node_allocator >

tree< T, tree_node_allocator >::leaf_iterator tree< T, tree_node_allocator >::end_leaf | ( |  | ) | const

Return leaf end iterator for entire tree.

## ◆ end_leaf() [2/2]

template<class T , class tree_node_allocator >

tree< T, tree_node_allocator >::leaf_iterator tree< T, tree_node_allocator >::end_leaf | ( | const iterator_base & | top | ) | const

Return leaf end iterator for the subtree at the given node.

## ◆ end_post()

template<class T , class tree_node_allocator >

tree< T, tree_node_allocator >::post_order_iterator tree< T, tree_node_allocator >::end_post | ( |  | ) | const

Return post-order end iterator of the tree.

## ◆ equal() [1/2]

template<class T , class tree_node_allocator >
template<typename iter >

bool tree< T, tree_node_allocator >::equal | ( | const iter & | one,
|  | const iter & | two,
|  | const iter & | three
| ) |  | const

Compare two ranges of nodes (compares nodes as well as tree structure).

Referenced by tree< Origin::ProjectNode >::equal(), and tree< Origin::ProjectNode >::equal_subtree().

## ◆ equal() [2/2]

template<class T , class tree_node_allocator >
template<typename iter , class BinaryPredicate >

bool tree< T, tree_node_allocator >::equal | ( | const iter & | one,
|  | const iter & | two,
|  | const iter & | three,
|  | BinaryPredicate | fun
| ) |  | const

## ◆ equal_subtree() [1/2]

template<class T , class tree_node_allocator >
template<typename iter >

bool tree< T, tree_node_allocator >::equal_subtree | ( | const iter & | one,
|  | const iter & | two
| ) |  | const

Referenced by tree< Origin::ProjectNode >::equal_subtree().

## ◆ equal_subtree() [2/2]

template<class T , class tree_node_allocator >
template<typename iter , class BinaryPredicate >

bool tree< T, tree_node_allocator >::equal_subtree | ( | const iter & | one,
|  | const iter & | two,
|  | BinaryPredicate | fun
| ) |  | const

## ◆ erase()

template<class T , class tree_node_allocator >
template<class iter >

iter tree< T, tree_node_allocator >::erase | ( | iter | it | ) |

Erase element at position pointed to by iterator, return incremented iterator.

Referenced by tree< Origin::ProjectNode >::clear(), tree< Origin::ProjectNode >::move_ontop(), and tree< Origin::ProjectNode >::replace().

## ◆ erase_children()

template<class T , class tree_node_allocator >

void tree< T, tree_node_allocator >::erase_children | ( | const iterator_base & | it | ) |

Erase all children of the node pointed to by iterator.

Referenced by tree< Origin::ProjectNode >::erase(), tree< Origin::ProjectNode >::erase_children(), and tree< Origin::ProjectNode >::replace().

## ◆ flatten()

template<class T , class tree_node_allocator >
template<typename iter >

iter tree< T, tree_node_allocator >::flatten | ( | iter | position | ) |

Move all children of node at 'position' to be siblings, returns position.

## ◆ head_initialise_()

template<class T , class tree_node_allocator >

void tree< T, tree_node_allocator >::head_initialise_ | ( |  | ) |
| private

Referenced by tree< Origin::ProjectNode >::tree().

## ◆ index()

template<class T , class tree_node_allocator >

unsigned int tree< T, tree_node_allocator >::index | ( | sibling_iterator | it | ) | const

Determine the index of a node in the range of siblings to which it belongs.

## ◆ insert() [1/2]

template<class T, class tree_node_allocator >
template<class iter >

iter tree< T, tree_node_allocator >::insert | ( | iter | position,
|  | const T & | x
| ) |  |

Insert node as previous sibling of node pointed to by position.

Referenced by tree< Origin::ProjectNode >::copy_(), tree< Origin::ProjectNode >::insert_subtree(), tree< Origin::ProjectNode >::set_head(), and tree< Origin::ProjectNode >::wrap().

## ◆ insert() [2/2]

template<class T, class tree_node_allocator >

tree< T, tree_node_allocator >::sibling_iterator tree< T, tree_node_allocator >::insert | ( | sibling_iterator | position,
|  | const T & | x
| ) |  |

Specialisation of previous member.

## ◆ insert_after()

template<class T, class tree_node_allocator >
template<class iter >

iter tree< T, tree_node_allocator >::insert_after | ( | iter | position,
|  | const T & | x
| ) |  |

Insert node as next sibling of node pointed to by position.

Referenced by tree< Origin::ProjectNode >::insert_subtree_after().

## ◆ insert_subtree()

template<class T , class tree_node_allocator >
template<class iter >

iter tree< T, tree_node_allocator >::insert_subtree | ( | iter | position,
|  | const iterator_base & | subtree
| ) |  |

Insert node (with children) pointed to by subtree as previous sibling of node pointed to by position.

Referenced by tree< Origin::ProjectNode >::append_children(), tree< Origin::ProjectNode >::merge(), tree< Origin::ProjectNode >::prepend_children(), and tree< Origin::ProjectNode >::replace().

## ◆ insert_subtree_after()

template<class T , class tree_node_allocator >
template<class iter >

iter tree< T, tree_node_allocator >::insert_subtree_after | ( | iter | position,
|  | const iterator_base & | subtree
| ) |  |

Insert node (with children) pointed to by subtree as next sibling of node pointed to by position.

## ◆ is_in_subtree()

template<class T , class tree_node_allocator >

bool tree< T, tree_node_allocator >::is_in_subtree | ( | const iterator_base & | position,
|  | const iterator_base & | begin,
|  | const iterator_base & | end
| ) |  | const

Determine whether node at position is in the subtrees with root in the range.

## ◆ is_valid()

template<class T , class tree_node_allocator >

bool tree< T, tree_node_allocator >::is_valid | ( | const iterator_base & | it | ) | const

Determine whether the iterator is an 'end' iterator and thus not actually pointing to a node.

Referenced by tree< Origin::ProjectNode >::equal(), and tree< Origin::ProjectNode >::lowest_common_ancestor().

## ◆ lowest_common_ancestor()

template<class T , class tree_node_allocator >

tree< T, tree_node_allocator >::iterator tree< T, tree_node_allocator >::lowest_common_ancestor | ( | const iterator_base & | one,
|  | const iterator_base & | two
| ) |  | const

Find the lowest common ancestor of two nodes, that is, the deepest node such that both nodes are descendants of it.

## ◆ max_depth() [1/2]

template<class T , class tree_node_allocator >

int tree< T, tree_node_allocator >::max_depth | ( |  | ) | const

Determine the maximal depth of the tree. An empty tree has max_depth=-1.

Referenced by tree< Origin::ProjectNode >::max_depth().

## ◆ max_depth() [2/2]

template<class T , class tree_node_allocator >

int tree< T, tree_node_allocator >::max_depth | ( | const iterator_base & | pos | ) | const

Determine the maximal depth of the tree with top node at the given position.

## ◆ merge()

template<class T , class tree_node_allocator >

void tree< T, tree_node_allocator >::merge | ( | sibling_iterator | to1,
|  | sibling_iterator | to2,
|  | sibling_iterator | from1,
|  | sibling_iterator | from2,
|  | bool | duplicate_leaves = `false`
| ) |  |

Merge with other tree, creating new branches and leaves only if they are not already present.

Referenced by tree< Origin::ProjectNode >::merge().

## ◆ move_after()

template<class T , class tree_node_allocator >
template<typename iter >

iter tree< T, tree_node_allocator >::move_after | ( | iter | target,
|  | iter | source
| ) |  |

Move 'source' node (plus its children) to become the next sibling of 'target'.

## ◆ move_before() [1/2]

template<class T , class tree_node_allocator >
template<typename iter >

iter tree< T, tree_node_allocator >::move_before | ( | iter | target,
|  | iter | source
| ) |  |

Move 'source' node (plus its children) to become the previous sibling of 'target'.

## ◆ move_before() [2/2]

template<class T , class tree_node_allocator >

tree< T, tree_node_allocator >::sibling_iterator tree< T, tree_node_allocator >::move_before | ( | sibling_iterator | target,
|  | sibling_iterator | source
| ) |  |

## ◆ move_ontop()

template<class T , class tree_node_allocator >
template<typename iter >

iter tree< T, tree_node_allocator >::move_ontop | ( | iter | target,
|  | iter | source
| ) |  |

Move 'source' node (plus its children) to become the node at 'target' (erasing the node at 'target').

## ◆ next_at_same_depth()

template<class T , class tree_node_allocator >
template<typename iter >

iter tree< T, tree_node_allocator >::next_at_same_depth | ( | iter | position | ) | const

Return iterator to the next node at a given depth.

## ◆ next_sibling()

template<class T , class tree_node_allocator >
template<typename iter >

iter tree< T, tree_node_allocator >::next_sibling | ( | iter | position | ) | const

Return iterator to the next sibling of a node.

## ◆ number_of_children()

template<class T , class tree_node_allocator >

unsigned int tree< T, tree_node_allocator >::number_of_children | ( | const iterator_base & | it | ) |
| static

Count the number of children of node at position.

Referenced by tree< Origin::ProjectNode >::equal_subtree().

## ◆ number_of_siblings()

template<class T , class tree_node_allocator >

unsigned int tree< T, tree_node_allocator >::number_of_siblings | ( | const iterator_base & | it | ) | const

Count the number of siblings (left and right) of node at iterator. Total nodes at this level is +1.

## ◆ operator=()

template<class T, class tree_node_allocator>

tree< T, tree_node_allocator > & tree< T, tree_node_allocator >::operator= | ( | const tree< T, tree_node_allocator > & | other | ) |

## ◆ parent()

template<class T , class tree_node_allocator >
template<typename iter >

iter tree< T, tree_node_allocator >::parent | ( | iter | position | ) |
| static

Return iterator to the parent of a node.

Referenced by tree< Origin::ProjectNode >::lowest_common_ancestor(), tree< Origin::ProjectNode >::merge(), and tree< Origin::ProjectNode >::replace().

## ◆ prepend_child() [1/3]

template<class T , class tree_node_allocator >
template<typename iter >

iter tree< T, tree_node_allocator >::prepend_child | ( | iter | position | ) |

Referenced by tree< Origin::ProjectNode >::prepend_child().

## ◆ prepend_child() [2/3]

template<class T, class tree_node_allocator >
template<class iter >

iter tree< T, tree_node_allocator >::prepend_child | ( | iter | position,
|  | const T & | x
| ) |  |

## ◆ prepend_child() [3/3]

template<class T, class tree_node_allocator >
template<class iter >

iter tree< T, tree_node_allocator >::prepend_child | ( | iter | position,
|  | iter | other_position
| ) |  |

## ◆ prepend_children()

template<class T , class tree_node_allocator >
template<class iter >

iter tree< T, tree_node_allocator >::prepend_children | ( | iter | position,
|  | sibling_iterator | from,
|  | sibling_iterator | to
| ) |  |

## ◆ previous_sibling()

template<class T , class tree_node_allocator >
template<typename iter >

iter tree< T, tree_node_allocator >::previous_sibling | ( | iter | position | ) | const

Return iterator to the previous sibling of a node.

## ◆ reparent() [1/2]

template<class T , class tree_node_allocator >
template<typename iter >

iter tree< T, tree_node_allocator >::reparent | ( | iter | position,
|  | sibling_iterator | begin,
|  | sibling_iterator | end
| ) |  |

Move nodes in range to be children of 'position'.

Referenced by tree< Origin::ProjectNode >::reparent(), and tree< Origin::ProjectNode >::wrap().

## ◆ reparent() [2/2]

template<class T , class tree_node_allocator >
template<typename iter >

iter tree< T, tree_node_allocator >::reparent | ( | iter | position,
|  | iter | from
| ) |  |

Move all child nodes of 'from' to be children of 'position'.

## ◆ replace() [1/3]

template<class T, class tree_node_allocator >
template<class iter >

iter tree< T, tree_node_allocator >::replace | ( | iter | position,
|  | const T & | x
| ) |  |

Replace node at 'position' with other node (keeping same children); 'position' becomes invalid.

Referenced by tree< Origin::ProjectNode >::append_child(), tree< Origin::ProjectNode >::copy_(), tree< Origin::ProjectNode >::insert_subtree(), tree< Origin::ProjectNode >::insert_subtree_after(), tree< Origin::ProjectNode >::prepend_child(), tree< Origin::ProjectNode >::subtree(), and tree< Origin::ProjectNode >::tree().

## ◆ replace() [2/3]

template<class T, class tree_node_allocator >
template<class iter >

iter tree< T, tree_node_allocator >::replace | ( | iter | position,
|  | const iterator_base & | from
| ) |  |

Replace node at 'position' with subtree starting at 'from' (do not erase subtree at 'from'); see above.

## ◆ replace() [3/3]

template<class T , class tree_node_allocator >

tree< T, tree_node_allocator >::sibling_iterator tree< T, tree_node_allocator >::replace | ( | sibling_iterator | orig_begin,
|  | sibling_iterator | orig_end,
|  | sibling_iterator | new_begin,
|  | sibling_iterator | new_end
| ) |  |

Replace string of siblings (plus their children) with copy of a new string (with children); see above.

## ◆ set_head()

template<class T, class tree_node_allocator >

tree< T, tree_node_allocator >::pre_order_iterator tree< T, tree_node_allocator >::set_head | ( | const T & | x | ) |

Short-hand to insert topmost node in otherwise empty tree.

Referenced by tree< Origin::ProjectNode >::subtree(), and tree< Origin::ProjectNode >::tree().

## ◆ sibling()

template<class T , class tree_node_allocator >

tree< T, tree_node_allocator >::sibling_iterator tree< T, tree_node_allocator >::sibling | ( | const iterator_base & | position,
|  | unsigned int | num
| ) |  |

Return iterator to the sibling indicated by index.

## ◆ size() [1/2]

template<class T , class tree_node_allocator >

size_t tree< T, tree_node_allocator >::size | ( |  | ) | const

Count the total number of nodes.

## ◆ size() [2/2]

template<class T , class tree_node_allocator >

size_t tree< T, tree_node_allocator >::size | ( | const iterator_base & | top | ) | const

Count the total number of nodes below the indicated node (plus one).

## ◆ sort() [1/2]

template<class T , class tree_node_allocator >

void tree< T, tree_node_allocator >::sort | ( | sibling_iterator | from,
|  | sibling_iterator | to,
|  | bool | deep = `false`
| ) |  |

Sort (std::sort only moves values of nodes, this one moves children as well).

Referenced by tree< Origin::ProjectNode >::sort().

## ◆ sort() [2/2]

template<class T , class tree_node_allocator >
template<class StrictWeakOrdering >

void tree< T, tree_node_allocator >::sort | ( | sibling_iterator | from,
|  | sibling_iterator | to,
|  | StrictWeakOrdering | comp,
|  | bool | deep = `false`
| ) |  |

## ◆ subtree() [1/2]

template<class T , class tree_node_allocator >

tree< T, tree_node_allocator > tree< T, tree_node_allocator >::subtree | ( | sibling_iterator | from,
|  | sibling_iterator | to
| ) |  | const

Extract a new tree formed by the range of siblings plus all their children.

Referenced by tree< Origin::ProjectNode >::insert_subtree(), and tree< Origin::ProjectNode >::insert_subtree_after().

## ◆ subtree() [2/2]

template<class T , class tree_node_allocator >

void tree< T, tree_node_allocator >::subtree | ( | tree< T, tree_node_allocator > & | tmp,
|  | sibling_iterator | from,
|  | sibling_iterator | to
| ) |  | const

## ◆ swap() [1/2]

template<class T , class tree_node_allocator >

void tree< T, tree_node_allocator >::swap | ( | sibling_iterator | it | ) |

Exchange the node (plus subtree) with its sibling node (do nothing if no sibling present).

Referenced by tree< Origin::ProjectNode >::swap().

## ◆ swap() [2/2]

template<class T , class tree_node_allocator >

void tree< T, tree_node_allocator >::swap | ( | iterator | one,
|  | iterator | two
| ) |  |

Exchange two nodes (plus subtrees)

## ◆ wrap()

template<class T, class tree_node_allocator >
template<typename iter >

iter tree< T, tree_node_allocator >::wrap | ( | iter | position,
|  | const T & | x
| ) |  |

Replace node with a new node, making the old node a child of the new node.

## Member Data Documentation

## ◆ alloc_

template<class T, class tree_node_allocator = std::allocator<tree_node_<T> >>

tree_node_allocator tree< T, tree_node_allocator >::alloc_
| private

Referenced by tree< Origin::ProjectNode >::append_child(), tree< Origin::ProjectNode >::erase(), tree< Origin::ProjectNode >::erase_children(), tree< Origin::ProjectNode >::head_initialise_(), tree< Origin::ProjectNode >::insert(), tree< Origin::ProjectNode >::insert_after(), tree< Origin::ProjectNode >::prepend_child(), tree< Origin::ProjectNode >::replace(), and tree< Origin::ProjectNode >::~tree().

## ◆ feet

template<class T, class tree_node_allocator = std::allocator<tree_node_<T> >>

tree_node * tree< T, tree_node_allocator >::feet

Referenced by tree< Origin::ProjectNode >::append_child(), tree< Origin::ProjectNode >::append_children(), tree< Origin::ProjectNode >::begin_leaf(), tree< Origin::ProjectNode >::begin_post(), tree< Origin::ProjectNode >::clear(), tree< Origin::ProjectNode >::end(), tree< Origin::ProjectNode >::end_leaf(), tree< Origin::ProjectNode >::end_post(), tree< Origin::ProjectNode >::head_initialise_(), tree< Origin::ProjectNode >::insert(), tree< Origin::ProjectNode >::is_valid(), tree< Origin::ProjectNode >::max_depth(), tree< Origin::ProjectNode >::number_of_siblings(), tree< Origin::ProjectNode >::prepend_child(), tree< Origin::ProjectNode >::prepend_children(), tree< Origin::ProjectNode >::set_head(), and tree< Origin::ProjectNode >::~tree().

## ◆ head

template<class T, class tree_node_allocator = std::allocator<tree_node_<T> >>

tree_node* tree< T, tree_node_allocator >::head

Referenced by tree< Origin::ProjectNode >::append_child(), tree< Origin::ProjectNode >::append_children(), tree< Origin::ProjectNode >::begin(), tree< Origin::ProjectNode >::begin_breadth_first(), tree< Origin::ProjectNode >::begin_leaf(), tree< Origin::ProjectNode >::begin_post(), tree< Origin::ProjectNode >::clear(), tree< Origin::ProjectNode >::erase(), tree< Origin::ProjectNode >::head_initialise_(), tree< Origin::ProjectNode >::index(), tree< Origin::ProjectNode >::is_valid(), tree< Origin::ProjectNode >::max_depth(), tree< Origin::ProjectNode >::number_of_siblings(), tree< Origin::ProjectNode >::prepend_child(), tree< Origin::ProjectNode >::prepend_children(), tree< Origin::ProjectNode >::replace(), tree< Origin::ProjectNode >::set_head(), tree< Origin::ProjectNode >::sibling(), and tree< Origin::ProjectNode >::~tree().

The documentation for this class was generated from the following file:

- /build/liborigin2/src/liborigin2/tree.hh