Skip to content
This repository was archived by the owner on Nov 29, 2020. It is now read-only.

Commit 12f44fe

Browse files
committed
use umap_WT
1 parent 61d1c66 commit 12f44fe

File tree

6 files changed

+10
-14
lines changed

6 files changed

+10
-14
lines changed

BellmanFord.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ void InitializeSingleSource(GT& G, T s, umap<T, RelaxInfo<T, WT>>& inf) {
6161
}
6262

6363
template <typename T, typename WT>
64-
void Relax(T u, T v, umap<Edge<T>, WT, EdgeHash<size_t>>& w,
65-
umap<T, RelaxInfo<T, WT>>& inf) {
64+
void Relax(T u, T v, umap_WT& w, umap<T, RelaxInfo<T, WT>>& inf) {
6665
WT weight = w[Edge<T>(u, v, true)];
6766
if (inf[v] > inf[u] + weight) {
6867
inf[v].set_d(inf[u] + weight);
@@ -71,8 +70,7 @@ void Relax(T u, T v, umap<Edge<T>, WT, EdgeHash<size_t>>& w,
7170
}
7271

7372
template <typename GT, typename T, typename WT>
74-
bool BellmanFord(GT& G, umap<Edge<T>, WT, EdgeHash<size_t>>& w, T s,
75-
umap<T, RelaxInfo<T, WT>>& ans) {
73+
bool BellmanFord(GT& G, umap_WT& w, T s, umap<T, RelaxInfo<T, WT>>& ans) {
7674
InitializeSingleSource(G, s, ans);
7775
for (size_t i = 0; i < G.V.size() - 1; i++)
7876
for (auto j = G.all_edges(); !j.end(); j++)

DagShortestPaths.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131
#include "BellmanFord.cpp"
3232

3333
template <typename GT, typename T, typename WT>
34-
void DagShortestPaths(GT& G, umap<Edge<T>, WT, EdgeHash<size_t>>& w, T s,
35-
umap<T, RelaxInfo<T, WT>>& ans) {
34+
void DagShortestPaths(GT& G, umap_WT& w, T s, umap<T, RelaxInfo<T, WT>>& ans) {
3635
std::deque<T> order;
3736
TopologicalSort(G, order);
3837
InitializeSingleSource(G, s, ans);

Dijkstra.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
#include "BellmanFord.cpp"
3131

3232
template <typename GT, typename T, typename WT>
33-
void Dijkstra(GT& G, umap<Edge<T>, WT, EdgeHash<size_t>>& w, T s,
34-
umap<T, RelaxInfo<T, WT>>& ans) {
33+
void Dijkstra(GT& G, umap_WT& w, T s, umap<T, RelaxInfo<T, WT>>& ans) {
3534
using QT = std::pair<RelaxInfo<T, WT>, T>;
3635
InitializeSingleSource(G, s, ans);
3736
uset<T> S;

FordFulkerson.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
#include "BFS.cpp"
3030

3131
template <typename GT, typename T, typename WT>
32-
void FordFulkerson(GT& G, umap<Edge<T>, WT, EdgeHash<size_t>>& c,
33-
T s, T t, umap<Edge<T>, WT, EdgeHash<size_t>>& f) {
32+
void FordFulkerson(GT& G, umap_WT& c, T s, T t, umap_WT& f) {
3433
for (auto i = G.all_edges(); !i.end(); i++)
3534
f[*i] = 0;
3635
auto get_c = [&G, &c, &f](T u, T v) mutable -> WT {

Graph.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
#define uset typename std::unordered_set
3535
#define umap typename std::unordered_map
36+
#define umap_WT typename std::unordered_map<Edge<T>, WT, EdgeHash<T>>
3637

3738
template <typename T>
3839
class Edge {
@@ -496,7 +497,7 @@ void random_dag(Graph<T>& G, T v, size_t e) {
496497
}
497498

498499
template <typename WT, typename T, typename GT>
499-
void random_weight(GT& G, umap<Edge<T>, WT, EdgeHash<T>>& w, WT l, WT u) {
500+
void random_weight(GT& G, umap_WT& w, WT l, WT u) {
500501
std::random_device rd;
501502
std::uniform_int_distribution<T> d(l, u);
502503
for (auto i = G.all_edges(); !i.end(); i++)

Johnson.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
#include "Dijkstra.cpp"
3131

3232
template <typename GT, typename T, typename WT>
33-
Matrix<Weight<WT>> Johnson(GT& G, umap<Edge<T>, WT, EdgeHash<size_t>>& w) {
33+
Matrix<Weight<WT>> Johnson(GT& G, umap_WT& w) {
3434
static_assert(std::is_same<T, size_t>::value, "Only supports T = size_t");
3535
const size_t n = G.V.size();
3636
T s;
3737
GT G_prime = G;
38-
umap<Edge<T>, WT, EdgeHash<size_t>> w_prime = w;
38+
umap_WT w_prime = w;
3939
for (s = n; G.V.find(s) != G.V.end(); s++);
4040
for (auto i = G.V.begin(); i != G.V.end(); i++) {
4141
G_prime.add_edge(s, *i);
@@ -49,7 +49,7 @@ Matrix<Weight<WT>> Johnson(GT& G, umap<Edge<T>, WT, EdgeHash<size_t>>& w) {
4949
assert(!BF_ans[v].d.inf);
5050
h[v] = BF_ans[v].d.val;
5151
}
52-
umap<Edge<T>, WT, EdgeHash<size_t>> w_hat;
52+
umap_WT w_hat;
5353
for (auto i = G.all_edges(); !i.end(); i++)
5454
w_hat[*i] = w[*i] + h[i.s()] - h[i.d()];
5555
Matrix<Weight<WT>> D(n, n, WT());

0 commit comments

Comments
 (0)