@@ -115,7 +115,7 @@ static PyObject* BinarySearchTree_search(BinarySearchTree* self, PyObject* args,
115
115
if (comp == 1 ) {
116
116
walk = reinterpret_cast <TreeNode*>(bt->tree ->_one_dimensional_array ->_data [PyLong_AsLong (walk)])->left ;
117
117
}
118
- else {
118
+ else {
119
119
walk = reinterpret_cast <TreeNode*>(bt->tree ->_one_dimensional_array ->_data [PyLong_AsLong (walk)])->right ;
120
120
}
121
121
}
@@ -124,7 +124,7 @@ static PyObject* BinarySearchTree_search(BinarySearchTree* self, PyObject* args,
124
124
if (ret_parent==Py_None || PyLong_AsLong (ret_parent)==0 ) {
125
125
return walk;
126
126
}
127
- else {
127
+ else {
128
128
return Py_BuildValue (" OO" ,walk,parent);
129
129
}
130
130
Py_RETURN_NONE; // dummy return statement, never executed
@@ -188,7 +188,7 @@ static PyObject* BinarySearchTree_insert(BinarySearchTree* self, PyObject* args)
188
188
prev_node = reinterpret_cast <TreeNode*>(bt->tree ->_one_dimensional_array ->_data [PyLong_AsLong (walk)])->right ;
189
189
walk = reinterpret_cast <TreeNode*>(bt->tree ->_one_dimensional_array ->_data [PyLong_AsLong (walk)])->right ;
190
190
}
191
- else {
191
+ else {
192
192
if (reinterpret_cast <TreeNode*>(bt->tree ->_one_dimensional_array ->_data [PyLong_AsLong (walk)])->left == Py_None) {
193
193
new_node->parent = prev_node;
194
194
ArrayForTrees_append (bt->tree , Py_BuildValue ( " [O]" , reinterpret_cast <PyObject*>(new_node)) );
@@ -229,12 +229,12 @@ static PyObject* BinarySearchTree_delete(BinarySearchTree* self, PyObject *args,
229
229
reinterpret_cast <TreeNode*>(bt->tree ->_one_dimensional_array ->_data [PyLong_AsLong (bt->root_idx )])->data = Py_None;
230
230
reinterpret_cast <TreeNode*>(bt->tree ->_one_dimensional_array ->_data [PyLong_AsLong (bt->root_idx )])->key = Py_None;
231
231
}
232
- else {
232
+ else {
233
233
if (reinterpret_cast <TreeNode*>(bt->tree ->_one_dimensional_array ->_data [PyLong_AsLong (parent)])->left == walk) {
234
234
Py_INCREF (Py_None);
235
235
reinterpret_cast <TreeNode*>(bt->tree ->_one_dimensional_array ->_data [PyLong_AsLong (parent)])->left = Py_None;
236
236
}
237
- else {
237
+ else {
238
238
Py_INCREF (Py_None);
239
239
reinterpret_cast <TreeNode*>(bt->tree ->_one_dimensional_array ->_data [PyLong_AsLong (parent)])->right = Py_None;
240
240
}
@@ -472,7 +472,7 @@ static PyObject* BinarySearchTree__lca_2(BinarySearchTree* self, PyObject* args)
472
472
PyObject* curr_root = bt->root_idx ;
473
473
PyObject* u = BinarySearchTree_search (self, Py_BuildValue (" (O)" ,j), PyDict_New ());
474
474
PyObject* v = BinarySearchTree_search (self, Py_BuildValue (" (O)" ,k), PyDict_New ());
475
- // std::cout<<PyLong_AsLong(u)<<" "<<PyLong_AsLong(v)<<std::endl;
475
+
476
476
if (u==Py_None || v==Py_None) {
477
477
PyErr_SetString (PyExc_ValueError, " One of the nodes doesn't exist." );
478
478
return NULL ;
@@ -503,35 +503,26 @@ static PyObject* BinarySearchTree__lca_2(BinarySearchTree* self, PyObject* args)
503
503
return NULL ;
504
504
}
505
505
long long v_left = PyLong_AsLongLong (cres2);
506
- // std::cout<<"h1"<<std::endl;
507
506
508
507
while (!(u_left ^ v_left)) {
509
508
if (u_left && v_left) {
510
509
curr_root = reinterpret_cast <TreeNode*>(bt->tree ->_one_dimensional_array ->_data [PyLong_AsLong (curr_root)])->left ;
511
- // std::cout<<"curr_root chagned to: "<<PyLong_AsLong(curr_root)<<std::endl;
512
510
}
513
511
else {
514
512
curr_root = reinterpret_cast <TreeNode*>(bt->tree ->_one_dimensional_array ->_data [PyLong_AsLong (curr_root)])->right ;
515
513
}
516
- // std::cout<<"h2"<<std::endl;
517
514
518
515
if (curr_root == u || curr_root == v) {
519
516
if (curr_root == Py_None) {
520
517
Py_RETURN_NONE;
521
518
}
522
519
return reinterpret_cast <TreeNode*>(bt->tree ->_one_dimensional_array ->_data [PyLong_AsLong (curr_root)])->key ;
523
520
}
524
- // std::cout<<"curr_root "<<PyLong_AsLong(curr_root)<<std::endl;
525
-
526
- if (curr_root == Py_None || u == Py_None) {
527
- // std::cout<<"here"<<std::endl;
528
- }
529
521
530
522
if (!PyCallable_Check (bt->comparator )) {
531
523
PyErr_SetString (PyExc_ValueError, " comparator should be callable" );
532
524
return NULL ;
533
525
}
534
- // std::cout<<"comp: "<<PyLong_AsLong(reinterpret_cast<TreeNode*>(bt->tree->_one_dimensional_array->_data[PyLong_AsLong(u)])->key)<<" "<<PyLong_AsLong(reinterpret_cast<TreeNode*>(bt->tree->_one_dimensional_array->_data[PyLong_AsLong(curr_root)])->key)<<std::endl;
535
526
PyObject* arguments1 = Py_BuildValue (" OO" , reinterpret_cast <TreeNode*>(bt->tree ->_one_dimensional_array ->_data [PyLong_AsLong (u)])->key , reinterpret_cast <TreeNode*>(bt->tree ->_one_dimensional_array ->_data [PyLong_AsLong (curr_root)])->key );
536
527
PyObject* cres1 = PyObject_CallObject (bt->comparator , arguments1);
537
528
Py_DECREF (arguments1);
@@ -540,7 +531,6 @@ static PyObject* BinarySearchTree__lca_2(BinarySearchTree* self, PyObject* args)
540
531
return NULL ;
541
532
}
542
533
u_left = PyLong_AsLongLong (cres1);
543
- // std::cout<<u_left<<std::endl;
544
534
545
535
if (!PyCallable_Check (bt->comparator )) {
546
536
PyErr_SetString (PyExc_ValueError, " comparator should be callable" );
@@ -554,9 +544,7 @@ static PyObject* BinarySearchTree__lca_2(BinarySearchTree* self, PyObject* args)
554
544
return NULL ;
555
545
}
556
546
v_left = PyLong_AsLongLong (cres2);
557
- // std::cout<<u_left<<" "<<v_left<<std::endl;
558
547
}
559
- // std::cout<<"h4"<<std::endl;
560
548
561
549
if (curr_root == Py_None) {
562
550
Py_RETURN_NONE;
0 commit comments