edge.h
Go to the documentation of this file.
1 /*
2  * This file is part of the alglib project.
3  *
4  * (c) Divyanshu Kakwani <divkakwani@gmail.com>
5  *
6  * For the full copyright and license information, please view the LICENSE file
7  * that was distributed with this source code.
8  */
9 
10 #pragma once
11 
12 #include <iostream>
13 
14 namespace alglib {
15 namespace graph {
16 
17 
18 template<typename vertex_t, typename attr_t = void>
19 struct edge_t {
20 
21  vertex_t from;
22  vertex_t to;
23  attr_t attribute;
24 
25  edge_t() = default;
26 
27  edge_t(const vertex_t& u, const vertex_t& v, const attr_t& attr) {
28  from = u;
29  to = v;
30  attribute = attr;
31  }
32 
33  bool operator==(const edge_t<vertex_t, edge_t>& other) const
34  { return attribute == other.attribute; }
35 
36  bool operator!=(const edge_t<vertex_t, edge_t>& other) const
37  { return attribute != other.attribute; }
38 
39  bool operator>(const edge_t<vertex_t, edge_t>& other) const
40  { return attribute > other.attribute; }
41 
42  bool operator<(const edge_t<vertex_t, edge_t>& other) const
43  { return attribute < other.attribute; }
44 
45  bool operator>=(const edge_t<vertex_t, edge_t>& other) const
46  { return attribute >= other.attribute; }
47 
48  bool operator<=(const edge_t<vertex_t, edge_t>& other) const
49  { return attribute <= other.attribute; }
50 };
51 
52 template<typename vertex_t, typename attr_t>
53 std::ostream& operator<<(std::ostream& out, const edge_t<vertex_t, attr_t>& e) {
54 
55  out << "(from: " << e.from << ", to: " << e.to
56  << ", attr: " << e.attribute << ")";
57  return out;
58 }
59 
60 
61 template<typename vertex_t, typename attr_t>
62 edge_t<vertex_t, attr_t> make_edge(vertex_t from, vertex_t to,
63  attr_t attribute) {
64  return edge_t<vertex_t, attr_t>(from, to, attribute);
65 }
66 
67 // Specialization for types when the attribute is void
68 template<typename vertex_t>
69 struct edge_t<vertex_t, void> : public edge_t<vertex_t, int> {
70 
71  edge_t() {}
72  edge_t(const vertex_t& u, const vertex_t v) : edge_t<vertex_t, int>(u, v, 1) {}
73 
74 };
75 
76 
77 } // end of graph namespace
78 } // end of alglib namespace
79 
80 
bool operator==(const edge_t< vertex_t, edge_t > &other) const
Definition: edge.h:33
long long from()
Definition: dijkstra.cpp:109
edge_t< vertex_t, attr_t > make_edge(vertex_t from, vertex_t to, attr_t attribute)
Definition: edge.h:62
Definition: bimap.h:17
bool operator>(const edge_t< vertex_t, edge_t > &other) const
Definition: edge.h:39
edge_t(const vertex_t &u, const vertex_t &v, const attr_t &attr)
Definition: edge.h:27
Definition: edge.h:19
bool operator!=(const edge_t< vertex_t, edge_t > &other) const
Definition: edge.h:36
vertex_t to
Definition: edge.h:22
vertex_t from
Definition: edge.h:21
edge_t(const vertex_t &u, const vertex_t v)
Definition: edge.h:72
bool operator>=(const edge_t< vertex_t, edge_t > &other) const
Definition: edge.h:45
attr_t attribute
Definition: edge.h:23