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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140 | #pragma once
#include <string><--- Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include "snippet/aliases.hpp"
#include "debugger/debug.hpp"
namespace uni {
namespace internal {
template<class Derived, class Core, bool LEAF_ONLY>
struct dumpable_tree {
private:
using node_handler = Core::node_handler;
using node_pointer = Core::node_pointer;
using size_type = Core::size_type;
inline auto _push(const node_pointer& tree) {
return static_cast<Derived*>(this)->_impl.push(tree);
// return static_cast<Derived*>(this)->push(tree);
}
public:
debugger::debug_t dump_rich(node_pointer tree, const std::string prefix, const int dir, size_type& index)<--- Function parameter 'prefix' should be passed by const reference.
requires (!LEAF_ONLY)
{
if(!tree || tree == node_handler::nil) return prefix + "\n";
this->_push(tree);
// debug(tree->priority >= tree->left->priority, tree->priority, tree->left->priority);
// debug(tree->priority >= tree->right->priority, tree->priority, tree->right->priority);
assert(tree->priority >= tree->left->priority);
assert(tree->priority >= tree->right->priority);
const auto left = this->dump_rich(tree->left, prefix + (dir == 1 ? "| " : " "), -1, index);
const auto here =
prefix + "--+ [" +
debugger::dump(index) + ", " + debugger::dump(index + tree->length) + ") : " +
"<" + debugger::dump(tree->priority) + "> " +
debugger::dump(tree->data) + " [" + debugger::dump(tree->length) + "]\n";
index += tree->length;
const auto right = this->dump_rich(tree->right, prefix + (dir == -1 ? "| " : " "), 1, index);
return left + here + right;
}
debugger::debug_t dump_rich(node_pointer tree, const std::string prefix, const int dir, size_type& index)<--- Function parameter 'prefix' should be passed by const reference.
requires
(
LEAF_ONLY &&
requires {
typename Core::node_colors;
}
)
{
if(!tree || tree == node_handler::nil) return prefix + "\n";
this->_push(tree);
const auto left = this->dump_rich(tree->left, prefix + (dir == 1 ? "| " : " "), -1, index);
const auto right = this->dump_rich(tree->right, prefix + (dir == -1 ? "| " : " "), 1, index);
const auto color = tree->color == Core::node_colors::BLACK ? "<->" : "<+>";
const auto here = [&]() -> std::string {
if(tree->is_leaf()) {
index += tree->size;
return
prefix + "--+ [" +
debugger::dump(index - tree->size) + ", " + debugger::dump(index) + ") : " +
debugger::COLOR_STRING + color + debugger::COLOR_INIT + " " +
debugger::dump(tree->data) + " [" + debugger::dump(tree->size) + "]\n";
}
return "";
}();
return left + here + right;
}
inline debugger::debug_t dump_rich(const node_pointer& tree, const std::string prefix = " ", const int dir = 0) {<--- Function parameter 'prefix' should be passed by const reference.
size_type index = 0;
return this->dump_rich(tree, prefix, dir, index);
}
debugger::debug_t _debug(node_pointer tree)
requires (!LEAF_ONLY)
{
if(!tree || tree == node_handler::nil) return "";
this->_push(tree);
return
"(" +
this->_debug(tree->left) + " " +
debugger::dump(tree->data) + " [" +
debugger::dump(tree->length) + "] " +
this->_debug(tree->right) +
")";
}
debugger::debug_t _debug(node_pointer tree)
requires LEAF_ONLY
{
if(!tree || tree == node_handler::nil) return "";
this->_push(tree);
return
"(" +
this->_debug(tree->left) + " " +
(
tree->is_leaf()
?
debugger::dump(tree->data) + " [" +
debugger::dump(tree->size) + "] "
:
""
) +
this->_debug(tree->right) +
")";
}
};
} // namespace internal
} // namespace uni
|