-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.h
72 lines (50 loc) · 1.35 KB
/
util.h
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
#pragma once
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <cstdlib>
#include "forest.h"
std::vector<std::string> splitString(const std::string& s, char sep);
inline char *duplicate_string(const std::string& s)
{
char *ptr = new char [s.size()+1];
strcpy(ptr, s.c_str());
return ptr;
}
template <typename keyT>
void dump(node<keyT> &n, std::ostream& out = std::cerr, int ident=0) {
for (int i=0; i < ident; i++)
out << " ";
out << "| " << n << "," << n.getCounter() << std::endl;
for (auto& child : n)
dump(child, out, ident+1);
}
template <typename keyT>
void dump(forest<keyT> &forest, std::ostream& out = std::cerr) {
for (auto& tree : forest) {
if (!tree.getParentRef())
dump(tree, out, 0);
out << std::endl << std::endl;
}
}
template <typename keyT>
void nodeDump(node<keyT> n, std::ostream& out) {
node<keyT> *ptr = &n;
out << "\"" << n << "," << n.getCounter();
out << " (";
if (ptr->getParentRef()) {
out << *ptr->getParentRef();
ptr = ptr->getParentRef();
while (ptr->getParentRef()) {
out << ",";
out << *ptr->getParentRef();
ptr=ptr->getParentRef();
}
} else {
out << "(null)";
}
out << ") ";
out << "\"";
}