1
0
Fork 0

Minor code and comment cleanups

This commit is contained in:
Joris van Rantwijk 2024-11-23 22:59:40 +01:00
parent f0773eb84b
commit 02917b2caf
2 changed files with 24 additions and 40 deletions

View File

@ -235,9 +235,9 @@ public:
* and adds them to this queue.
*
* After merging, this queue retains references to the sub-queues.
* This may be used later to split (undo the merge step).
* These may be used later to split (undo the merge step).
*
* This function takes time O(len(sub_queues) * log(n)).
* This function takes time O(n_sub_queues * log(n)).
*/
template <typename QueueIterator>
void merge(QueueIterator sub_queues_begin, QueueIterator sub_queues_end)
@ -302,7 +302,7 @@ public:
*
* After splitting, this queue will be empty.
*
* This function takes time O(k * log(n)).
* This function takes time O(n_sub_queues * log(n)).
*/
void split()
{
@ -774,10 +774,6 @@ private:
/**
* Join a left subtree, middle node and right subtree together.
*
* The index of all nodes in the left subtree must be less than
* the index of the middle node. The index of all nodes in
* the right subtree must be greater than the middle node.
*
* The left or right subtree may initially be a child of the middle
* node; such links will be broken as needed.
*
@ -826,7 +822,7 @@ private:
/** Name of this queue. */
const NameType name_;
/** Root node of the queue, or "nullptr" if the queue is empty. */
/** Root node of the tree, or "nullptr" if the queue is empty. */
Node* tree_;
/** Left-most node that belongs to this queue. */
@ -853,7 +849,7 @@ private:
* - Insert an element into the queue.
* - Remove an element from the queue.
* - Change the priority of a given element.
* - Find the element with lowest priority in a given queue.
* - Find the element with lowest priority in the queue.
*/
template <typename PrioType,
typename DataType>
@ -896,7 +892,7 @@ public:
* Return the priority of this node in the queue.
*
* The node must be contained in a queue.
* This function takes time O(log(n)).
* This function takes time O(1).
*/
PrioType prio() const
{

View File

@ -38,6 +38,7 @@ using VertexPair = std::pair<VertexId, VertexId>;
/** Type representing a weighted edge.
*
* @tparam WeightType Numeric type used to represent edge weights.
* This must be a signed type.
*/
template <typename WeightType>
struct Edge
@ -45,6 +46,9 @@ struct Edge
static_assert(std::numeric_limits<WeightType>::is_specialized,
"Edge weight must be a numeric type");
static_assert(std::numeric_limits<WeightType>::is_signed,
"WeightType must be signed");
/** Incident vertices. */
VertexPair vt;
@ -84,13 +88,6 @@ enum BlossomLabel { LABEL_NONE = 0, LABEL_S = 1, LABEL_T = 2 };
* ** private helper functions **
* ************************************************** */
/** Return a pair of vertices in flipped order. */
inline VertexPair flip_vertex_pair(const VertexPair& vt)
{
return std::make_pair(vt.second, vt.first);
}
/**
* Check that the input is a valid graph.
*
@ -283,8 +280,6 @@ template <typename WeightType> struct NonTrivialBlossom;
/**
* Represents a blossom.
*
* A blossom is an odd-length alternating cycle over sub-blossoms.
* An alternating path consists of alternating matched and unmatched edges.
* An alternating cycle is an alternating path that starts and ends in
@ -307,7 +302,7 @@ struct Blossom
/** Parent of this blossom, or "nullptr" if this blossom is top-level. */
NonTrivialBlossom<WeightType>* parent;
/** Index of the base vertex of this blossom. */
/** Base vertex of this blossom. */
VertexId base_vertex;
/** Label S or T if this is a top-level blossom in an alternating tree. */
@ -377,8 +372,6 @@ public:
* ************************************************** */
/**
* Represents a non-trivial blossom.
*
* A non-trivial blossom is a blossom that contains multiple sub-blossoms
* (at least 3 sub-blossoms, since all blossoms have odd length).
*
@ -585,8 +578,7 @@ public:
/**
* Each vertex is associated with a trivial blossom.
*
* "trivial_blossom[x]" is the trivial blossom that contains only
* vertex "x".
* "trivial_blossom[x]" is the trivial blossom that contains vertex "x".
*/
std::vector<BlossomT> trivial_blossom;
@ -656,7 +648,7 @@ public:
*/
EdgeQueueT delta3_queue;
/** For each edge, a node in delta3_queue. */
/** For each edge, an optional node in delta3_queue. */
std::vector<typename EdgeQueueT::Node> delta3_node;
/**
@ -1193,20 +1185,20 @@ public:
*/
void remove_alternating_tree(VertexId x, VertexId y)
{
auto do_blossom = [this,x,y](BlossomT* blossom) {
if (blossom->label != LABEL_NONE) {
assert(! blossom->parent);
if ((blossom->tree_root == x) || (blossom->tree_root == y)) {
reset_blossom_label(blossom);
}
}
};
for (BlossomT& blossom : trivial_blossom) {
do_blossom(&blossom);
if ((! blossom.parent)
&& (blossom.label != LABEL_NONE)
&& (blossom.tree_root == x || blossom.tree_root == y)) {
reset_blossom_label(&blossom);
}
}
for (BlossomT& blossom : nontrivial_blossom) {
do_blossom(&blossom);
if ((! blossom.parent)
&& (blossom.label != LABEL_NONE)
&& (blossom.tree_root == x || blossom.tree_root == y)) {
reset_blossom_label(&blossom);
}
}
}
@ -2373,10 +2365,6 @@ template <typename WeightType>
std::vector<VertexPair> maximum_weight_matching(
const std::vector<Edge<WeightType>>& edges)
{
// Edge weight type must be signed.
static_assert(std::numeric_limits<WeightType>::is_signed,
"WeightType must be signed");
// Check that the input meets all constraints.
impl::check_input_graph(edges);