This repository has been archived by the owner on Jun 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsupport.hpp
67 lines (61 loc) · 1.85 KB
/
support.hpp
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
#include <vector>
#include <iterator>
#include <iostream>
#include <fstream>
template<typename T>
void print_buffer(const std::vector<T> buffer)
{
std::cout << std::hex;
std::copy(buffer.begin(), buffer.end(), std::ostream_iterator<T>(std::cout, " "));
std::cout << std::endl;
}
template<typename T>
void isSorted(const std::string fileName)
{
const size_t inBuffMax = 256*1000*1000;
std::ifstream in(fileName.c_str(), std::ios::in | std::ios::binary);
if(in.is_open())
{
in.seekg(0, std::ios::end);
size_t inLen = in.tellg();
in.seekg(0, std::ios::beg);
size_t inBuffLen = std::min(inLen, inBuffMax);
size_t readed = 0;
while(readed < inBuffLen)
{
std::vector<T> buffer(inBuffLen / sizeof(T));
in.read((char*)&buffer[0], inBuffLen);
readed += in.gcount();
T previous = buffer[0];
for(int i=1; i<buffer.size(); ++i)
{
if(previous > buffer[i])
{
std::cout << "File: " << fileName << " is UNSORTED " << std::hex << buffer[i-1]
<< " " << buffer[i] << " " << buffer[i+1] << std::endl;
return;
}
previous = buffer[i];
}
}
std::cout << "File: " << fileName << " is sorted" << std::endl;
return;
}
std::cout << "Can not open: " << fileName << std::endl;
}
template<typename T>
void isSorted(const std::vector<T> buffer, size_t size)
{
T previous = buffer[0];
for(int i=1; i<size; ++i)
{
if(previous > buffer[i])
{
std::cout << "UNSORTED " << std::hex << buffer[i-1]
<< " " << buffer[i] << std::endl;
return;
}
previous = buffer[i];
}
}
const std::string genNewTempFileName();