Add heapId in KVstore tree node (#20)

* add heapId in node

* fixed bugs

* fixed bug

* fix

* Revert "fix"

This reverts commit ebaca3a30d.
This commit is contained in:
dssgsra 2017-04-14 00:10:18 +08:00 committed by GitHub
parent 13204bcd3f
commit f2c6acffce
6 changed files with 36 additions and 6 deletions

View File

@ -92,10 +92,12 @@ ISHeap::insert(ISNode* _np)
if (_np->getRank() >= this->heap[j]->getRank())
break;
heap[i] = heap[j];
heap[i]->heapId = i;
//this->npmap[k].pos = i; //adjust the position
i = j;
}
this->heap[i] = _np;
_np->heapId = i;
this->length++;
return true;
}
@ -110,6 +112,7 @@ ISHeap::remove()
}
//Node* tp = this->heap[0];
this->length--;
this->heap[0]->heapId = -1;
if (this->length == 0)
return true;
ISNode* xp = this->heap[this->length];
@ -121,10 +124,12 @@ ISHeap::remove()
if (xp->getRank() <= this->heap[j]->getRank())
break;
this->heap[i] = this->heap[j];
this->heap[i]->heapId = i;
i = j;
j = 2 * i + 1;
}
this->heap[i] = xp;
this->heap[i]->heapId = i;
return true;
}
@ -133,9 +138,10 @@ ISHeap::modify(ISNode* _np, bool _flag) //control direction
{
//search and adjust
unsigned i, j;
for (i = 0; i < this->length; ++i)
if (this->heap[i] == _np)
break;
i = _np->heapId;
// for (i = 0; i < this->length; ++i)
// if (this->heap[i] == _np)
// break;
if (_flag == true) //move up
{
while (i != 0)
@ -144,7 +150,9 @@ ISHeap::modify(ISNode* _np, bool _flag) //control direction
if (_np->getRank() < heap[j]->getRank())
{
heap[i] = heap[j];
heap[i]->heapId = i;
heap[j] = _np;
heap[j]->heapId = j;
i = j;
}
else
@ -161,7 +169,9 @@ ISHeap::modify(ISNode* _np, bool _flag) //control direction
if (heap[j]->getRank() < _np->getRank())
{
heap[i] = heap[j];
heap[i]->heapId = i;
heap[j] = _np;
heap[j]->heapId = j;
i = j;
}
else

View File

@ -28,12 +28,14 @@ ISNode::ISNode()
{
store = flag = 0;
flag |= NF_IM;
heapId = -1;
AllocKeys();
}
ISNode::ISNode(bool isVirtual)
{
store = flag = 0;
heapId = -1;
if (!isVirtual)
{
flag |= NF_IM;

View File

@ -30,6 +30,8 @@ public:
static const unsigned NF_KN = 0x07f000; //NOTICE: decided by DEGREE
static const unsigned INTL_SIZE = sizeof(int) * MAX_KEY_NUM;
static const unsigned LEAF_SIZE = INTL_SIZE + sizeof(Bstr) * MAX_KEY_NUM;
int heapId;
protected:
unsigned store; //store address, the BLock index
unsigned flag; //NF_RK, NF_IL,NF_ID, NF_IV, propety
@ -41,6 +43,7 @@ protected:
public:
ISNode();
ISNode(bool isVirtual);
bool isLeaf() const;
bool isDirty() const;
void setDirty();

View File

@ -92,10 +92,12 @@ SIHeap::insert(SINode* _np)
if (_np->getRank() >= this->heap[j]->getRank())
break;
heap[i] = heap[j];
heap[i]->heapId = i;
//this->npmap[k].pos = i; //adjust the position
i = j;
}
this->heap[i] = _np;
_np->heapId = i;
this->length++;
return true;
}
@ -110,6 +112,7 @@ SIHeap::remove()
}
//Node* tp = this->heap[0];
this->length--;
this->heap[0]->heapId = -1;
if (this->length == 0)
return true;
SINode* xp = this->heap[this->length];
@ -121,10 +124,12 @@ SIHeap::remove()
if (xp->getRank() <= this->heap[j]->getRank())
break;
this->heap[i] = this->heap[j];
this->heap[i]->heapId = i;
i = j;
j = 2 * i + 1;
}
this->heap[i] = xp;
this->heap[i]->heapId = i;
return true;
}
@ -133,9 +138,10 @@ SIHeap::modify(SINode* _np, bool _flag) //control direction
{
//search and adjust
unsigned i, j;
for (i = 0; i < this->length; ++i)
if (this->heap[i] == _np)
break;
i = _np->heapId;
// for (i = 0; i < this->length; ++i)
// if (this->heap[i] == _np)
// break;
if (_flag == true) //move up
{
while (i != 0)
@ -144,7 +150,9 @@ SIHeap::modify(SINode* _np, bool _flag) //control direction
if (_np->getRank() < heap[j]->getRank())
{
heap[i] = heap[j];
heap[i]->heapId = i;
heap[j] = _np;
heap[j]->heapId = j;
i = j;
}
else
@ -161,7 +169,9 @@ SIHeap::modify(SINode* _np, bool _flag) //control direction
if (heap[j]->getRank() < _np->getRank())
{
heap[i] = heap[j];
heap[i]->heapId = i;
heap[j] = _np;
heap[j]->heapId = j;
i = j;
}
else

View File

@ -28,12 +28,14 @@ SINode::SINode()
{
store = flag = 0;
flag |= NF_IM;
heapId = -1;
AllocKeys();
}
SINode::SINode(bool isVirtual)
{
store = flag = 0;
heapId = -1;
if (!isVirtual)
{
flag |= NF_IM;

View File

@ -31,6 +31,8 @@ public:
static const unsigned NF_KN = 0x07f000; //NOTICE: decided by DEGREE
static const unsigned INTL_SIZE = sizeof(Bstr) * MAX_KEY_NUM;
static const unsigned LEAF_SIZE = sizeof(int) * MAX_KEY_NUM + INTL_SIZE;
int heapId;
protected:
unsigned store; //store address, the BLock index
unsigned flag; //NF_RK, NF_IL,NF_ID, NF_IV, propety
@ -42,6 +44,7 @@ protected:
public:
SINode();
SINode(bool isVirtual);
bool isLeaf() const;
bool isDirty() const;
void setDirty();