From f2c6acffce025b1d092465a444c906277f1e0bfa Mon Sep 17 00:00:00 2001 From: dssgsra Date: Fri, 14 Apr 2017 00:10:18 +0800 Subject: [PATCH] Add heapId in KVstore tree node (#20) * add heapId in node * fixed bugs * fixed bug * fix * Revert "fix" This reverts commit ebaca3a30d2ec61368c16a5e75266b5c8366fb98. --- KVstore/ISTree/heap/ISHeap.cpp | 16 +++++++++++++--- KVstore/ISTree/node/ISNode.cpp | 2 ++ KVstore/ISTree/node/ISNode.h | 3 +++ KVstore/SITree/heap/SIHeap.cpp | 16 +++++++++++++--- KVstore/SITree/node/SINode.cpp | 2 ++ KVstore/SITree/node/SINode.h | 3 +++ 6 files changed, 36 insertions(+), 6 deletions(-) diff --git a/KVstore/ISTree/heap/ISHeap.cpp b/KVstore/ISTree/heap/ISHeap.cpp index f1f2a26..e39f4f5 100644 --- a/KVstore/ISTree/heap/ISHeap.cpp +++ b/KVstore/ISTree/heap/ISHeap.cpp @@ -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 diff --git a/KVstore/ISTree/node/ISNode.cpp b/KVstore/ISTree/node/ISNode.cpp index 01d7dc2..b74570c 100644 --- a/KVstore/ISTree/node/ISNode.cpp +++ b/KVstore/ISTree/node/ISNode.cpp @@ -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; diff --git a/KVstore/ISTree/node/ISNode.h b/KVstore/ISTree/node/ISNode.h index b25b544..686bad5 100644 --- a/KVstore/ISTree/node/ISNode.h +++ b/KVstore/ISTree/node/ISNode.h @@ -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(); diff --git a/KVstore/SITree/heap/SIHeap.cpp b/KVstore/SITree/heap/SIHeap.cpp index 9e4f07d..75c844d 100644 --- a/KVstore/SITree/heap/SIHeap.cpp +++ b/KVstore/SITree/heap/SIHeap.cpp @@ -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 diff --git a/KVstore/SITree/node/SINode.cpp b/KVstore/SITree/node/SINode.cpp index d97ee47..e822918 100644 --- a/KVstore/SITree/node/SINode.cpp +++ b/KVstore/SITree/node/SINode.cpp @@ -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; diff --git a/KVstore/SITree/node/SINode.h b/KVstore/SITree/node/SINode.h index 83c1eb9..bb38e5d 100644 --- a/KVstore/SITree/node/SINode.h +++ b/KVstore/SITree/node/SINode.h @@ -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();