-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDoubleSorter.h
49 lines (41 loc) · 1.1 KB
/
DoubleSorter.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
#pragma once
#include <string>
#include <vector>
namespace MyLib {
class DoubleSorter
{
public:
enum class Order {
ascending,
descending
};
private:
static const size_t fiveMegabytesInBytes = 1024 * 1024 * 5;
static const size_t tenMegabytesInBytes = 2 * fiveMegabytesInBytes;
static const size_t rowsCount = 1;
static const size_t halfRowsCount = 2;
private:
size_t quantity;
size_t partsCount;
size_t rowSize;
size_t halfRowSize;
size_t iterationsCount;
size_t dummyQuantity;
Order order;
std::string inputTextFileName;
std::string outputTextFileName;
std::string tempSrcByteFileName;
std::string tempDestByteFileName;
public:
// maxRamUsageInBytes == -1 means that algorithm can use as much memory as needed
DoubleSorter(const std::string& inputTextFileName, const std::string& outputTextFileName, Order order = Order::ascending, int maxRamUsageInBytes = -1);
private:
bool compare(double a, double b);
void appendDummiesToByteFile();
void translateTextFileToByteFile();
void mergeSort();
void translateByteFileToTextFile();
public:
void sort();
};
}