-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
69 lines (61 loc) · 1.73 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
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
#include <iostream>//for debug
#include <utility>//for pairs
#include <cstdio>//for working with files
#include <filesystem>//for working with directory
#include <string>//for string
#include "HashTable.h"
#include "OpenTable.h"
namespace fs = std::filesystem;
typedef std::pair< uint32_t , uint32_t > name_fn;
static name_fn ParsePath(std::string s , bool path=false)
{
if(!path) {
auto it = s.begin();
for (auto i = s.begin(); i != s.end(); i++) {
if ((*i) == '/') {
it = i;
}
}
s.erase(s.begin(), it + 1);
}
return {
static_cast<uint32_t>( std::stoul( s.substr( 1, s.find('x') ) ) ) ,
static_cast<uint32_t>( std::stoul( s.substr( s.find('x') + 1 ) ) )
};
}
static int GetData( std::string& s )
{
static OpenTable table;
name_fn path = ParsePath(s, true );
uint16_t temp = table.getData(path.first, path.second,s);
return temp;
}
static int WriteDatabase(const std::string& dir)
{
HashTable table(dir);
name_fn path;
for ( auto& item:fs::directory_iterator( dir ) ){
std::string s=item.path();
uint16_t size = std::filesystem::file_size(s);
std::FILE *file = std::fopen( s.c_str(), "rb");
if(!file) return 1;
path = ParsePath(s);
table.write( path.first, path.second, size, file);
std::fclose( file );
}
return 0;
}
int main()
{
if(WriteDatabase("/home/vuniverse/CLionProjects/MapHasher/Data"))
{
std::cerr << "error WriteDatabase" << std::endl;
return 1;
}
std::string str;
while ( std::cin >> str ){
GetData( str );
std::cout << "Data:\n---\n" << str << "\n---\nend of data\n"<< std::endl;
}
return 0;
}