-
Notifications
You must be signed in to change notification settings - Fork 1
/
SortingData.h
116 lines (99 loc) · 3.75 KB
/
SortingData.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
#pragma once
/**
* SortingData.h
* @author: Kevin German
**/
#include <mutex>
#include <chrono>
#include "settings.h"
class SortingData
{
mutable std::mutex mMutex; //mutex for protecting the internal data from race conditions
std::chrono::nanoseconds mAssignmentDelay{ defaultAssignmentDelay }; //artificial delay for assignments
std::chrono::nanoseconds mCompareDelay{ defaultCompareDelay }; //artificial delay for comparisons
bool mRecentlyAssigned{ false }; //true if recently assigned
mutable bool mRecentlyCompared{false}; //true if recently compared
bool mVerificationEnabled{ false }; //used for visualizing the verification process
public:
int mKey{0};//key used for comparisons
/**
* @brief constructor
* @param key: int key for comparisons
**/
explicit SortingData(const int key) : mKey(key) {}
/**
* @brief move constructor
* @param other: SortingData rvalue
**/
SortingData(SortingData&& other) noexcept;
/**
* @brief copy constructor
* @param other: SortingData reference
**/
SortingData(const SortingData& other);
/**
* @brief default constructor
**/
SortingData() = default;
/**
* @brief default destructor
**/
~SortingData() = default;
/**
* @brief classic comparison operator '<'. modifies internal state of booth object (despite constness) and has a artificial delay build in (mCompareDelay)
* @param other: reference to the object on the right side of '<'
* @return true if this->mKey < other.mKey
* @note modifies internal state of both objects. The fake constness is necessary for some algorithms in the stl (like std::inplace_merge)
**/
bool operator<(const SortingData& other) const;
/**
* @brief classic bitwise operator
* @param other: int used for bitwise operation
* @return int mKey & other
**/
int operator&(int other) const;
/**
* @brief assignment operator '=' with artificial delay(mAssignmentDelay)
* @param other: SortingData
* @return reference to this object
**/
SortingData& operator=(const SortingData & other);
/**
* @brief move assignment operator '=' without artificial delay(mAssignmentDelay)
* @param other SortingData rvalue
* @return reference to this object
**/
SortingData& operator=(SortingData &&other);
/**
* @brief increment operator (prefix). neded for std::iota
* @return reference to this object
**/
SortingData& operator++();
/**
* @brief check if this object was recently compared (used for visualizing comparison operations)
* @return true if object was compared and modify state back to not compared
**/
bool compared();
/**
* @brief check if this object was recently assigned (used for visualizing assignment operations)
* @return true if object was assigned recently and modify state back to not assigned
**/
bool assigned();
/**
* @brief enable verification mode. if enabled all calls to compared() and assigned() will not modify the state back to not compared.
* Resets assigned and compare flag as well and increases the time needed for comparisons (looks better in visualization process)
* @return void
**/
void enableVerification(bool enable);
/**
* @brief check if verification mode is enabled
* @return true if verification mode is enabled
**/
bool verificationEnabled() const;
/**
* @brief classic comparison operator '<'. modifies internal state of booth object (despite constness) and has a artificial delay build in (mCompareDelay)
* @param compareDelay: std::chrono::nanoseconds. Sets minimum time needed for comparisions to this value
* @param assignmentDelay: std::chrono::nanoseconds. Sets minimum time needed for assignments to this value
**/
void setDelay(std::chrono::nanoseconds compareDelay, std::chrono::nanoseconds assignmentDelay);
};