Repository: bitcoin/bitcoin
File: src/test/fuzz/cluster_linearize.cpp (C++)

Code before:
// Copyright (c) The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <cluster_linearize.h>
#include <random.h>
#include <serialize.h>
#include <streams.h>
#include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>
#include <test/util/cluster_linearize.h>
#include <util/bitset.h>
#include <util/feefrac.h>

#include <algorithm>
#include <cstdint>
#include <utility>
#include <vector>

using namespace cluster_linearize;

namespace {

/** A simple finder class for candidate sets.
 *
 * This class matches SearchCandidateFinder in interface and behavior, though with fewer
 * optimizations.
 */
template<typename SetType>
class SimpleCandidateFinder
{
    /** Internal dependency graph. */
    const DepGraph<SetType>& m_depgraph;
    /** Which transaction are left to include. */
    SetType m_todo;

public:
    /** Construct an SimpleCandidateFinder for a given graph. */
    SimpleCandidateFinder(const DepGraph<SetType>& depgraph LIFETIMEBOUND) noexcept :
        m_depgraph(depgraph), m_todo{depgraph.Positions()} {}

    /** Remove a set of transactions from the set of to-be-linearized ones. */
    void MarkDone(SetType select) noexcept { m_todo -= select; }

    /** Determine whether unlinearized transactions remain. */
    bool AllDone() const noexcept { return m_todo.None(); }

    /** Find a candidate set using at most max_iterations iterations, and the number of iterations

Review comment (refactor):
In "clusterlin: add big comment explaning the relation between tests"  9877e275b95400e46f336bc34ce41ed68ce43683

I like the new comment addition, just the first description is a bit unclear because the line is diagonal

Maybe this suggestion will be clearer?
```diff
diff --git a/src/test/fuzz/cluster_linearize.cpp b/src/test/fuzz/cluster_linearize.cpp
index 7d0fb5fbec0..8820e3b3eaa 100644
--- a/src/test/fuzz/cluster_linearize.cpp
+++ b/src/test/fuzz/cluster_linearize.cpp
@@ -18,10 +18,11 @@
 #include <utility>
 
 /*
- * The tests in this file primarily test the candidate finder classes and linearization algorithms.
+ * The tests in this file primarily cover the candidate finder classes and linearization algorithms.
  *
- *   <----: the right side is tested in the named test by comparison with the left side
- *   <<---: right side is implemented using left side
+ *   <----: An implementation (at the start of the line --) is tested in the test marked with *
+ *          by comparison with other implementations (at the end of the line ->).
+ *   <<---: The right side is implemented using the left side.
  *
  *   +-----------------------+
  *   | SearchCandidateFinder | <<---------------------\
@@ -38,7 +39,7 @@
  *     |                            |                    |        ||
  *     |                            |                    |        vv  TEST CODE
  *     |                            |                    |
- *     |-clusterlin_search_finder   |                    |-clusterlin_linearize
+ *     |-clusterlin_search_finder*  |                    |-clusterlin_linearize*
  *     |                            |                    |
  *     v                            |                    v
  *   +-----------------------+      |               +-----------------+
@@ -47,7 +48,7 @@
  *                  |               |                    |
  *                  +---------------/                    |
  *                  |                                    |
- *                  |-clusterlin_simple_finder           |-clusterlin_simple_linearize
+ *                  |-clusterlin_simple_finder*          |-clusterlin_simple_linearize*
  *                  v                                    v
  *   +---------------------------+                  +---------------------+
  *   | ExhaustiveCandidateFinder |                  | ExhaustiveLinearize |
abubakarismail@Abubakars-MacBook-Pro ~/D/W/b/bitcoin ((9877e275))> 
```

Code after:
// Copyright (c) The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <cluster_linearize.h>
#include <random.h>
#include <serialize.h>
#include <streams.h>
#include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>
#include <test/util/cluster_linearize.h>
#include <util/bitset.h>
#include <util/feefrac.h>

#include <algorithm>
#include <cstdint>
#include <utility>
#include <vector>

/*
 * The tests in this file primarily cover the candidate finder classes and linearization algorithms.
 *
 *   <----: An implementation (at the start of the line --) is tested in the test marked with *,
 *          possibly by comparison with other implementations (at the end of the line ->).
 *   <<---: The right side is implemented using the left side.
 *
 *   +-----------------------+
 *   | SearchCandidateFinder | <<---------------------\
 *   +-----------------------+                        |
 *     |                                            +-----------+
 *     |                                            | Linearize |
 *     |                                            +-----------+
 *     |        +-------------------------+           |  |
 *     |        | AncestorCandidateFinder | <<--------/  |
 *     |        +-------------------------+              |
 *     |          |                     ^                |        ^^  PRODUCTION CODE
 *     |          |                     |                |        ||
 *  ==============================================================================================
 *     |          |                     |                |        ||
 *     | clusterlin_ancestor_finder*    |                |        vv  TEST CODE
 *     |                                |                |
 *     |-clusterlin_search_finder*      |                |-clusterlin_linearize*
 *     |                                |                |
 *     v                                |                v
 *   +-----------------------+          |           +-----------------+
 *   | SimpleCandidateFinder | <<-------------------| SimpleLinearize |
 *   +-----------------------+          |           +-----------------+
 *                  |                   |                |