-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
39 lines (32 loc) · 1.15 KB
/
main.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
#include "FileSplitter.h"
#include "FileMerger.h"
#include <iostream>
using namespace external_sort;
int main(int argc, const char* argv[]) {
if (argc < 3) {
std::cout << "Not enough parameters. Example usage: external_sort file_for_sort.txt sorted.txt\n";
return -1;
}
try {
FileSplitter splitter(argv[1]);
FileWrapper outFile(argv[2], false);
static_assert(MAX_SORTED_SIZE > 0, "Limit size of part of file can't be zero");
static_assert(MAX_SORTED_SIZE <= 1024, "Limit size of part of file too big");
#ifdef DEBUG_MERGE
const auto partSize = 300;
#else
const auto partSize = MAX_SORTED_SIZE * 1024L * 1024L;
#endif
std::cout << "Start file " << argv[1] << " splitting...\n";
splitter.Split(partSize, [&outFile, &argv](FileSplitter::SplitIterator begin, FileSplitter::SplitIterator end) {
std::cout << "Start merge files to destination " << argv[2] << std::endl;
MergeSortedTo(begin, end, outFile);
});
std::cout << "Finished\n";
return 0;
}
catch(const std::exception& error) {
std::cout << "Error: " << error.what() << std::flush;
return -1;
}
}