Skip to content

Commit

Permalink
Code for defining C++ backend for tree algorithms.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kishan-Ved committed Apr 13, 2024
1 parent cf62fc5 commit 9642c68
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions pydatastructs/trees/_backend/cpp/tree_algorithms.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <Python.h>
#include "trees.hpp" // Header file containing C++ implementations of wrapper functions of tree data structures

// Method definitions
static PyMethodDef trees_PyMethodDef[] = {
{"binary_tree", (PyCFunction) binary_tree, METH_VARARGS, ""},
// Add method definitions for other tree data structures over here.
{NULL, NULL, 0, NULL} /* Sentinel */
};

// Sentinel info:
// The sentinel entry {NULL, NULL, 0, NULL} is used to indicate the end of the method definition array.
// When the Python interpreter processes this array, it stops iterating over the array when it encounters this sentinel entry.

// Module structure
static struct PyModuleDef trees_module = {
PyModuleDef_HEAD_INIT,
"_trees",
NULL,
-1,
trees_PyMethodDef
};

// Module initialization function
PyMODINIT_FUNC PyInit__trees(void) {
PyObject *module;
module = PyModule_Create(&trees_module);
if (module == NULL)
return NULL;
return module;
}

0 comments on commit 9642c68

Please sign in to comment.