Skip to content

Commit 8f86225

Browse files
authored
[Fix] [Issue 338] Inconsistent id types (#342)
* Add id_t and fix warnings * Fix Subset_struct * Fix UnionFindTest error * More fixes to UnionFindTest * Use CXXGraph::id_t in more places * Address a few PR comments * Ensure CXXGRAPH_ID_TYPE is always unsigned * Do not return a reference to temporary id
1 parent 43e3830 commit 8f86225

25 files changed

+225
-202
lines changed

include/Edge/DirectedEdge.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ std::ostream &operator<<(std::ostream &o, const DirectedEdge<T> &edge);
4545
template <typename T>
4646
class DirectedEdge : public Edge<T> {
4747
public:
48-
DirectedEdge(const unsigned long id, const Node<T> &node1,
48+
DirectedEdge(const CXXGraph::id_t id, const Node<T> &node1,
4949
const Node<T> &node2);
50-
DirectedEdge(const unsigned long id, shared<const Node<T>> node1,
50+
DirectedEdge(const CXXGraph::id_t id, shared<const Node<T>> node1,
5151
shared<const Node<T>> node2);
52-
DirectedEdge(const unsigned long id,
52+
DirectedEdge(const CXXGraph::id_t id,
5353
const std::pair<const Node<T> *, const Node<T> *> &nodepair);
54-
DirectedEdge(const unsigned long id,
54+
DirectedEdge(const CXXGraph::id_t id,
5555
const std::pair<shared<const Node<T>>, shared<const Node<T>>> &nodepair);
5656
DirectedEdge(const Edge<T> &edge);
5757
virtual ~DirectedEdge() = default;
@@ -69,23 +69,23 @@ class DirectedEdge : public Edge<T> {
6969
};
7070

7171
template <typename T>
72-
DirectedEdge<T>::DirectedEdge(const unsigned long id, const Node<T> &node1,
72+
DirectedEdge<T>::DirectedEdge(const CXXGraph::id_t id, const Node<T> &node1,
7373
const Node<T> &node2)
7474
: Edge<T>(id, node1, node2) {}
7575

7676
template <typename T>
77-
DirectedEdge<T>::DirectedEdge(const unsigned long id, shared<const Node<T>> node1,
77+
DirectedEdge<T>::DirectedEdge(const CXXGraph::id_t id, shared<const Node<T>> node1,
7878
shared<const Node<T>> node2) : Edge<T>(id, node1, node2) {}
7979

8080
template <typename T>
8181
DirectedEdge<T>::DirectedEdge(
82-
const unsigned long id,
82+
const CXXGraph::id_t id,
8383
const std::pair<const Node<T> *, const Node<T> *> &nodepair)
8484
: Edge<T>(id, nodepair) {}
8585

8686
template <typename T>
8787
DirectedEdge<T>::DirectedEdge(
88-
const unsigned long id,
88+
const CXXGraph::id_t id,
8989
const std::pair<shared<const Node<T>>, shared<const Node<T>>> &nodepair)
9090
: Edge<T>(id, nodepair) {}
9191

include/Edge/DirectedWeightedEdge.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,16 @@ std::ostream &operator<<(std::ostream &o, const DirectedWeightedEdge<T> &edge);
4848
template <typename T>
4949
class DirectedWeightedEdge : public DirectedEdge<T>, public Weighted {
5050
public:
51-
DirectedWeightedEdge(const unsigned long id, const Node<T> &node1,
51+
DirectedWeightedEdge(const CXXGraph::id_t id, const Node<T> &node1,
5252
const Node<T> &node2, const double weight);
53-
DirectedWeightedEdge(const unsigned long id, shared<const Node<T>> node1,
53+
DirectedWeightedEdge(const CXXGraph::id_t id, shared<const Node<T>> node1,
5454
shared<const Node<T>> node2, const double weight);
5555
DirectedWeightedEdge(
56-
const unsigned long id,
56+
const CXXGraph::id_t id,
5757
const std::pair<const Node<T> *, const Node<T> *> &nodepair,
5858
const double weight);
5959
DirectedWeightedEdge(
60-
const unsigned long id,
60+
const CXXGraph::id_t id,
6161
const std::pair<shared<const Node<T>>, shared<const Node<T>>> &nodepair,
6262
const double weight);
6363
DirectedWeightedEdge(const DirectedEdge<T> &edge, const double weight);
@@ -78,29 +78,29 @@ class DirectedWeightedEdge : public DirectedEdge<T>, public Weighted {
7878
};
7979

8080
template <typename T>
81-
DirectedWeightedEdge<T>::DirectedWeightedEdge(const unsigned long id,
81+
DirectedWeightedEdge<T>::DirectedWeightedEdge(const CXXGraph::id_t id,
8282
const Node<T> &node1,
8383
const Node<T> &node2,
8484
const double weight)
8585
: DirectedEdge<T>(id, node1, node2), Weighted(weight) {}
8686

8787
template <typename T>
88-
DirectedWeightedEdge<T>::DirectedWeightedEdge(const unsigned long id,
88+
DirectedWeightedEdge<T>::DirectedWeightedEdge(const CXXGraph::id_t id,
8989
shared<const Node<T>> node1,
9090
shared<const Node<T>> node2,
9191
const double weight)
9292
: DirectedEdge<T>(id, node1, node2), Weighted(weight) {}
9393

9494
template <typename T>
9595
DirectedWeightedEdge<T>::DirectedWeightedEdge(
96-
const unsigned long id,
96+
const CXXGraph::id_t id,
9797
const std::pair<const Node<T> *, const Node<T> *> &nodepair,
9898
const double weight)
9999
: DirectedEdge<T>(id, nodepair), Weighted(weight) {}
100100

101101
template <typename T>
102102
DirectedWeightedEdge<T>::DirectedWeightedEdge(
103-
const unsigned long id,
103+
const CXXGraph::id_t id,
104104
const std::pair<shared<const Node<T>>, shared<const Node<T>>> &nodepair,
105105
const double weight)
106106
: DirectedEdge<T>(id, nodepair), Weighted(weight) {}

include/Edge/Edge.hpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <utility>
2828

2929
#include "Node/Node.hpp"
30+
#include "Utility/id_t.hpp"
3031

3132
namespace CXXGraph {
3233
// Smart pointers alias
@@ -46,20 +47,20 @@ std::ostream &operator<<(std::ostream &o, const Edge<T> &edge);
4647
template <typename T>
4748
class Edge {
4849
private:
49-
unsigned long long id = 0;
50+
CXXGraph::id_t id = 0;
5051
std::pair<shared<const Node<T>>, shared<const Node<T>>> nodePair;
5152

5253
public:
53-
Edge(const unsigned long long id, const Node<T> &node1, const Node<T> &node2);
54-
Edge(const unsigned long long id, shared<const Node<T>> node1, shared<const Node<T>> node2);
55-
Edge(const unsigned long long id,
54+
Edge(const CXXGraph::id_t id, const Node<T> &node1, const Node<T> &node2);
55+
Edge(const CXXGraph::id_t id, shared<const Node<T>> node1, shared<const Node<T>> node2);
56+
Edge(const CXXGraph::id_t id,
5657
const std::pair<const Node<T> *, const Node<T> *> &nodepair);
57-
Edge(const unsigned long long id,
58+
Edge(const CXXGraph::id_t id,
5859
const std::pair<shared<const Node<T>>, shared<const Node<T>>> &nodepair);
5960
virtual ~Edge() = default;
6061
void setFirstNode(shared<const Node<T>> node);
6162
void setSecondNode(shared<const Node<T>> node);
62-
const unsigned long long &getId() const;
63+
const unsigned long long getId() const;
6364
const std::pair<shared<const Node<T>>, shared<const Node<T>>> &getNodePair() const;
6465
shared<const Node<T>> getOtherNode(shared<const Node<T>> node) const;
6566
virtual const std::optional<bool> isDirected() const;
@@ -75,30 +76,30 @@ class Edge {
7576
};
7677

7778
template <typename T>
78-
Edge<T>::Edge(const unsigned long long id, const Node<T> &node1,
79+
Edge<T>::Edge(const CXXGraph::id_t id, const Node<T> &node1,
7980
const Node<T> &node2) {
8081
this->nodePair.first = make_shared<const Node<T>>(node1);
8182
this->nodePair.second = make_shared<const Node<T>>(node2);
8283
this->id = id;
8384
}
8485

8586
template <typename T>
86-
Edge<T>::Edge(const unsigned long long id, shared<const Node<T>> node1, shared<const Node<T>> node2) {
87+
Edge<T>::Edge(const CXXGraph::id_t id, shared<const Node<T>> node1, shared<const Node<T>> node2) {
8788
this->nodePair.first = node1;
8889
this->nodePair.second = node2;
8990
this->id = id;
9091
}
9192

9293
template <typename T>
93-
Edge<T>::Edge(const unsigned long long id,
94+
Edge<T>::Edge(const CXXGraph::id_t id,
9495
const std::pair<const Node<T> *, const Node<T> *> &nodepair) {
9596
this->nodePair.first = make_shared<const Node<T>>(*(nodepair.first));
9697
this->nodePair.second = make_shared<const Node<T>>(*(nodepair.second));
9798
this->id = id;
9899
}
99100

100101
template <typename T>
101-
Edge<T>::Edge(const unsigned long long id,
102+
Edge<T>::Edge(const CXXGraph::id_t id,
102103
const std::pair<shared<const Node<T>>, shared<const Node<T>>> &nodepair)
103104
: nodePair(nodepair) {
104105
this->id = id;
@@ -117,7 +118,7 @@ void Edge<T>::setSecondNode(shared<const Node<T>> node) {
117118
}
118119

119120
template <typename T>
120-
const unsigned long long &Edge<T>::getId() const {
121+
const unsigned long long Edge<T>::getId() const {
121122
return id;
122123
}
123124

include/Edge/UndirectedEdge.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ std::ostream &operator<<(std::ostream &o, const UndirectedEdge<T> &edge);
4444
template <typename T>
4545
class UndirectedEdge : public Edge<T> {
4646
public:
47-
UndirectedEdge(const unsigned long id, const Node<T> &node1,
47+
UndirectedEdge(const CXXGraph::id_t id, const Node<T> &node1,
4848
const Node<T> &node2);
49-
UndirectedEdge(const unsigned long id, shared<const Node<T>> node1,
49+
UndirectedEdge(const CXXGraph::id_t id, shared<const Node<T>> node1,
5050
shared<const Node<T>> node2);
51-
UndirectedEdge(const unsigned long id,
51+
UndirectedEdge(const CXXGraph::id_t id,
5252
const std::pair<const Node<T> *, const Node<T> *> &nodepair);
53-
UndirectedEdge(const unsigned long id,
53+
UndirectedEdge(const CXXGraph::id_t id,
5454
const std::pair<shared<const Node<T>>, shared<const Node<T>>> &nodepair);
5555
UndirectedEdge(const Edge<T> &edge);
5656
virtual ~UndirectedEdge() = default;
@@ -68,24 +68,24 @@ class UndirectedEdge : public Edge<T> {
6868
};
6969

7070
template <typename T>
71-
UndirectedEdge<T>::UndirectedEdge(const unsigned long id, const Node<T> &node1,
71+
UndirectedEdge<T>::UndirectedEdge(const CXXGraph::id_t id, const Node<T> &node1,
7272
const Node<T> &node2)
7373
: Edge<T>(id, node1, node2) {}
7474

7575
template <typename T>
76-
UndirectedEdge<T>::UndirectedEdge(const unsigned long id, shared<const Node<T>> node1,
76+
UndirectedEdge<T>::UndirectedEdge(const CXXGraph::id_t id, shared<const Node<T>> node1,
7777
shared<const Node<T>> node2)
7878
: Edge<T>(id, node1, node2) {}
7979

8080
template <typename T>
8181
UndirectedEdge<T>::UndirectedEdge(
82-
const unsigned long id,
82+
const CXXGraph::id_t id,
8383
const std::pair<const Node<T> *, const Node<T> *> &nodepair)
8484
: Edge<T>(id, nodepair) {}
8585

8686
template <typename T>
8787
UndirectedEdge<T>::UndirectedEdge(
88-
const unsigned long id,
88+
const CXXGraph::id_t id,
8989
const std::pair<shared<const Node<T>>, shared<const Node<T>>> &nodepair)
9090
: Edge<T>(id, nodepair) {}
9191

include/Edge/UndirectedWeightedEdge.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,16 @@ std::ostream &operator<<(std::ostream &o,
5050
template <typename T>
5151
class UndirectedWeightedEdge : public UndirectedEdge<T>, public Weighted {
5252
public:
53-
UndirectedWeightedEdge(const unsigned long id, const Node<T> &node1,
53+
UndirectedWeightedEdge(const CXXGraph::id_t id, const Node<T> &node1,
5454
const Node<T> &node2, const double weight);
55-
UndirectedWeightedEdge(const unsigned long id, shared<const Node<T>> node1,
55+
UndirectedWeightedEdge(const CXXGraph::id_t id, shared<const Node<T>> node1,
5656
shared<const Node<T>> node2, const double weight);
5757
UndirectedWeightedEdge(
58-
const unsigned long id,
58+
const CXXGraph::id_t id,
5959
const std::pair<const Node<T> *, const Node<T> *> &nodepair,
6060
const double weight);
6161
UndirectedWeightedEdge(
62-
const unsigned long id,
62+
const CXXGraph::id_t id,
6363
const std::pair<shared<const Node<T>>, shared<const Node<T>>> &nodepair,
6464
const double weight);
6565
UndirectedWeightedEdge(const UndirectedEdge<T> &edge, const double weight);
@@ -80,29 +80,29 @@ class UndirectedWeightedEdge : public UndirectedEdge<T>, public Weighted {
8080
};
8181

8282
template <typename T>
83-
UndirectedWeightedEdge<T>::UndirectedWeightedEdge(const unsigned long id,
83+
UndirectedWeightedEdge<T>::UndirectedWeightedEdge(const CXXGraph::id_t id,
8484
const Node<T> &node1,
8585
const Node<T> &node2,
8686
const double weight)
8787
: UndirectedEdge<T>(id, node1, node2), Weighted(weight) {}
8888

8989
template <typename T>
90-
UndirectedWeightedEdge<T>::UndirectedWeightedEdge(const unsigned long id,
90+
UndirectedWeightedEdge<T>::UndirectedWeightedEdge(const CXXGraph::id_t id,
9191
shared<const Node<T>> node1,
9292
shared<const Node<T>> node2,
9393
const double weight)
9494
: UndirectedEdge<T>(id, node1, node2), Weighted(weight) {}
9595

9696
template <typename T>
9797
UndirectedWeightedEdge<T>::UndirectedWeightedEdge(
98-
const unsigned long id,
98+
const CXXGraph::id_t id,
9999
const std::pair<const Node<T> *, const Node<T> *> &nodepair,
100100
const double weight)
101101
: UndirectedEdge<T>(id, nodepair), Weighted(weight) {}
102102

103103
template <typename T>
104104
UndirectedWeightedEdge<T>::UndirectedWeightedEdge(
105-
const unsigned long id,
105+
const CXXGraph::id_t id,
106106
const std::pair<shared<const Node<T>>, shared<const Node<T>>> &nodepair,
107107
const double weight)
108108
: UndirectedEdge<T>(id, nodepair), Weighted(weight) {}

0 commit comments

Comments
 (0)