-
Notifications
You must be signed in to change notification settings - Fork 2
/
resultvector.cpp
105 lines (88 loc) · 1.55 KB
/
resultvector.cpp
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
#include "resultvector.h"
#include <algorithm>
void ResultVector::flush()
{
for(auto i = size_t{0}; i < index; ++i)
{
vectors[cache[i]] += 1;
}
index = 0;
}
void ResultVector::addToDepth(long depth)
{
++execution_count;
if(index < CACHESIZE)
{
cache[index++] = depth;
}
else
{
vectors[depth] += 1;
flush();
}
}
long ResultVector::getExecutionCount()
{
return execution_count;
}
long ResultVector::readDepthCount(long depth)
{
flush();
return vectors[depth];
}
const bool ResultVector::isSingle()
{
flush();
if( vectors.size() == 1)
return true;
return false;
}
const bool ResultVector::isZero()
{
flush();
if( vectors.size() == 0)
return true;
return false;
}
inline bool sortBySecond(pair<long,long> i, pair<long,long> j)
{
return(i.second > j.second);
}
inline bool sortByFirst(pair<long,long> i, pair<long,long> j)
{
return(i.first < j.first);
}
void ResultVector::sortedVectors(vector<pair<long,long> > &sorted_vectors)
{
flush();
for(auto rawv : vectors)
{
sorted_vectors.push_back(std::make_pair(rawv.first,rawv.second));
}
std::sort(sorted_vectors.begin(), sorted_vectors.end(), sortByFirst);
}
bool ResultVector::vectorsGreater(int minVector)
{
flush();
for(auto timeit = vectors.begin(); timeit != vectors.end(); ++timeit)
{
if(timeit->second > minVector)
{
return true;
}
}
return false;
}
void ResultVector::clear()
{
vectors.clear();
execution_count = 0;
index = 0;
}
void ResultVector::printVector(FILE *out)
{
for(auto vec : vectors)
{
fprintf(out, "<%ld,%ld>", vec.first, vec.second);
}
}