-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgdb.cc
68 lines (54 loc) · 1.25 KB
/
gdb.cc
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
#include <iostream>
#include "gdb.h"
using namespace std;
GraphDatabase::GraphDatabase()
{
(this->persist_file).open("gdb1.gdb", ios::out|ios::binary);
(this->persist_file_r).open("gdb1.gdb", ios::in|ios::binary);
return;
}
void GraphDatabase::insert_node(unsigned int id, void *data, unsigned int data_len)
{
this->G.insert_node(id, data, data_len);
return;
}
void GraphDatabase::insert_edge(unsigned int from, unsigned int to, string relation)
{
this->G.insert_edge(from, to, relation);
return;
}
void GraphDatabase::delete_node(unsigned int id)
{
this->G.delete_node(id);
return;
}
NodeVector GraphDatabase::get_node(unsigned int id)
{
return this->G.get_node(id);
}
Node* GraphDatabase::read_node(unsigned int id)
{
return this->G.read_node(id, this->persist_file_r);
}
void GraphDatabase::persist()
{
(this->G).persist(this->persist_file);
return;
}
void GraphDatabase::recover()
{
ifstream f;
f.open("./gdb1.gdb", ios::in|ios::binary);
if (!f.is_open()) {
cout << "File open failed!" << endl;
return;
}
(this->G).recover(f);
f.close();
}
GraphDatabase::~GraphDatabase()
{
(this->persist_file).close();
(this->persist_file_r).close();
return;
}