-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgraph.hpp
More file actions
91 lines (72 loc) · 2.68 KB
/
graph.hpp
File metadata and controls
91 lines (72 loc) · 2.68 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
#ifndef UARK_CSCE_GRAPH_HEADER
#define UARK_CSCE_GRAPH_HEADER
#include <vector>
#include <stdexcept>
#include <unordered_set>
#include <iostream>
#include "vertex.hpp"
#include "edge.hpp"
using namespace std;
namespace csce {
class Graph {
public:
Graph();
Graph &add(size_t id);
Graph &add(const Vertex& vertex);
Graph &add(size_t uId, size_t vId);
Graph &add(const Vertex& u, const Vertex& v);
Graph &add(const Edge& edge);
bool contains(size_t id) const;
bool contains(const Vertex& vertex) const;
bool contains(size_t uId, size_t vId) const;
bool contains(const Vertex& u, const Vertex& v) const;
bool contains(const Edge& edge) const;
Graph difference(const Graph& other) const;
size_t getDegree(size_t id) const;
size_t getDegree(const Vertex& vertex) const;
Edge getEdge(size_t uId, size_t vId) const;
Edge getEdge(const Vertex& u, const Vertex& v) const;
Edge getEdge(const Edge& edge) const;
size_t getEdgeCount() const;
vector<Edge> getEdges() const;
vector<Edge> getEdges(size_t id) const;
vector<Edge> getEdges(const Vertex& incident) const;
Vertex getVertex(size_t id) const;
Vertex getVertex(const Vertex& vertex) const;
size_t getVertexCount() const;
vector<Vertex> getVerticies() const;
bool isSubGraph(const Graph& graph) const;
Graph join(const Graph& other) const;
Graph &remove(size_t id);
Graph &remove(const Vertex& vertex);
Graph &remove(size_t uId, size_t vId);
Graph &remove(const Vertex& u, const Vertex& v);
Graph &remove(const Edge& edge);
bool operator ==(const Graph& other) const {
if (this->getVertexCount() != other.getVertexCount()) {
return false;
}
if (this->getEdgeCount() != other.getEdgeCount()) {
return false;
}
// dumb search (implement sorted comparison later)
for (auto vertex = _verticies.begin(); vertex != _verticies.end(); vertex++) {
if (!other.contains(*vertex)) {
return false;
}
}
auto edges = this->getEdges();
for (auto edge = edges.begin(); edge != edges.end(); edge++) {
if (!other.contains(*edge)) {
return false;
}
}
return true;
}
private:
vector<Vertex> _verticies;
vector<Vertex>::iterator _findVertex(const Vertex& vertex);
vector<Vertex>::const_iterator _findVertex(const Vertex& vertex) const;
};
}
#endif /* UARK_CSCE_GRAPH_HEADER */