-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsubtree_comparison.hpp
64 lines (39 loc) · 1.47 KB
/
subtree_comparison.hpp
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
#include "cpprofiler/analysis/subtree_comp_win.hh"
#include "nodetree.hh"
#include <thread>
#include <chrono>
using cpprofiler::analysis::SubtreeCompWindow;
namespace subtree_comparison {
static void compareExecutions(Execution& ex, const Execution& ex1,
const Execution& ex2) {
/// ** construct a tree out of nodes from ex1 and ex2 **
// std::this_thread::sleep_for(std::chrono::milliseconds(1000));
/// target
auto& nt = ex.nodeTree();
auto& na = nt.getNA();
auto* root = nt.getRoot();
/// create two children and copy the trees into them
utils::addChildren(root, nt, 2);
auto* l_child = root->getChild(na, 0);
auto* r_child = root->getChild(na, 1);
/// left source
const auto* l_root_s = ex1.nodeTree().getRoot();
/// right source
const auto* r_root_s = ex2.nodeTree().getRoot();
utils::copyTree(l_child, nt, l_root_s, ex1.nodeTree());
utils::copyTree(r_child, nt, r_root_s, ex2.nodeTree());
/// maps nodes to execution id
std::unique_ptr<std::unordered_map<VisualNode*, int>> node2ex_id;
node2ex_id.reset(new std::unordered_map<VisualNode*, int>());
utils::applyToEachNode(nt, l_child, [&node2ex_id](VisualNode* n){
(*node2ex_id)[n] = 0;
});
utils::applyToEachNode(nt, r_child, [&node2ex_id](VisualNode* n){
(*node2ex_id)[n] = 1;
});
(*node2ex_id)[root] = 3;
/// run similar subtree analysis
auto shapes_window = new SubtreeCompWindow{ex, std::move(node2ex_id)};
shapes_window->show();
}
}