-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataNodeQuery.cpp
More file actions
131 lines (109 loc) · 2.75 KB
/
dataNodeQuery.cpp
File metadata and controls
131 lines (109 loc) · 2.75 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a<b) ? (a) : (b))
#define max(a,b) ((a>b) ? (a) : (b))
#define abs(a) ((a>0) ? (a) : ((-1)*a))
#define ll long long
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORL(i,n) for(long long i=0;i<n;i++)
#define MOD 1000000007
#define PI 3.141592653589
#define pb push_back
#define mp make_pair
int dp[5009][5009]={0};
#define fastio ios_base::sync_with_stdio(false); cin.tie(0);
#define fileio freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define MAX_CHILD 5
#define null NULL
#define square(a) a*a
class nodeInd{
public:
ll id,ptr,adjPtr;
int size;
};
class nodeData {
public:
ll id;
double lon,lat;
vector<ll> adj,adjPtr;
char* otherData;
} nd;
nodeData queryNode(ll id)
{
fstream f,f1,f2;
f.open("NodeIndexNew.ind",ios::in | ios::out | ios::binary);
f1.open("CompleteNodeData.dat",ios::in | ios::out | ios::binary);
f2.open("adjacency.dat",ios::in | ios::out | ios::binary);
char *res = NULL;
f.seekg(0,ios::end);
ll no_nodes=f.tellg();
nodeInd in;
no_nodes/=sizeof(nodeInd);
int size;
ll temp;
ll s=0,e=no_nodes-1,m;
while(s<=e)
{
m=(s+e)/2;
f.seekg(m*sizeof(nodeInd));f.seekp(m*sizeof(nodeInd));
f.read((char*)&in,sizeof(nodeInd));
if(in.id==id)
{
//cout<<"Found";
nd.otherData= new char[in.size];
f1.seekg(in.ptr);f1.seekp(in.ptr);
f1.read(nd.otherData,in.size);
f2.seekg(in.adjPtr);f2.seekp(in.adjPtr);
f2>>nd.id>>nd.lon>>nd.lat>>size;
while(size--)
{
f2>>temp;
nd.adj.pb(temp);
f2>>temp;
nd.adjPtr.pb(temp);
}
return nd;
}
if(in.id<id)
s=m+1;
else
e=m-1;
}
cout<<"Not Found";
return NULL;
}
int main()
{
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
nodeData nd1;
if(nd1 = queryNode(58049719))
{
cout<<nd.id<<" "<<nd.lon<<" "<<nd.lat<<" "<<nd.adj.size()<<endl;
cout<<nd.otherData<<endl;
}
// ll id,ptr;
// char s1[27];
// int size;
// nodeInd in;
// int t=10;
// while(!f.eof())
// {
// if(f.read(s1,27)){
// cout<<s1<<endl;
// }
// }
// f.close();
// freopen("data.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// f.open("NodeIndexNew.ind",ios::in | ios::out | ios::trunc);
// cout<<"temp data done"<<endl;
// while(cin>>id>>ptr>>size)
// {
// in.id=id;
// in.ptr=ptr;
// in.size=size;
// f.write((char*)&in,sizeof(in));
// }
return 0;
}