-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOpenTable.cpp
63 lines (55 loc) · 2.03 KB
/
OpenTable.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
//
// Created by vuniverse on 9/2/21.
//
#include "OpenTable.h"
#include "functions.h"
OpenTable::OpenTable()
{
m_file = std::fopen("/home/vuniverse/CLionProjects/CordsSorter/Output/hashes", "rb" );
m_memory = std::fopen("/home/vuniverse/CLionProjects/CordsSorter/Output/values", "rb" );
}
OpenTable::~OpenTable()
{
std::fclose(m_file);
std::fclose(m_memory);
}
memSize OpenTable::getData( const cords& y , const cords& x , std::string& s )
{
//Generate HASHES
cords cord = ( y >= x ) ? ( y - x ) : ( x - y ); //Individual hash for node
byte row = cord % hash_size; //Hash for table
byte column = bitIdentification(y, x ).get(); //generate bit flags to variable flags os type union flags
setHashTablePosition(column, row, m_file); //Set position in hashtable
position temp;
//moving from table to data list
std::fread(&temp, sizeof( position ), 1, m_file );
if(temp == m_zero){
std::cerr << " Empty table row "<< std::endl;
return 0;
}
std::fseek(m_file, static_cast<long>(temp), SEEK_SET);
cords hash;
do { //Check pointer
std::fread(&temp, sizeof( position ), 1, m_file );
std::fread(&hash, sizeof( cords ), 1, m_file );
if(hash==cord){
//Reuse of temp. Other meaning. Sorry ;(
//Go to m_memory
std::fread(&temp, sizeof( position ), 1, m_file );
std::fseek(m_memory, static_cast<long>(temp), SEEK_SET);
//size
memSize size;
std::fread(&size, sizeof( memSize ), 1, m_memory);
char* buffer = new char[ size+1 ];
buffer[size] = '\0';
std::fread(buffer, size, 1, m_memory);
s=buffer;
//yea, this is fucking raw pointer. Don`t forgot to clean data ;)
return size;
}else {
std::fseek(m_file, static_cast<long>(temp), SEEK_SET);
}
}while (temp != m_zero );
std::cerr << " Couldn't find same element "<< std::endl;
return 0;
}