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:
parent
13204bcd3f
commit
f2c6acffce
|
@ -92,10 +92,12 @@ ISHeap::insert(ISNode* _np)
|
||||||
if (_np->getRank() >= this->heap[j]->getRank())
|
if (_np->getRank() >= this->heap[j]->getRank())
|
||||||
break;
|
break;
|
||||||
heap[i] = heap[j];
|
heap[i] = heap[j];
|
||||||
|
heap[i]->heapId = i;
|
||||||
//this->npmap[k].pos = i; //adjust the position
|
//this->npmap[k].pos = i; //adjust the position
|
||||||
i = j;
|
i = j;
|
||||||
}
|
}
|
||||||
this->heap[i] = _np;
|
this->heap[i] = _np;
|
||||||
|
_np->heapId = i;
|
||||||
this->length++;
|
this->length++;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -110,6 +112,7 @@ ISHeap::remove()
|
||||||
}
|
}
|
||||||
//Node* tp = this->heap[0];
|
//Node* tp = this->heap[0];
|
||||||
this->length--;
|
this->length--;
|
||||||
|
this->heap[0]->heapId = -1;
|
||||||
if (this->length == 0)
|
if (this->length == 0)
|
||||||
return true;
|
return true;
|
||||||
ISNode* xp = this->heap[this->length];
|
ISNode* xp = this->heap[this->length];
|
||||||
|
@ -121,10 +124,12 @@ ISHeap::remove()
|
||||||
if (xp->getRank() <= this->heap[j]->getRank())
|
if (xp->getRank() <= this->heap[j]->getRank())
|
||||||
break;
|
break;
|
||||||
this->heap[i] = this->heap[j];
|
this->heap[i] = this->heap[j];
|
||||||
|
this->heap[i]->heapId = i;
|
||||||
i = j;
|
i = j;
|
||||||
j = 2 * i + 1;
|
j = 2 * i + 1;
|
||||||
}
|
}
|
||||||
this->heap[i] = xp;
|
this->heap[i] = xp;
|
||||||
|
this->heap[i]->heapId = i;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,9 +138,10 @@ ISHeap::modify(ISNode* _np, bool _flag) //control direction
|
||||||
{
|
{
|
||||||
//search and adjust
|
//search and adjust
|
||||||
unsigned i, j;
|
unsigned i, j;
|
||||||
for (i = 0; i < this->length; ++i)
|
i = _np->heapId;
|
||||||
if (this->heap[i] == _np)
|
// for (i = 0; i < this->length; ++i)
|
||||||
break;
|
// if (this->heap[i] == _np)
|
||||||
|
// break;
|
||||||
if (_flag == true) //move up
|
if (_flag == true) //move up
|
||||||
{
|
{
|
||||||
while (i != 0)
|
while (i != 0)
|
||||||
|
@ -144,7 +150,9 @@ ISHeap::modify(ISNode* _np, bool _flag) //control direction
|
||||||
if (_np->getRank() < heap[j]->getRank())
|
if (_np->getRank() < heap[j]->getRank())
|
||||||
{
|
{
|
||||||
heap[i] = heap[j];
|
heap[i] = heap[j];
|
||||||
|
heap[i]->heapId = i;
|
||||||
heap[j] = _np;
|
heap[j] = _np;
|
||||||
|
heap[j]->heapId = j;
|
||||||
i = j;
|
i = j;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -161,7 +169,9 @@ ISHeap::modify(ISNode* _np, bool _flag) //control direction
|
||||||
if (heap[j]->getRank() < _np->getRank())
|
if (heap[j]->getRank() < _np->getRank())
|
||||||
{
|
{
|
||||||
heap[i] = heap[j];
|
heap[i] = heap[j];
|
||||||
|
heap[i]->heapId = i;
|
||||||
heap[j] = _np;
|
heap[j] = _np;
|
||||||
|
heap[j]->heapId = j;
|
||||||
i = j;
|
i = j;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -28,12 +28,14 @@ ISNode::ISNode()
|
||||||
{
|
{
|
||||||
store = flag = 0;
|
store = flag = 0;
|
||||||
flag |= NF_IM;
|
flag |= NF_IM;
|
||||||
|
heapId = -1;
|
||||||
AllocKeys();
|
AllocKeys();
|
||||||
}
|
}
|
||||||
|
|
||||||
ISNode::ISNode(bool isVirtual)
|
ISNode::ISNode(bool isVirtual)
|
||||||
{
|
{
|
||||||
store = flag = 0;
|
store = flag = 0;
|
||||||
|
heapId = -1;
|
||||||
if (!isVirtual)
|
if (!isVirtual)
|
||||||
{
|
{
|
||||||
flag |= NF_IM;
|
flag |= NF_IM;
|
||||||
|
|
|
@ -30,6 +30,8 @@ public:
|
||||||
static const unsigned NF_KN = 0x07f000; //NOTICE: decided by DEGREE
|
static const unsigned NF_KN = 0x07f000; //NOTICE: decided by DEGREE
|
||||||
static const unsigned INTL_SIZE = sizeof(int) * MAX_KEY_NUM;
|
static const unsigned INTL_SIZE = sizeof(int) * MAX_KEY_NUM;
|
||||||
static const unsigned LEAF_SIZE = INTL_SIZE + sizeof(Bstr) * MAX_KEY_NUM;
|
static const unsigned LEAF_SIZE = INTL_SIZE + sizeof(Bstr) * MAX_KEY_NUM;
|
||||||
|
|
||||||
|
int heapId;
|
||||||
protected:
|
protected:
|
||||||
unsigned store; //store address, the BLock index
|
unsigned store; //store address, the BLock index
|
||||||
unsigned flag; //NF_RK, NF_IL,NF_ID, NF_IV, propety
|
unsigned flag; //NF_RK, NF_IL,NF_ID, NF_IV, propety
|
||||||
|
@ -41,6 +43,7 @@ protected:
|
||||||
public:
|
public:
|
||||||
ISNode();
|
ISNode();
|
||||||
ISNode(bool isVirtual);
|
ISNode(bool isVirtual);
|
||||||
|
|
||||||
bool isLeaf() const;
|
bool isLeaf() const;
|
||||||
bool isDirty() const;
|
bool isDirty() const;
|
||||||
void setDirty();
|
void setDirty();
|
||||||
|
|
|
@ -92,10 +92,12 @@ SIHeap::insert(SINode* _np)
|
||||||
if (_np->getRank() >= this->heap[j]->getRank())
|
if (_np->getRank() >= this->heap[j]->getRank())
|
||||||
break;
|
break;
|
||||||
heap[i] = heap[j];
|
heap[i] = heap[j];
|
||||||
|
heap[i]->heapId = i;
|
||||||
//this->npmap[k].pos = i; //adjust the position
|
//this->npmap[k].pos = i; //adjust the position
|
||||||
i = j;
|
i = j;
|
||||||
}
|
}
|
||||||
this->heap[i] = _np;
|
this->heap[i] = _np;
|
||||||
|
_np->heapId = i;
|
||||||
this->length++;
|
this->length++;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -110,6 +112,7 @@ SIHeap::remove()
|
||||||
}
|
}
|
||||||
//Node* tp = this->heap[0];
|
//Node* tp = this->heap[0];
|
||||||
this->length--;
|
this->length--;
|
||||||
|
this->heap[0]->heapId = -1;
|
||||||
if (this->length == 0)
|
if (this->length == 0)
|
||||||
return true;
|
return true;
|
||||||
SINode* xp = this->heap[this->length];
|
SINode* xp = this->heap[this->length];
|
||||||
|
@ -121,10 +124,12 @@ SIHeap::remove()
|
||||||
if (xp->getRank() <= this->heap[j]->getRank())
|
if (xp->getRank() <= this->heap[j]->getRank())
|
||||||
break;
|
break;
|
||||||
this->heap[i] = this->heap[j];
|
this->heap[i] = this->heap[j];
|
||||||
|
this->heap[i]->heapId = i;
|
||||||
i = j;
|
i = j;
|
||||||
j = 2 * i + 1;
|
j = 2 * i + 1;
|
||||||
}
|
}
|
||||||
this->heap[i] = xp;
|
this->heap[i] = xp;
|
||||||
|
this->heap[i]->heapId = i;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,9 +138,10 @@ SIHeap::modify(SINode* _np, bool _flag) //control direction
|
||||||
{
|
{
|
||||||
//search and adjust
|
//search and adjust
|
||||||
unsigned i, j;
|
unsigned i, j;
|
||||||
for (i = 0; i < this->length; ++i)
|
i = _np->heapId;
|
||||||
if (this->heap[i] == _np)
|
// for (i = 0; i < this->length; ++i)
|
||||||
break;
|
// if (this->heap[i] == _np)
|
||||||
|
// break;
|
||||||
if (_flag == true) //move up
|
if (_flag == true) //move up
|
||||||
{
|
{
|
||||||
while (i != 0)
|
while (i != 0)
|
||||||
|
@ -144,7 +150,9 @@ SIHeap::modify(SINode* _np, bool _flag) //control direction
|
||||||
if (_np->getRank() < heap[j]->getRank())
|
if (_np->getRank() < heap[j]->getRank())
|
||||||
{
|
{
|
||||||
heap[i] = heap[j];
|
heap[i] = heap[j];
|
||||||
|
heap[i]->heapId = i;
|
||||||
heap[j] = _np;
|
heap[j] = _np;
|
||||||
|
heap[j]->heapId = j;
|
||||||
i = j;
|
i = j;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -161,7 +169,9 @@ SIHeap::modify(SINode* _np, bool _flag) //control direction
|
||||||
if (heap[j]->getRank() < _np->getRank())
|
if (heap[j]->getRank() < _np->getRank())
|
||||||
{
|
{
|
||||||
heap[i] = heap[j];
|
heap[i] = heap[j];
|
||||||
|
heap[i]->heapId = i;
|
||||||
heap[j] = _np;
|
heap[j] = _np;
|
||||||
|
heap[j]->heapId = j;
|
||||||
i = j;
|
i = j;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -28,12 +28,14 @@ SINode::SINode()
|
||||||
{
|
{
|
||||||
store = flag = 0;
|
store = flag = 0;
|
||||||
flag |= NF_IM;
|
flag |= NF_IM;
|
||||||
|
heapId = -1;
|
||||||
AllocKeys();
|
AllocKeys();
|
||||||
}
|
}
|
||||||
|
|
||||||
SINode::SINode(bool isVirtual)
|
SINode::SINode(bool isVirtual)
|
||||||
{
|
{
|
||||||
store = flag = 0;
|
store = flag = 0;
|
||||||
|
heapId = -1;
|
||||||
if (!isVirtual)
|
if (!isVirtual)
|
||||||
{
|
{
|
||||||
flag |= NF_IM;
|
flag |= NF_IM;
|
||||||
|
|
|
@ -31,6 +31,8 @@ public:
|
||||||
static const unsigned NF_KN = 0x07f000; //NOTICE: decided by DEGREE
|
static const unsigned NF_KN = 0x07f000; //NOTICE: decided by DEGREE
|
||||||
static const unsigned INTL_SIZE = sizeof(Bstr) * MAX_KEY_NUM;
|
static const unsigned INTL_SIZE = sizeof(Bstr) * MAX_KEY_NUM;
|
||||||
static const unsigned LEAF_SIZE = sizeof(int) * MAX_KEY_NUM + INTL_SIZE;
|
static const unsigned LEAF_SIZE = sizeof(int) * MAX_KEY_NUM + INTL_SIZE;
|
||||||
|
|
||||||
|
int heapId;
|
||||||
protected:
|
protected:
|
||||||
unsigned store; //store address, the BLock index
|
unsigned store; //store address, the BLock index
|
||||||
unsigned flag; //NF_RK, NF_IL,NF_ID, NF_IV, propety
|
unsigned flag; //NF_RK, NF_IL,NF_ID, NF_IV, propety
|
||||||
|
@ -42,6 +44,7 @@ protected:
|
||||||
public:
|
public:
|
||||||
SINode();
|
SINode();
|
||||||
SINode(bool isVirtual);
|
SINode(bool isVirtual);
|
||||||
|
|
||||||
bool isLeaf() const;
|
bool isLeaf() const;
|
||||||
bool isDirty() const;
|
bool isDirty() const;
|
||||||
void setDirty();
|
void setDirty();
|
||||||
|
|
Loading…
Reference in New Issue