@@ -99,17 +99,13 @@ class ddt {
99
99
freeTree (root->left );
100
100
freeTree (root->right );
101
101
102
- // TODO: make it more CPP-like.
103
- free (root->value );
104
- free (root->key );
105
- free (root);
102
+ delete root;
106
103
}
107
104
}
108
105
109
106
TREE* createAndInitTreeNode (const string& key, const T& value)
110
107
{
111
- // TODO: make it more CPP-like.
112
- TREE* newNode = (TREE*)malloc (sizeof (TREE));
108
+ TREE* newNode = new TREE;
113
109
114
110
newNode->key = key;
115
111
newNode->value = value;
@@ -236,11 +232,11 @@ class ddt {
236
232
else {
237
233
/* Check for leaf node: both left and right child nodes are empty. */
238
234
if (!(root->left || root->right )) {
239
- free ( root) ;
235
+ delete root;
240
236
return nullptr ;
241
237
} else if (root->left == nullptr ^ root->right == nullptr ) { // If either are empty
242
238
TREE* temp = either (root->right , root->left ); // No code duplication
243
- free ( root) ;
239
+ delete root;
244
240
root = temp;
245
241
} else {
246
242
TREE* temp = root->left ;
@@ -289,8 +285,7 @@ class ddt {
289
285
290
286
if (key_hash == root_value_hash) {
291
287
return root->value ;
292
- }
293
- else if (key_hash < root_value_hash)
288
+ } else if (key_hash < root_value_hash)
294
289
return getValueByKey (root->left , key);
295
290
else /* key_hash > root_value_hash */
296
291
return getValueByKey (root->right , key);
@@ -311,12 +306,6 @@ class ddt {
311
306
tree = removeNode (tree, key);
312
307
}
313
308
314
- // FIXME:
315
- void clear () {
316
- freeTree (tree);
317
- }
318
-
319
- // FIXME:
320
309
void reinit (const string& key, const T& value) {
321
310
clearTree (tree, key, value);
322
311
}
0 commit comments