1
0
Fork 0

Remove dependence on Boost.Hash

This commit is contained in:
Joris van Rantwijk 2023-05-18 09:55:55 +02:00
parent 731b202af3
commit 9c669f2d03
1 changed files with 11 additions and 13 deletions

View File

@ -1,8 +1,5 @@
/**
* Algorithm for finding a maximum weight matching in general graphs.
*
* Depends on Boost.Hash.
* Tested with Boost v1.74, available from https://www.boost.org/
*/
#ifndef MWMATCHING_H_
@ -18,12 +15,9 @@
#include <stack>
#include <stdexcept>
#include <tuple>
#include <unordered_set>
#include <utility>
#include <vector>
#include <boost/functional/hash.hpp>
namespace mwmatching {
@ -95,7 +89,7 @@ inline VertexPair flip_vertex_pair(const VertexPair& vt)
* The graph may not have self-edges or multiple edges between
* the same pair of vertices. Edge weights must be within a valid range.
*
* This function takes time O(m).
* This function takes time O(m * log(m)).
*
* @param edges Vector of weighted edges defining the graph.
* @throw std::invalid_argument If the input graph is not valid.
@ -136,18 +130,22 @@ void check_input_graph(const std::vector<Edge<WeightType>>& edges)
}
// Check that the graph does not contain duplicate edges.
std::unordered_set<VertexPair, boost::hash<VertexPair>> edges_seen;
std::vector<VertexPair> edge_endpoints;
edge_endpoints.reserve(edges.size());
for (const Edge<WeightType>& edge : edges) {
VertexPair vt = edge.vt;
if (vt.first > vt.second) {
vt = flip_vertex_pair(vt);
std::swap(vt.first, vt.second);
}
auto status = edges_seen.insert(vt);
if (!status.second) {
edge_endpoints.push_back(vt);
}
std::sort(edge_endpoints.begin(), edge_endpoints.end());
if (std::unique(edge_endpoints.begin(), edge_endpoints.end())
!= edge_endpoints.end()) {
throw std::invalid_argument("Duplicate edges are not supported");
}
}
}
/**