Tree Compression with Top Trees Revisited
|
Ordered tree data structure. More...
#include <OrderedTree.h>
Public Types | |
typedef NodeType | nodeType |
the node type used in this tree More... | |
typedef EdgeType | edgeType |
the type of the edges used in this tree More... | |
Public Member Functions | |
OrderedTree (const int n=0, const int m=0) | |
OrderedTree (const OrderedTree< NodeType, EdgeType > &other) | |
EdgeType * | firstEdge () |
pointer to the dummy edge More... | |
EdgeType * | firstEdge (const int u) |
const EdgeType * | firstEdge (const int u) const |
EdgeType * | lastEdge () |
pointer to the last edge More... | |
EdgeType * | lastEdge (const int u) |
const EdgeType * | lastEdge (const int u) const |
int | nodeId (const NodeType *node) |
int | edgeId (const EdgeType *edge) |
int | addNode () |
int | addNodes (const int n) |
EdgeType * | addEdge (const int from, const int to, const int extraSpace=0) |
void | killNodes () |
void | removeEdge (const int from, const int edge, const bool compact=true) |
void | removeEdgeTo (const int from, const int to, const bool compact=true) |
void | mergeSiblings (const EdgeType *leftEdge, const EdgeType *rightEdge, int &newNode, MergeType &mergeType) |
void | mergeChain (const int middleId, MergeType &mergeType) |
template<typename LabelType > | |
bool | isEqual (const OrderedTree< NodeType, EdgeType > &other, LabelType &labels, LabelType &otherLabels, const bool verbose=false) const |
template<typename LabelType > | |
bool | nodesEqual (const OrderedTree< NodeType, EdgeType > &other, LabelType &labels, LabelType &otherLabels, const int nodeId, const int otherNodeId, const bool verbose=false) const |
Recursive node comparison helper function used by isEqual(). You should not need to use this directly. More... | |
string | summary () const |
A one-line summary of the tree. More... | |
string | shortString () const |
string | toString () const |
String representation of the tree, including all nodes and edges. More... | |
void | checkConsistency () |
void | compact (const bool verbose=true, const int factor=1) |
void | compactNode (const int nodeId) |
void | inplaceCompact (const bool verbose=true) |
void | inplaceCompact (std::vector< bool > &dirty, const bool verbose=true) |
template<typename T , typename Fold , typename Callback > | |
const T | foldLeftPostOrder (const Callback &callback, const Fold &fold, const T initial) const |
template<typename T , typename Fold , typename Callback > | |
const T | traverseFoldLeftPostOrder (const int nodeId, const Callback &callback, const Fold &fold, const T initial) const |
This does the work for foldLeftPostOrder() and should not be used directly. More... | |
int | height () const |
double | avgDepth () const |
void | clear () |
Public Attributes | |
std::vector< NodeType > | nodes |
std::vector< EdgeType > | edges |
int | _firstFreeNode |
int | _firstFreeEdge |
int | _numNodes |
int | _numEdges |
Protected Member Functions | |
void | initialise (const int n, const int m) |
EdgeType * | _prepareEdge (const int edgeId, const int from, const int to) |
Helper method for inserting new edges. More... | |
Friends | |
std::ostream & | operator<< (std::ostream &os, const OrderedTree< NodeType, EdgeType > &tree) |
Ordered tree data structure.
Holds an ordered tree
The tree is implemented as an adjacency array (See section 8.2 of http://people.mpi-inf.mpg.de/~mehlhorn/ftp/Toolbox/GraphRep.pdf)
You can define your own node and edge types, e.g. add labels to the nodes or values to the edges if you wish
Definition at line 37 of file OrderedTree.h.
typedef EdgeType OrderedTree< NodeType, EdgeType >::edgeType |
the type of the edges used in this tree
Definition at line 42 of file OrderedTree.h.
typedef NodeType OrderedTree< NodeType, EdgeType >::nodeType |
the node type used in this tree
Definition at line 40 of file OrderedTree.h.
|
inline |
Definition at line 44 of file OrderedTree.h.
|
inline |
Definition at line 48 of file OrderedTree.h.
|
inlineprotected |
Helper method for inserting new edges.
Definition at line 613 of file OrderedTree.h.
|
inline |
Add an edge to the tree
from | tail (source) node ID |
to | head (destination) node ID |
extraSpace | extra space to allocate for more outgoing edges of 'from' if more edges need to be allocated |
Definition at line 130 of file OrderedTree.h.
|
inline |
|
inline |
Add multiple nodes
n | the number of nodes to add |
Definition at line 118 of file OrderedTree.h.
|
inline |
Calculate the average depth of the nodes in the tree. Uses foldLeftPostOrder() and worth looking at as slightly more complex example for a fold
Definition at line 579 of file OrderedTree.h.
|
inline |
Perform a few consistency checks. NOP if NDEBUG is set
Definition at line 400 of file OrderedTree.h.
|
inline |
Definition at line 587 of file OrderedTree.h.
|
inline |
Compress the edge vector, removing gaps
verbose | whether to print some debug information |
factor | how many times the number of its outgoing edges a node's edge space shall be allocated. If you set this to 2, for example, space for another edge will be reserved for each edge that there is, so that inserting an edge does not cause moving or reallocation. |
Definition at line 418 of file OrderedTree.h.
|
inline |
Definition at line 461 of file OrderedTree.h.
|
inline |
Get edge ID from pointer
edge | an edge pointer |
Definition at line 99 of file OrderedTree.h.
|
inline |
pointer to the dummy edge
Definition at line 57 of file OrderedTree.h.
|
inline |
Pointer to a node's first edge. Does not check whether the node actually has outgoing edges.
u | a node ID (index in the node vector) |
Definition at line 63 of file OrderedTree.h.
|
inline |
const pointer to a node's first edge. Does not check whether the node actually has outgoing edges.
u | a node ID (index in the node vector) |
Definition at line 69 of file OrderedTree.h.
|
inline |
Perform a left fold over each node's children in post-order
callback | a callback to be called for each node with the result of the last fold operation |
fold | the fold function. Parameters: previous value, current value |
initial | inital value for the first folding |
Definition at line 553 of file OrderedTree.h.
|
inline |
Calculate the height of the tree (i.e., the maximum depth of a node). Uses foldLeftPostOrder() and worth looking at as a simple example of a fold
Definition at line 571 of file OrderedTree.h.
|
inlineprotected |
Initialise the tree
n | number of nodes to reserve space for |
m | number of edges to reserve space for |
Definition at line 595 of file OrderedTree.h.
|
inline |
Do an inplace compaction of each node's vertices This is faster than rebuilding compaction.
Definition at line 483 of file OrderedTree.h.
|
inline |
Do an inplace compaction of only the dirty vertices This is faster than rebuilding compaction.
Definition at line 515 of file OrderedTree.h.
|
inline |
Check whether this tree is equal to another tree.
other | the other tree |
labels | the labels for this tree. Label type is kept very general deliberately |
otherLabels | the other tree's labels |
verbose | whether to print an error traceback if the trees are not equal |
Definition at line 313 of file OrderedTree.h.
|
inline |
Definition at line 182 of file OrderedTree.h.
|
inline |
pointer to the last edge
Definition at line 74 of file OrderedTree.h.
|
inline |
Pointer to a node's last edge. Does not check wether the node actually has outgoing edges.
u | a node ID (index in the node vector) |
Definition at line 80 of file OrderedTree.h.
|
inline |
const ointer to a node's last edge. Does not check wether the node actually has outgoing edges.
u | a node ID (index in the node vector) |
Definition at line 86 of file OrderedTree.h.
|
inline |
Merge two chained edges like this: a -> b -> c will become a -> b, where b and c are the only children of their parents. Any potential children of c will be attached to b.
middleId | the middle node's ID in this merge (b in the example) |
mergeType | will be set to the type of the merge performed |
Definition at line 279 of file OrderedTree.h.
|
inline |
Merge two descendants of the same node (i.e., siblings)
leftEdge | pointer to the edge leading to the left child |
rightEdge | pointer to the edge leading to the right edge |
newNode | will hold the ID of the merged node after this function returns |
mergeType | will hold the type of the merge that was done after this returns |
Definition at line 242 of file OrderedTree.h.
|
inline |
Get node ID from pointer
node | a node pointer |
Definition at line 93 of file OrderedTree.h.
|
inline |
Recursive node comparison helper function used by isEqual(). You should not need to use this directly.
Definition at line 322 of file OrderedTree.h.
|
inline |
Remove an edge from the tree
from | the edge's tail (source) node |
edge | the edge's ID |
compact | whether to consolidate 'from's outgoing edges |
Definition at line 193 of file OrderedTree.h.
|
inline |
Remove an edge between to nodes from the tree. Finds and removes the first edge from 'from' to 'to'
from | tail (source) node ID |
to | head (destination) node ID |
compact | wether to consolidate 'from's outgoing edges after removal |
Definition at line 226 of file OrderedTree.h.
|
inline |
A rather compact representation of the tree as a string. Comprises nodes with children or a parent, and valid edges. Format: " ID/(node or edge)"
Definition at line 357 of file OrderedTree.h.
|
inline |
A one-line summary of the tree.
Definition at line 348 of file OrderedTree.h.
|
inline |
String representation of the tree, including all nodes and edges.
Definition at line 373 of file OrderedTree.h.
|
inline |
This does the work for foldLeftPostOrder() and should not be used directly.
Definition at line 559 of file OrderedTree.h.
|
friend |
Definition at line 386 of file OrderedTree.h.
int OrderedTree< NodeType, EdgeType >::_firstFreeEdge |
Definition at line 628 of file OrderedTree.h.
int OrderedTree< NodeType, EdgeType >::_firstFreeNode |
Definition at line 627 of file OrderedTree.h.
int OrderedTree< NodeType, EdgeType >::_numEdges |
Definition at line 630 of file OrderedTree.h.
int OrderedTree< NodeType, EdgeType >::_numNodes |
Definition at line 629 of file OrderedTree.h.
std::vector<EdgeType> OrderedTree< NodeType, EdgeType >::edges |
Definition at line 626 of file OrderedTree.h.
std::vector<NodeType> OrderedTree< NodeType, EdgeType >::nodes |
Definition at line 625 of file OrderedTree.h.