Skip to content

Commit a8ea072

Browse files
committed
added tests
1 parent 3cef009 commit a8ea072

File tree

3 files changed

+164
-149
lines changed

3 files changed

+164
-149
lines changed

pydatastructs/trees/_backend/cpp/AVLTree.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,20 @@ static PyObject* AVLTree_insert(AVLTree* self, PyObject *args) {
229229
return NULL;
230230
}
231231
SelfBalancingBinaryTree_insert(self->sbbt, Py_BuildValue("(OO)", key, data));
232-
long s = self->sbbt->bst->binary_tree->size - 1;
232+
BinaryTree* bt = self->sbbt->bst->binary_tree;
233+
long s = bt->size - 1;
233234
AVLTree__balance_insertion(self, Py_BuildValue("(OO)", PyLong_FromLong(s), reinterpret_cast<TreeNode*>(bt->tree->_one_dimensional_array->_data[s])->parent));
234235

235236
Py_RETURN_NONE;
236237
}
237238

238239
static struct PyMethodDef AVLTree_PyMethodDef[] = {
239240
{"search", (PyCFunction) AVLTree_search, METH_VARARGS | METH_KEYWORDS, NULL},
241+
{"insert", (PyCFunction) AVLTree_insert, METH_VARARGS, NULL},
242+
{"_left_right_rotate", (PyCFunction) AVLTree__left_right_rotate, METH_VARARGS, NULL},
243+
{"_right_left_rotate", (PyCFunction) AVLTree__right_left_rotate, METH_VARARGS, NULL},
244+
{"_left_rotate", (PyCFunction) AVLTree__left_rotate, METH_VARARGS, NULL},
245+
{"_right_rotate", (PyCFunction) AVLTree__right_rotate, METH_VARARGS, NULL},
240246
{NULL}
241247
};
242248

pydatastructs/trees/_backend/cpp/BinaryTreeTraversal.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "SelfBalancingBinaryTree.hpp"
1717
#include "RedBlackTree.hpp"
1818
#include "SplayTree.hpp"
19+
#include "AVLTree.hpp"
1920

2021
typedef struct {
2122
PyObject_HEAD
@@ -44,10 +45,16 @@ static PyObject* BinaryTreeTraversal___new__(PyTypeObject* type, PyObject *args,
4445
if (PyType_Ready(&SplayTreeType) < 0) { // This has to be present to finalize a type object. This should be called on all type objects to finish their initialization.
4546
return NULL;
4647
}
48+
if (PyType_Ready(&AVLTreeType) < 0) { // This has to be present to finalize a type object. This should be called on all type objects to finish their initialization.
49+
return NULL;
50+
}
4751

4852
if (PyObject_IsInstance(tree, (PyObject *)&SplayTreeType)) {
4953
self->tree = reinterpret_cast<SplayTree*>(tree)->sbbt->bst->binary_tree;
5054
}
55+
else if (PyObject_IsInstance(tree, (PyObject *)&AVLTreeType)) {
56+
self->tree = reinterpret_cast<AVLTree*>(tree)->sbbt->bst->binary_tree;
57+
}
5158
else if (PyObject_IsInstance(tree, (PyObject *)&RedBlackTreeType)) {
5259
self->tree = reinterpret_cast<RedBlackTree*>(tree)->sbbt->bst->binary_tree;
5360
}

0 commit comments

Comments
 (0)