ModErn Text Analysis
META Enumerates Textual Applications
graph.h
Go to the documentation of this file.
1 
10 #ifndef META_GRAPH_H_
11 #define META_GRAPH_H_
12 
13 namespace meta
14 {
15 namespace graph
16 {
17 template <class Node, class Edge>
18 class graph
19 {
20  public:
21  using adjacency_list = std::vector<std::pair<node_id, Edge>>;
22 
23  virtual ~graph() = default;
24 
29  virtual Node& node(node_id id);
30  virtual const Node& node(node_id id) const;
31 
37  virtual util::optional<Edge> edge(node_id source, node_id dest) const;
38 
43  virtual uint64_t size() const;
44 
48  virtual uint64_t num_edges() const;
49 
54  virtual node_id insert(Node node) = 0;
55 
60  template <class... Args>
61  node_id emplace(Args&&... args);
62 
68  virtual void add_edge(Edge edge, node_id source, node_id dest) = 0;
69 
75  virtual void add_edge(node_id source, node_id dest);
76 
77  protected:
79  std::vector<std::pair<Node, adjacency_list>> nodes_;
80 
82  uint64_t num_edges_ = 0;
83 };
84 
88 class graph_exception : public std::runtime_error
89 {
90  public:
91  using std::runtime_error::runtime_error;
92 };
93 }
94 }
95 #include "graph.tcc"
96 #endif
A class for representing optional values.
Definition: vocabulary_map.h:21
virtual void add_edge(Edge edge, node_id source, node_id dest)=0
virtual util::optional< Edge > edge(node_id source, node_id dest) const
Definition: graph.tcc:31
Definition: graph.h:18
node_id emplace(Args &&...args)
Constructs a node with forwarded arguments.
Definition: graph.tcc:69
virtual uint64_t num_edges() const
Definition: graph.tcc:50
Basic exception for graph interactions.
Definition: graph.h:88
The ModErn Text Analysis toolkit is a suite of natural language processing, classification, information retreival, data mining, and other applications of text processing.
Definition: analyzer.h:24
virtual Node & node(node_id id)
Definition: graph.tcc:13
virtual uint64_t size() const
Definition: graph.tcc:56
std::vector< std::pair< Node, adjacency_list > > nodes_
Each Node object is indexed by its id.
Definition: graph.h:79
virtual node_id insert(Node node)=0
uint64_t num_edges_
Saves the number of edges in this graph.
Definition: graph.h:82