diff options
author | sje <sje@4f64403b-2f21-0410-a795-97e2b3489a10> | 2007-10-04 04:40:23 +0000 |
---|---|---|
committer | sje <sje@4f64403b-2f21-0410-a795-97e2b3489a10> | 2007-10-04 04:40:23 +0000 |
commit | 57076d297233ecc7f2654a31086c0ff339284071 (patch) | |
tree | 94b44ec33430bc3a12a09dd4af4a88001d4b5a2c | |
parent | 353cab2448830e0653bb36c0981b064e8bc8040f (diff) |
another fix for map item removal
git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@351 4f64403b-2f21-0410-a795-97e2b3489a10
-rw-r--r-- | meta2/collection.h | 24 | ||||
-rw-r--r-- | meta2/version.h | 2 |
2 files changed, 10 insertions, 16 deletions
diff --git a/meta2/collection.h b/meta2/collection.h index af0f781..9067158 100644 --- a/meta2/collection.h +++ b/meta2/collection.h @@ -333,16 +333,10 @@ protected: TreeNode<T> *delete_node(TreeNode<T> *n) {
if(n->left && n->right) {
- //if(rand() & 1) { // ?
- TreeNode<T> *minmax = n->left;
- while(minmax->right) minmax = minmax->right;
- //} else {
- // Node *minmax = current->right;
- // while(minmax->left) minmax = minmax->left;
- //}
+ TreeNode<T> *minmax = n->left;
+ while(minmax->right) minmax = minmax->right;
n->val = minmax->val;
delete_node(minmax);
- Collection<T>::count--;
return n;
} else if(n->right) {
if(n->parent) {
@@ -351,6 +345,7 @@ protected: } else
root = n->right;
n->right->parent = n->parent;
+ n->parent = 0; // don't mess with pointers
} else if(n->left) {
if(n->parent) {
if(n->parent->left = n) n->parent->left = n->left;
@@ -358,10 +353,10 @@ protected: } else
root = n->left;
n->left->parent = n->parent;
+ n->parent = 0; // don't mess with pointers
} else {
if(n == root) root = 0;
}
- n->parent = 0;
delete n;
Collection<T>::count--;
return 0;
@@ -388,6 +383,7 @@ protected: } else
root = n;
+ Collection<T>::count++;
}
public:
@@ -470,7 +466,6 @@ public: void add(T &val) {
TreeNode<T> *n = new TreeNode<T>(val, 0);
insert_node(n);
- Collection<T>::count++;
}
const bool remove(T &val) {
@@ -527,12 +522,12 @@ public: template<class A, class B> class Map: public BinaryTree< Pair< A, B > > {
protected:
- TreeNode<Pair< A, B > > *find(A &val) const {
+ TreeNode<Pair< A, B > > *find(A &key) const {
TreeNode<Pair< A, B > > *n = BinaryTree< Pair< A, B > >::root;
while(n) {
- if(n->val.first == val)
+ if(n->val.first == key)
return n;
- else if(val < n->val.first)
+ else if(key < n->val.first)
n = n->left;
else
n = n->right;
@@ -565,7 +560,6 @@ public: Pair< A, B > p(key);
TreeNode<Pair< A, B > > *n = new TreeNode<Pair< A, B > >(p, 0);
insert_node(n);
- Collection< Pair< A, B > >::count++;
return n->val.second;
}
}
@@ -581,7 +575,7 @@ public: virtual const bool remove(A &key) {
TreeNode<Pair< A, B > > *n = find(key);
if(n) {
- BinaryTree< Pair< A, B > >::remove(n->val);
+ delete_node(n);
return true;
} else
return false;
diff --git a/meta2/version.h b/meta2/version.h index 2b64a2b..f8e3ee7 100644 --- a/meta2/version.h +++ b/meta2/version.h @@ -5,7 +5,7 @@ #define __MAJOR_VERSION 0
#define __MINOR_VERSION 0
#define __RELEASE_NUM 0
-#define __BUILD_NUM 5
+#define __BUILD_NUM 6
#define __FILEVERSION_STRING __MAJOR_VERSION,__MINOR_VERSION,__RELEASE_NUM,__BUILD_NUM
#define __FILEVERSION_STRING_DOTS __MAJOR_VERSION.__MINOR_VERSION.__RELEASE_NUM.__BUILD_NUM
|