-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathedge.h
35 lines (25 loc) · 963 Bytes
/
edge.h
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
#pragma once
#include "node.h"
#include <algorithm>
#include <utility>
class Edge {
public:
Node a, b;
Edge() : a(), b() {}
Edge(Node a, Node b) : a(a), b(b) {}
// Define less than operator to allow storing edges in ordered trees
bool operator<(const Edge& other) const {
// Since the edges are undirected we first sort the nodes in each edge
auto myNodes = std::make_pair(a.getIndex(), b.getIndex());
if (myNodes.second < myNodes.first)
std::swap(myNodes.first, myNodes.second);
auto otherNodes = std::make_pair(other.a.getIndex(), other.b.getIndex());
if (otherNodes.second < otherNodes.first)
std::swap(otherNodes.first, otherNodes.second);
// Compare lexicographically
return myNodes < otherNodes;
}
bool operator==(const Edge& other) const {
return (a == other.a && b == other.b) || (a == other.b && b == other.a);
}
};