Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/proofcomparator.h
// Copyright (c) 2021 The Bitcoin developers | // Copyright (c) 2021 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_AVALANCHE_PROOFCOMPARATOR_H | #ifndef BITCOIN_AVALANCHE_PROOFCOMPARATOR_H | ||||
#define BITCOIN_AVALANCHE_PROOFCOMPARATOR_H | #define BITCOIN_AVALANCHE_PROOFCOMPARATOR_H | ||||
#include <avalanche/proof.h> | #include <avalanche/proof.h> | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <memory> | #include <memory> | ||||
namespace avalanche { | namespace avalanche { | ||||
/** | /** | ||||
* Compare proof references by pointer address. | |||||
*/ | |||||
struct ProofRefComparatorByAddress { | |||||
bool operator()(const ProofRef &lhs, const ProofRef &rhs) const { | |||||
return lhs.get() < rhs.get(); | |||||
} | |||||
}; | |||||
/** | |||||
* Compare proofs by score, then by id in case of equality. | * Compare proofs by score, then by id in case of equality. | ||||
*/ | */ | ||||
struct ProofComparatorByScore { | struct ProofComparatorByScore { | ||||
bool operator()(const Proof &lhs, const Proof &rhs) const { | bool operator()(const Proof &lhs, const Proof &rhs) const { | ||||
uint32_t scoreLhs = lhs.getScore(); | uint32_t scoreLhs = lhs.getScore(); | ||||
uint32_t scoreRhs = rhs.getScore(); | uint32_t scoreRhs = rhs.getScore(); | ||||
return (scoreLhs != scoreRhs) ? scoreLhs > scoreRhs | return (scoreLhs != scoreRhs) ? scoreLhs > scoreRhs | ||||
▲ Show 20 Lines • Show All 50 Lines • Show Last 20 Lines |