Add a skiplist to the CBlockIndex structure.

This allows fast (O(log n)) access to far predecessor blocks.
Use it to speed up CChain::FindFork and CChain::GetLocator.
This commit is contained in:
Pieter Wuille
2014-06-25 00:56:47 +02:00
committed by Pieter Wuille
parent aa81564700
commit c9a0918330
2 changed files with 70 additions and 3 deletions

View File

@@ -677,6 +677,9 @@ public:
// pointer to the index of the predecessor of this block
CBlockIndex* pprev;
// pointer to the index of some further predecessor of this block
CBlockIndex* pskip;
// height of the entry in the chain. The genesis block has height 0
int nHeight;
@@ -716,6 +719,7 @@ public:
{
phashBlock = NULL;
pprev = NULL;
pskip = NULL;
nHeight = 0;
nFile = 0;
nDataPos = 0;
@@ -737,6 +741,7 @@ public:
{
phashBlock = NULL;
pprev = NULL;
pskip = NULL;
nHeight = 0;
nFile = 0;
nDataPos = 0;
@@ -869,10 +874,15 @@ public:
}
return false;
}
// Build the skiplist pointer for this entry.
void BuildSkip();
// Efficiently find an ancestor of this block.
CBlockIndex* GetAncestor(int height);
const CBlockIndex* GetAncestor(int height) const;
};
/** Used to marshal pointers into hashes for db storage. */
class CDiskBlockIndex : public CBlockIndex
{