Skip to content

Commit

Permalink
add ~Btree(), link leaf node
Browse files Browse the repository at this point in the history
  • Loading branch information
kkw authored and kkw committed May 31, 2016
1 parent 1951bb3 commit 379b417
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions map/BtreeMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,17 @@ BtreeMap<K,V>::BtreeMap(){

template <class K,class V>
BtreeMap<K,V>::~BtreeMap(){
delete root->left(0);
Queue<pNode> queue;
queue.push(root->left(0));
pNode c;

while( !queue.isEmpty() && (c = queue.pop()) != NULL){
int i = 0;
while(c->left(i) != NULL && i < DCOUNT){
queue.push(c->left(i++));
}
delete c;
}
delete root;
}

Expand All @@ -45,7 +55,6 @@ V BtreeMap<K,V>::get(const K& key) {
}
template <class K,class V>
V BtreeMap<K,V>::put(const K& key,const V& value){
printf("put : %d\n",key);
pNode p = root;
pNode c = root->left(0);
Stack<pNode> stack;
Expand All @@ -57,7 +66,7 @@ V BtreeMap<K,V>::put(const K& key,const V& value){
while(1){
stack.push(p);
for(i = 0; i< c->getSize() && c->key(i) < key;i++);
if(c->left(i) == NULL) break;
if(c->isLeaf()) break;
p = c;
c = c->left(i);
}
Expand Down
2 changes: 1 addition & 1 deletion map/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void Node<K,V>::remove(int index, pData& _data, Node*& _left){
template <class K, class V>
pNode Node<K,V>::splitFirst(){
pNode newNode = new Node<K,V>();
newNode->insert(data[0], left(0), NULL);
newNode->insert(data[0], left(0), this);
_moveLeft(0);
return newNode;
}
Expand Down

0 comments on commit 379b417

Please sign in to comment.