-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph.h
49 lines (39 loc) · 1.19 KB
/
graph.h
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
#ifndef __GRAPH_H__
#define __GRAPH_H__
#include <map>
#include <vector>
#include <string>
#include "gdb_vector.h"
using namespace std;
class Node {
private:
unsigned int id;
void *data;
unsigned int data_len;
map<string, NodeVector> edges;
public:
Node(unsigned int id, void *data, unsigned int data_len);
void insert_edge(Node *to, string relation);
unsigned int get_id();
NodeVector get(string relation);
void persist(ofstream &persist_file);
//void persist_node(ofstream &persist_file);
//void persist_edge(ofstream &persist_file);
};
class Graph {
private:
map<unsigned int, Node*> nodes;
map<unsigned int, unsigned int> nodes_persist;
vector<Node*> nodes_unpersist;
public:
Graph();
Node* insert_node(unsigned int id, void *data, unsigned int data_len);
void insert_edge(unsigned int from, unsigned int to, string relation);
void delete_node(unsigned int id);
NodeVector get_node(unsigned int id);
void write_node(unsigned int id, ofstream &persist_file);
Node* read_node(unsigned int id, ifstream &persist_file);
void persist(ofstream &persist_file);
void recover(ifstream &persist_file);
};
#endif