forked from ZigRazor/CXXGraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEdge_impl.hpp
More file actions
148 lines (125 loc) · 4.17 KB
/
Edge_impl.hpp
File metadata and controls
148 lines (125 loc) · 4.17 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/***********************************************************/
/*** ______ ____ ______ _ ***/
/*** / ___\ \/ /\ \/ / ___|_ __ __ _ _ __ | |__ ***/
/*** | | \ / \ / | _| '__/ _` | '_ \| '_ \ ***/
/*** | |___ / \ / \ |_| | | | (_| | |_) | | | | ***/
/*** \____/_/\_\/_/\_\____|_| \__,_| .__/|_| |_| ***/
/*** |_| ***/
/***********************************************************/
/*** Header-Only C++ Library for Graph ***/
/*** Representation and Algorithms ***/
/***********************************************************/
/*** Author: ZigRazor ***/
/*** E-Mail: zigrazor@gmail.com ***/
/***********************************************************/
/*** Collaboration: ----------- ***/
/***********************************************************/
/*** License: MPL v2.0 ***/
/***********************************************************/
#ifndef __CXXGRAPH_EDGE_IMPL_H__
#define __CXXGRAPH_EDGE_IMPL_H__
#pragma once
#include <memory>
#include <string>
#include <utility>
#include "CXXGraph/Edge/Edge_decl.h"
namespace CXXGraph {
// Smart pointers alias
template <typename T>
using unique = std::unique_ptr<T>;
template <typename T>
using shared = std::shared_ptr<T>;
using std::make_shared;
using std::make_unique;
template <typename T>
Edge<T>::Edge(const std::string &userId, const Node<T> &node1,
const Node<T> &node2) {
this->nodePair.first = make_shared<const Node<T>>(node1);
this->nodePair.second = make_shared<const Node<T>>(node2);
this->userId = userId;
setId(userId);
}
template <typename T>
Edge<T>::Edge(const std::string &userId, shared<const Node<T>> node1,
shared<const Node<T>> node2) {
this->nodePair.first = node1;
this->nodePair.second = node2;
this->userId = userId;
setId(userId);
}
template <typename T>
Edge<T>::Edge(const std::string &userId,
const std::pair<const Node<T> *, const Node<T> *> &nodepair) {
this->nodePair.first = make_shared<const Node<T>>(*(nodepair.first));
this->nodePair.second = make_shared<const Node<T>>(*(nodepair.second));
this->userId = userId;
setId(userId);
}
template <typename T>
Edge<T>::Edge(
const std::string &userId,
const std::pair<shared<const Node<T>>, shared<const Node<T>>> &nodepair)
: nodePair(nodepair) {
this->userId = userId;
setId(userId);
}
template <typename T>
void Edge<T>::setId(const std::string &inpId) {
this->id = std::hash<std::string>{}(inpId);
}
template <typename T>
void Edge<T>::setFirstNode(shared<const Node<T>> node) {
/* this->nodePair = std::make_pair(node, this->nodePair.second); */
this->nodePair.first = node;
}
template <typename T>
void Edge<T>::setSecondNode(shared<const Node<T>> node) {
/* this->nodePair = std::make_pair(this->nodePair.first, node); */
this->nodePair.second = node;
}
template <typename T>
CXXGraph::id_t Edge<T>::getId() const {
return id;
}
template <typename T>
const std::string &Edge<T>::getUserId() const {
return userId;
}
template <typename T>
const std::pair<shared<const Node<T>>, shared<const Node<T>>> &
Edge<T>::getNodePair() const {
return nodePair;
}
template <typename T>
shared<const Node<T>> Edge<T>::getOtherNode(shared<const Node<T>> node) const {
if (this->getNodePair().first == node) {
return this->getNodePair().second;
} else {
return this->getNodePair().first;
}
}
template <typename T>
const std::optional<bool> Edge<T>::isDirected() const {
return std::nullopt;
}
template <typename T>
const std::optional<bool> Edge<T>::isWeighted() const {
return std::nullopt;
}
template <typename T>
bool Edge<T>::operator==(const Edge<T> &b) const {
return (this->id == b.id && this->nodePair == b.nodePair);
}
template <typename T>
bool Edge<T>::operator<(const Edge<T> &b) const {
return (this->id < b.id);
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const Edge<T> &edge) {
os << "((Node: " << edge.nodePair.first->getId()
<< ")) ?----- |Edge: " << edge.id
<< "|-----? ((Node: " << edge.nodePair.second->getId() << "))";
return os;
}
} // namespace CXXGraph
#endif // __CXXGRAPH_EDGE_IMPL_H__