Skip to content

Commit

Permalink
wi[p
Browse files Browse the repository at this point in the history
  • Loading branch information
czgdp1807 committed May 10, 2024
1 parent ef1142b commit 37d8262
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 292 deletions.
242 changes: 0 additions & 242 deletions pydatastructs/trees/_backend/cpp/BST_module.cpp

This file was deleted.

50 changes: 0 additions & 50 deletions pydatastructs/trees/_backend/cpp/BST_module.hpp

This file was deleted.

51 changes: 51 additions & 0 deletions pydatastructs/trees/_backend/cpp/BinaryTree.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#ifndef TREES_BINARY_TREE_HPP
#define TREES_BINARY_TREE_HPP

#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <structmember.h>
#include <cstdlib>
#include "../../../utils/_backend/cpp/utils.hpp"

typedef struct {
PyObject_HEAD
size_t root_idx;
PyObject* comparator;
PyObject* tree;
size_t size;
bool is_ordered_stastic;
} BinaryTree;

static void BinaryTree_dealloc(BinaryTree *self) {
Py_TYPE(self)->tp_free(reinterpret_cast<PyObject*>(self));
}

static PyObject* BinaryTree___new__(PyTypeObject* type, PyObject *args, PyObject *kwds) {
BinaryTree *self;
self = reinterpret_cast<BinaryTree*>(type->tp_alloc(type, 0));

PyObject *key = PyObject_GetItem(args, PyZero);
PyObject *root_data = PyObject_GetItem(args, PyOne);
PyObject *comp = PyObject_GetItem(args, PyTwo);
PyObject *is_order_statistic = PyObject_GetItem(args, PyThree);
if( (key == Py_None) && (root_data != Py_None) ) {
PyErr_SetString(PyExc_ValueError, "Key required.");
return NULL;
}

key = root_data == Py_None ? Py_None : key;
root = TreeNode(key, root_data)
root.is_root = True
obj.root_idx = 0
obj.tree, obj.size = ArrayForTrees(TreeNode, [root]), 1
obj.comparator = lambda key1, key2: key1 < key2 \
if comp is None else comp
obj.is_order_statistic = is_order_statistic
return obj

return reinterpret_cast<PyObject*>(self);
}



#endif
Empty file.
Empty file.
Empty file.
Empty file.
1 change: 1 addition & 0 deletions pydatastructs/utils/_backend/cpp/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
PyObject *PyZero = PyLong_FromLong(0);
PyObject *PyOne = PyLong_FromLong(1);
PyObject *PyTwo = PyLong_FromLong(2);
PyObject *PyThree = PyLong_FromLong(3);
const char* _encoding = "utf-8";
const char* _invalid_char = "<invalid-character>";

Expand Down

0 comments on commit 37d8262

Please sign in to comment.