Graph 3
graph.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <array>
4 #include <iostream>
5 #include <set> // graph_2
6 #include <string>
7 #include <vector>
8 
9 
14 class graph {
15  using Edge=std::array<unsigned int,2>; // graph_3
16 public:
25  [[maybe_unused]] explicit graph(const std::string &file_name);
26 
27  // Rule of five
28  graph(graph const & org) = default;
29  graph(graph && org) = default;
30  graph& operator=(graph const & rhs) = default;
31  graph& operator=(graph && rhs) = default;
32  ~graph() = default;
33 
40  [[nodiscard]] std::vector<std::vector<unsigned int>> get_node2nodes() const;
41 
45  [[nodiscard]] size_t Nedges() const
46  {
47  return _edges.size();
48  }
49 
53  [[nodiscard]] size_t Nvertices() const
54  {
55  return _vertices.size(); // graph_2
56  }
57 
61  [[nodiscard]] size_t Max_vertex() const // graph_2
62  {
63  return _maxvert;
64  }
65 
72  [[maybe_unused]] bool Append(unsigned int v1, unsigned int v2); // graph_3
73 
81  [[maybe_unused]] bool Delete(unsigned int v1, unsigned int v2); // graph_3
82 
88  bool Delete(Edge const &e); // graph_3
89 
96  void Delete(std::vector<Edge> const &v); // graph_3
97 
104  friend std::ostream& operator<<(std::ostream &s, graph const &rhs);
105 
106 private:
111  void DetermineNumberVertices();
112 
113  std::vector<Edge> _edges;
114  std::set<unsigned int> _vertices;
115  unsigned int _maxvert;
117 };
Definition: graph.h:14
graph & operator=(graph const &rhs)=default
size_t Nedges() const
Definition: graph.h:45
size_t Max_vertex() const
Definition: graph.h:61
void Delete(std::vector< Edge > const &v)
Removes the given edges from the graph. The method add only edges that not already contained in the g...
graph & operator=(graph &&rhs)=default
bool Delete(unsigned int v1, unsigned int v2)
Removes one directed edge (v1, v2) from the graph. The method add only edges that not already contain...
Definition: graph.cpp:124
friend std::ostream & operator<<(std::ostream &s, graph const &rhs)
Prints edges and vertices of the graph.
graph(const std::string &file_name)
Reads edges for graph from file.
size_t Nvertices() const
Definition: graph.h:53
~graph()=default
graph(graph &&org)=default
bool Append(unsigned int v1, unsigned int v2)
Appends one directed edge to the graph. The method add only edges that not already contained in the g...
Definition: graph.cpp:99
graph(graph const &org)=default
std::vector< std::vector< unsigned int > > get_node2nodes() const
Definition: graph.cpp:35