CBlockIndex::GetMedianTimePast method

From Peercoin Wiki
Jump to: navigation, search

https://github.com/ppcoin/ppcoin/blob/v0.4.0ppc/src/main.h#L1305

int64 CBlockIndex::GetMedianTimePast() const
{
    int64 pmedian[nMedianTimeSpan];
    int64* pbegin = &pmedian[nMedianTimeSpan];
    int64* pend = &pmedian[nMedianTimeSpan];

    const CBlockIndex* pindex = this;
    for (int i = 0; i < nMedianTimeSpan && pindex; i++, pindex = pindex->pprev)
        *(--pbegin) = pindex->GetBlockTime();

    std::sort(pbegin, pend);
    return pbegin[(pend - pbegin)/2];
}