forked from TUfischl/newdetkdecomp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGlobals.h
117 lines (92 loc) · 2.27 KB
/
Globals.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
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
#pragma once
#if !defined(CLS_GLOBALS)
#define CLS_GLOBALS
#include<string>
#include<vector>
using namespace std;
using uint = unsigned int;
/*
struct ComponentHash {
size_t operator()(const Vertex *c) const;
size_t operator()(const Hyperedge *c) const;
};
using VE_VEC = vector<Vertex *>;
using VE_SET = unordered_set<Vertex *,ComponentHash>;
using HE_VEC = vector<Hyperedge *>;
using HE_SET = unordered_set<Hyperedge *,ComponentHash>;
*/
// Writes an error message to the standard error output stream
void writeErrorMsg(const string& cMessage, const string& cLocation, bool bExitProgram = true);
// Sorts an array of pointers in non-decreasing order according to a given int array
void sortPointers(void **Ptr, int *iEval, int iL, int iR);
// Returns a random integer between iLB and iUB
int random_range(int iLB, int iUB);
// Converts an unsigned integer number into a string
char *uitoa(unsigned int iNumber, char *cString);
template<class T>
struct Iterable
{
T _begin;
T _end;
Iterable(T begin, T end)
: _begin(begin), _end(end)
{}
T begin()
{
return _begin;
}
T end()
{
return _end;
}
};
template<class T>
Iterable<T> make_iterable(T t, T u)
{
return Iterable<T>(t, u);
}
template<typename T>
void sortVectors(vector<T> &Ptr, vector<int> &iEval, int iL, int iR)
{
int i = iL - 1, j = iR;
T pTmp;
int iTmp;
if (iR - iL > 200) { // Quicksort
while (true) {
while (iEval[++i] < iEval[iR]);
while (iEval[--j] > iEval[iR]);
if (i >= j) break;
// Swap valuation entries
iTmp = iEval[i];
iEval[i] = iEval[j];
iEval[j] = iTmp;
// Swap pointers
pTmp = Ptr[i];
Ptr[i] = Ptr[j];
Ptr[j] = pTmp;
}
// Swap valuation entries
iTmp = iEval[i];
iEval[i] = iEval[iR];
iEval[iR] = iTmp;
// Swap pointers
pTmp = Ptr[i];
Ptr[i] = Ptr[iR];
Ptr[iR] = pTmp;
sortVectors<T>(Ptr, iEval, iL, i - 1);
sortVectors<T>(Ptr, iEval, i + 1, iR);
}
else { // Insertion sort
for (i = iL + 1; i <= iR; i++) {
iTmp = iEval[i];
pTmp = Ptr[i];
for (j = i - 1; (j >= iL) && (iTmp < iEval[j]); j--) {
iEval[j + 1] = iEval[j];
Ptr[j + 1] = Ptr[j];
}
iEval[j + 1] = iTmp;
Ptr[j + 1] = pTmp;
}
}
}
#endif