MCPcopy Create free account
hub / github.com/ElementsProject/elements / CalculateTruncatedMedian

Function CalculateTruncatedMedian

src/rpc/blockchain.cpp:2253–2266  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2251
2252template<typename T>
2253static T CalculateTruncatedMedian(std::vector<T>& scores)
2254{
2255 size_t size = scores.size();
2256 if (size == 0) {
2257 return 0;
2258 }
2259
2260 std::sort(scores.begin(), scores.end());
2261 if (size % 2 == 0) {
2262 return (scores[size / 2 - 1] + scores[size / 2]) / 2;
2263 } else {
2264 return scores[size / 2];
2265 }
2266}
2267
2268void CalculatePercentilesByWeight(CAmount result[NUM_GETBLOCKSTATS_PERCENTILES], std::vector<std::pair<CAmount, int64_t>>& scores, int64_t total_weight)
2269{

Callers 1

getblockstatsFunction · 0.85

Calls 3

sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected