#include "Mempool.h" #include #include #include auto Mempool::calcCompactFeeHistogram(double binSize) const -> FeeHistogramVec { FeeHistogramVec ret; std::map> histogram; // sorted map, descending order by key for (const auto & [txid, tx] : txs) { const auto feeRate = unsigned(tx->fee / bitcoin::Amount::satoshi()) // sats / std::max(tx->sizeBytes, 1u); // per byte histogram[feeRate] += tx->sizeBytes; // accumulate size by feeRate } // now, compact the bins ret.reserve(8); unsigned cumSize = 0; double r = 0.; for (const auto & [feeRate, size] : histogram) { cumSize += size; if (cumSize + r > binSize) { ret.emplace_back(FeeHistogramItem{feeRate, cumSize}); r += double(cumSize) - binSize; cumSize = 0; binSize *= 1.1; } } ret.shrink_to_fit(); // save memory return ret; }