-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathsgraph.hpp
More file actions
98 lines (77 loc) · 2.28 KB
/
sgraph.hpp
File metadata and controls
98 lines (77 loc) · 2.28 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
// The Steraming Graph Interface
#pragma once
#include <cstdint>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iostream>
#include "trigger.hpp"
namespace sae {
namespace streaming {
using vid_t = int64_t;
using eid_t = int64_t;
using tid_t = uint8_t;
using data_t = std::string;
struct Graph {
vid_t n;
vid_t m;
};
inline std::ostream& operator<<(std::ostream& os, const Graph& g) {
os << "graph{n=" << g.n << ", m=" << g.m << "}";
return os;
}
struct Vertex {
vid_t id;
tid_t type;
data_t data;
bool operator<(const Vertex& v) const {
return id < v.id;
}
bool operator==(const Vertex& v) const {
return id == v.id;
}
};
inline std::ostream& operator<<(std::ostream& os, const Vertex& v) {
os << "vertex{id=" << v.id << ", type=" << int(v.type) << ", data=" << v.data << "}";
return os;
}
struct Edge {
eid_t id;
vid_t source;
vid_t target;
tid_t type;
data_t data;
bool operator<(const Edge& e) const {
return id < e.id;
}
bool operator==(const Edge& e) const {
return id == e.id;
}
};
inline std::ostream& operator<<(std::ostream& os, const Edge& e) {
os << "edge{id=" << e.id << ", source=" << e.source << ", target=" << e.target << ", type=" << int(e.type) << ", data=" << e.data << "}";
return os;
}
// Implementations should guarantee that the callbacks are in the specific order: graph, vertex, edge.
struct StreamingGraph {
virtual ~StreamingGraph() {};
virtual void process(const Trigger<Graph>&,
const Trigger<Vertex>&,
const Trigger<Edge>&) = 0;
};
// The following code are for automatic graph format registering
using StreamingGraphCreator = std::function<StreamingGraph*(std::istream&)>;
using GraphFormatMap = std::map<std::string, StreamingGraphCreator>;
extern GraphFormatMap *graph_format_map;
struct GraphFormatRegisterer {
GraphFormatRegisterer(const char *, StreamingGraphCreator&&);
};
} // namespace streaming
} // namespace sae
#define REGSITER_GRAPH_FORMAT(name, klass) \
namespace sae { namespace streaming { \
GraphFormatRegisterer graph_format_registerer_##name(#name, [](std::istream& is) { \
return new klass(is); \
}); \
}}