Changeset View
Changeset View
Standalone View
Standalone View
src/timedata.h
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | public: | ||||
T median() const { | T median() const { | ||||
int vSortedSize = vSorted.size(); | int vSortedSize = vSorted.size(); | ||||
assert(vSortedSize > 0); | assert(vSortedSize > 0); | ||||
if (vSortedSize & 1) { | if (vSortedSize & 1) { | ||||
// Odd number of elements | // Odd number of elements | ||||
return vSorted[vSortedSize / 2]; | return vSorted[vSortedSize / 2]; | ||||
} else { | } else { | ||||
// Even number of elements | // Even number of elements | ||||
return (vSorted[vSortedSize / 2 - 1] + vSorted[vSortedSize / 2]) / | auto left = vSorted[vSortedSize / 2 - 1]; | ||||
2; | auto right = vSorted[vSortedSize / 2]; | ||||
return left / 2 + right / 2 + (left & right & 1); | |||||
} | } | ||||
} | } | ||||
int size() const { return vValues.size(); } | int size() const { return vValues.size(); } | ||||
std::vector<T> sorted() const { return vSorted; } | std::vector<T> sorted() const { return vSorted; } | ||||
}; | }; | ||||
/** Functions to keep track of adjusted P2P time */ | /** Functions to keep track of adjusted P2P time */ | ||||
int64_t GetTimeOffset(); | int64_t GetTimeOffset(); | ||||
int64_t GetAdjustedTime(); | int64_t GetAdjustedTime(); | ||||
void AddTimeData(const CNetAddr &ip, int64_t nTime); | void AddTimeData(const CNetAddr &ip, int64_t nTime); | ||||
#endif // BITCOIN_TIMEDATA_H | #endif // BITCOIN_TIMEDATA_H |