diff --git a/src/avalanche/processor.h b/src/avalanche/processor.h --- a/src/avalanche/processor.h +++ b/src/avalanche/processor.h @@ -80,8 +80,8 @@ using BlockVoteMap = std::map; -using ProofVoteMap = std::map, VoteRecord, - ProofSharedPointerComparator>; +using ProofVoteMap = + std::map, VoteRecord, ProofComparator>; struct query_timeout {}; diff --git a/src/avalanche/proofcomparator.h b/src/avalanche/proofcomparator.h --- a/src/avalanche/proofcomparator.h +++ b/src/avalanche/proofcomparator.h @@ -13,16 +13,20 @@ namespace avalanche { /** - * Compare shared pointers to proof by score, then by id in case of equality. + * Compare proofs by score, then by id in case of equality. */ -struct ProofSharedPointerComparator { - bool operator()(const std::shared_ptr &lhs, - const std::shared_ptr &rhs) const { - uint32_t scoreLhs = lhs->getScore(); - uint32_t scoreRhs = rhs->getScore(); +struct ProofComparator { + bool operator()(const Proof &lhs, const Proof &rhs) const { + uint32_t scoreLhs = lhs.getScore(); + uint32_t scoreRhs = rhs.getScore(); return (scoreLhs != scoreRhs) ? scoreLhs > scoreRhs - : lhs->getId() < rhs->getId(); + : lhs.getId() < rhs.getId(); + } + + bool operator()(const std::shared_ptr &lhs, + const std::shared_ptr &rhs) const { + return (*this)(*lhs, *rhs); } }; diff --git a/src/avalanche/test/processor_tests.cpp b/src/avalanche/test/processor_tests.cpp --- a/src/avalanche/test/processor_tests.cpp +++ b/src/avalanche/test/processor_tests.cpp @@ -277,7 +277,7 @@ votes.reserve(numItems); // Votes are sorted by high score first - std::sort(items.begin(), items.end(), ProofSharedPointerComparator()); + std::sort(items.begin(), items.end(), ProofComparator()); for (auto &item : items) { votes.emplace_back(error, item->getId()); } diff --git a/src/avalanche/test/proofcomparator_tests.cpp b/src/avalanche/test/proofcomparator_tests.cpp --- a/src/avalanche/test/proofcomparator_tests.cpp +++ b/src/avalanche/test/proofcomparator_tests.cpp @@ -25,7 +25,7 @@ auto proofMinScore = buildRandomProof(MIN_VALID_PROOF_SCORE); auto proofMaxScore = buildRandomProof(std::numeric_limits::max()); - const ProofSharedPointerComparator comparator; + const ProofComparator comparator; auto prevProof = proofMinScore; for (size_t i = 0; i < 100; i++) {