Skip to content

Commit 9642c68

Browse files
committed
Code for defining C++ backend for tree algorithms.
1 parent cf62fc5 commit 9642c68

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <Python.h>
2+
#include "trees.hpp" // Header file containing C++ implementations of wrapper functions of tree data structures
3+
4+
// Method definitions
5+
static PyMethodDef trees_PyMethodDef[] = {
6+
{"binary_tree", (PyCFunction) binary_tree, METH_VARARGS, ""},
7+
// Add method definitions for other tree data structures over here.
8+
{NULL, NULL, 0, NULL} /* Sentinel */
9+
};
10+
11+
// Sentinel info:
12+
// The sentinel entry {NULL, NULL, 0, NULL} is used to indicate the end of the method definition array.
13+
// When the Python interpreter processes this array, it stops iterating over the array when it encounters this sentinel entry.
14+
15+
// Module structure
16+
static struct PyModuleDef trees_module = {
17+
PyModuleDef_HEAD_INIT,
18+
"_trees",
19+
NULL,
20+
-1,
21+
trees_PyMethodDef
22+
};
23+
24+
// Module initialization function
25+
PyMODINIT_FUNC PyInit__trees(void) {
26+
PyObject *module;
27+
module = PyModule_Create(&trees_module);
28+
if (module == NULL)
29+
return NULL;
30+
return module;
31+
}

0 commit comments

Comments
 (0)