refactor: cleanup map comparison struct definitions

This commit is contained in:
Kittywhiskers Van Gogh 2023-09-25 20:19:30 +05:30
parent 5faf29d318
commit 5950f7ce35
2 changed files with 11 additions and 22 deletions

View File

@ -10,6 +10,7 @@
#include <amount.h>
#include <chrono>
#include <tuple>
namespace AddressType {
enum AddressType {
@ -71,23 +72,10 @@ struct CMempoolAddressDeltaKey
struct CMempoolAddressDeltaKeyCompare
{
bool operator()(const CMempoolAddressDeltaKey& a, const CMempoolAddressDeltaKey& b) const {
if (a.type == b.type) {
if (a.addressBytes == b.addressBytes) {
if (a.txhash == b.txhash) {
if (a.index == b.index) {
return a.spending < b.spending;
} else {
return a.index < b.index;
}
} else {
return a.txhash < b.txhash;
}
} else {
return a.addressBytes < b.addressBytes;
}
} else {
return a.type < b.type;
}
auto to_tuple = [](const CMempoolAddressDeltaKey& obj) {
return std::tie(obj.type, obj.addressBytes, obj.txhash, obj.index, obj.spending);
};
return to_tuple(a) < to_tuple(b);
}
};

View File

@ -12,6 +12,8 @@
#include <serialize.h>
#include <uint256.h>
#include <tuple>
struct CSpentIndexKey {
uint256 txid;
unsigned int outputIndex;
@ -80,11 +82,10 @@ struct CSpentIndexValue {
struct CSpentIndexKeyCompare
{
bool operator()(const CSpentIndexKey& a, const CSpentIndexKey& b) const {
if (a.txid == b.txid) {
return a.outputIndex < b.outputIndex;
} else {
return a.txid < b.txid;
}
auto to_tuple = [](const CSpentIndexKey& obj) {
return std::tie(obj.txid, obj.outputIndex);
};
return to_tuple(a) < to_tuple(b);
}
};