-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtree_gen.h
More file actions
68 lines (59 loc) · 1.99 KB
/
tree_gen.h
File metadata and controls
68 lines (59 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* Sergeev Artemiy, 33601/2 (3057/2) */
#ifndef _TREE_GEN_H_
#define _TREE_GEN_H_
#include <stdio.h>
/* Unique layout of rooted tree representation class.
* Comment: layout of tree is the lexicographically greatest
* distance sequence L(T, z) = [l1, l2, ..., ln], where
* li is a distance from the i-th vertex to root 'z' */
class tree_layout
{
protected:
unsigned int *labels; // Array of vertices labels (distance to root)
unsigned int labelsCount;
public:
/* Default class constructor */
tree_layout( unsigned int verticesCount );
/* Copying constructor */
tree_layout( const tree_layout &layout );
/* Class destructor */
~tree_layout( void )
{
if (labels)
delete[] labels;
labelsCount = 0;
}
/* Allow to get and set 'index'-th label from layout function */
unsigned int & operator[]( unsigned int index )
{
return labels[index % labelsCount];
}
/* Return size of labels array (count of vertices in tree) function */
unsigned int size( void ) const
{
return labelsCount;
}
/* Search a maximum vertex label in 'labels' array function */
unsigned int max( void ) const;
/* Assignment new layout operator */
tree_layout & operator=( const tree_layout &layout );
/* Check tree for n-path rooted case function */
bool isSimple( void ) const;
/* Calculate height of left subtree function */
unsigned int leftHeight( void ) const;
};
/* Compare two layouts with equal vertices count operator (compare lexicographically) */
bool operator<=( tree_layout &layout1, tree_layout &layout2 );
/* Check non-equal operator */
bool operator!=( tree_layout &layout1, tree_layout &layout2 );
/* Generator new layout helpful class */
class tree_generator
{
public:
/* Construct new layout from some layout function.
* (input) p - index of label for start */
static tree_layout successor( tree_layout &layout, unsigned int p = 0 );
/* Build next tree layout by some layout */
static tree_layout buildLayout( tree_layout &layout );
};
#endif /* _TREE_GEN_H_ */