-
Notifications
You must be signed in to change notification settings - Fork 0
/
fibheapbenchmark.cpp
103 lines (84 loc) · 2.33 KB
/
fibheapbenchmark.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
#include "fibheapbenchmark.h"
FibHeapBenchmark::FibHeapBenchmark(int nodesAlloc) : FibHeapBase(), aloccSize(nodesAlloc), resetCount(0), upCount(0)
{
array = new FNode*[aloccSize];
}
FibHeapBenchmark::~FibHeapBenchmark()
{
for(int i=0; i<aloccSize; ++i)
{
delete array[i];
}
delete[] array;
}
void FibHeapBenchmark::GenerateWorsCase(int randRange) // using vector for the speed
{
QTime mid(0,0,0);
qsrand( mid.secsTo(QTime::currentTime()) );
int randomNumber = 0;
for(int i = 0; i < aloccSize; ++i)
{
randomNumber = (qrand() % randRange)+1; // ne zelimo kljuca ki je manjsi od ena
array[i] = this->Insert(randomNumber);//new FNode(randomNumber);//this->Insert(randomNumber);
}
}
void FibHeapBenchmark::ResetWorsCase(int randRange) // using vector for the speed
{
this->n = 0;
this->min = 0;
// this->LastNode = 0;
++resetCount;
QTime mid(0,0,0);
qsrand( mid.secsTo(QTime::currentTime()) );
int numNodes = aloccSize-resetCount;
for(int i = 0; i < numNodes; ++i)
{
array[i]->reset((qrand() % randRange)+1); // ne zelimo kljuca ki je manjsi od ena
this->Insert(array[i]);
}
}
bool FibHeapBenchmark::WorsCaseOneUp(int randRange)
{
if(aloccSize < upCount)
return false; // the bechmarking is finished
this->n = 0;
this->min = 0;
// this->LastNode = 0;
QTime mid(0,0,0);
qsrand( mid.secsTo(QTime::currentTime()) );
for(int i = 0; i < upCount; ++i)
{
array[i]->reset((qrand() % randRange)+1); // ne zelimo kljuca ki je manjsi od ena
this->Insert(array[i]);
}
array[upCount++] = this->Insert( (qrand() % randRange)+1 );
return true;
}
bool FibHeapBenchmark::WorsCaseUp(int randRange)
{
if(aloccSize == upCount)
return false; // the bechmarking is finished
this->n = 0;
this->min = 0;
// this->LastNode = 0;
++upCount;
QTime mid(0,0,0);
qsrand( mid.secsTo(QTime::currentTime()) );
for(int i = 0; i < upCount; ++i)
{
array[i]->reset((qrand() % randRange)+1); // ne zelimo kljuca ki je manjsi od ena
this->Insert(array[i]);
}
return true;
}
void FibHeapBenchmark::initNodes()
{
for(int i=0; i<aloccSize; ++i)
{
array[i] = new FNode(0);
}
}
void FibHeapBenchmark::upCountReset()
{
upCount = 0;
}