ModErn Text Analysis
META Enumerates Textual Applications
directed_graph.h
Go to the documentation of this file.
1 
10 #ifndef META_DIRECTED_GRAPH_H_
11 #define META_DIRECTED_GRAPH_H_
12 
13 #include <stdexcept>
14 #include <vector>
15 #include <unordered_set>
16 #include <cstddef>
17 #include "meta.h"
18 #include "util/optional.h"
19 #include "graph/graph.h"
20 #include "graph/default_node.h"
21 #include "graph/default_edge.h"
22 
23 namespace meta
24 {
25 namespace graph
26 {
30 template <class Node = default_node, class Edge = default_edge>
31 class directed_graph : public graph<Node, Edge>
32 {
33  public:
34  using adjacency_list = typename graph<Node, Edge>::adjacency_list;
35  using vec_t = std::vector<std::pair<Node, adjacency_list>>;
40 
45  const adjacency_list& adjacent(node_id id) const;
46 
51  const std::vector<node_id>& incoming(node_id id) const;
52 
57  virtual node_id insert(Node node) override;
58 
64  virtual void add_edge(Edge edge, node_id source, node_id dest) override;
65 
66  #include "node_iterator.h"
69 
73  iterator begin() { return {nodes_.begin()}; }
74 
75  const_iterator begin() const { return {nodes_.cbegin()}; }
76 
80  iterator end() { return {nodes_.end()}; }
81 
82  const_iterator end() const { return {nodes_.cend()}; }
83 
84  #include "edge_iterator.h"
85  typedef edge_iterator<typename vec_t::iterator> e_iterator;
86  typedef edge_iterator<typename vec_t::const_iterator> const_e_iterator;
87 
91  e_iterator edges_begin() { return {this, nodes_.begin(), nodes_.end()}; }
92 
93  const_e_iterator edges_begin() const
94  {
95  return {this, nodes_.cbegin(), nodes_.cend()};
96  }
97 
101  e_iterator edges_end() { return {this, nodes_.end(), nodes_.end()}; }
102 
103  const_e_iterator edges_end() const
104  {
105  return {this, nodes_.cend(), nodes_.cend()};
106  }
107 
108  private:
113  std::vector<std::vector<node_id>> incoming_;
114 };
115 
119 class directed_graph_exception : public std::runtime_error
120 {
121  public:
122  using std::runtime_error::runtime_error;
123 };
124 }
125 }
126 
127 #include "graph/directed_graph.tcc"
128 #endif
iterator begin()
Definition: directed_graph.h:73
Contains top-level namespace documentation for the META toolkit.
virtual node_id insert(Node node) override
Definition: directed_graph.tcc:31
virtual util::optional< Edge > edge(node_id source, node_id dest) const
Definition: graph.tcc:31
std::vector< std::vector< node_id > > incoming_
Each Node object is indexed by its id.
Definition: directed_graph.h:113
Definition: edge_iterator.h:22
Definition: graph.h:18
e_iterator edges_end()
Definition: directed_graph.h:101
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
Definition: directed_graph.h:12
const std::vector< node_id > & incoming(node_id id) const
Definition: directed_graph.tcc:22
virtual Node & node(node_id id)
Definition: graph.tcc:13
virtual void add_edge(Edge edge, node_id source, node_id dest) override
Definition: directed_graph.tcc:40
const adjacency_list & adjacent(node_id id) const
Definition: directed_graph.tcc:11
Basic exception for directed_graph interactions.
Definition: directed_graph.h:119
std::vector< std::pair< Node, adjacency_list > > nodes_
Each Node object is indexed by its id.
Definition: graph.h:79
A (currently) simple class to represent a directed graph in memory.
Definition: directed_graph.h:31
e_iterator edges_begin()
Definition: directed_graph.h:91
iterator end()
Definition: directed_graph.h:80