-
Notifications
You must be signed in to change notification settings - Fork 0
/
AoAHW3ApplicationDelegate.cpp
91 lines (55 loc) · 2.02 KB
/
AoAHW3ApplicationDelegate.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
//
// AoAHW3ApplicationDelegate.cpp
// AoAHW3
//
// Created by Buğra Ekuklu on 04.11.2016.
// Copyright © 2016 The Digital Warehouse. All rights reserved.
//
#include "AoAHW3ApplicationDelegate.hpp"
#include <cassert>
#include <algorithm>
#include <string>
#include <sstream>
#include <iostream>
#include <cstdlib>
#include <chrono>
#include <fstream>
#include "Models/DOMElement.hpp"
#include "Strategies/RadixSortStrategy.cpp"
UInt16
AoAHW3ApplicationDelegate::applicationDidStart(const Container::Array<String> &arguments) const noexcept
{
using StringStream = std::stringstream;
using InputFileStream = std::ifstream;
using OutputFileStream = std::ofstream;
using HighResolutionClock = std::chrono::high_resolution_clock;
using Container::Array;
if (arguments.getLength() == 2) {
Array<DOMElement> array;
InputFileStream inputFile("numbers_to_sort.txt");
OutputFileStream outputFile("sorted_numbers.txt");
String feed;
UInt64 inputLength = std::stoll(arguments[1]);
for (UInt64 i = 0; !inputFile.eof() && i < inputLength; ++i) {
inputFile >> feed;
inputFile >> feed;
array.append(DOMElement(i, std::stoll(feed)));
}
RadixSortStrategy<DOMElement> rss(array);
auto startTime = HighResolutionClock::now();
rss.sort();
auto endTime = HighResolutionClock::now();
printf("Counting sort based radix sort duration: %llu nanoseconds\n", std::chrono::duration_cast<std::chrono::nanoseconds>(endTime - startTime).count());
for (UInt64 i = 0; i < rss.getArray().getLength(); ++i) {
outputFile
<< rss.getArray()[i].index
<< "\t"
<< rss.getArray()[i].data
<< std::endl;
}
return 0;
} else {
fprintf(stderr, "wrong number of input argument(s), expected 1 or 2");
return 9;
}
}