-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgraph_storage.hpp
More file actions
56 lines (49 loc) · 1.39 KB
/
graph_storage.hpp
File metadata and controls
56 lines (49 loc) · 1.39 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
#include <json/json.h>
#include <iostream>
#include <list>
#include <sstream>
#include <unordered_map>
#include "storage.hpp"
typedef list<string>::iterator rid; // index of record
/**
* The storage element for GraphStorage.
*/
class Node {
private:
// the endpoints, where the value cannot be hashed anymore.
list<pair<Json::Value, rid> > leafs;
unordered_map<string, shared_ptr<Node> > map;
void debug_print(int level);
public:
/**
* Append the rid index to the tree.
*/
void create_index(const rid &it, Json::Value root);
/**
* Find the minimum subset of documents (leafs) that matches the query.
*/
void collect_index(list<pair<Json::Value, rid> > &min_leafs,
Json::Value query);
};
/**
* Store the index of the documents in the tree structure.
*
* @author Che-Yuan Liang, Mar. 2018
* @issues 1. the reverse index won't be cleaned up after deletion. Currently
* the way to delete a document is done by setting the record as
* empty.
*/
class GraphStorage : public Storage {
private:
list<string> storage;
Node root;
void debug_print() {
for (const string &s : storage) {
cout << s.empty() << " " << s.size() << " " << s << endl;
}
}
public:
bool add(const string &s);
vector<string> get(const string &s);
bool del(const string &s);
};