Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added C++ backend for Node, TreeNode, ArrayForTrees, BinaryTree and BinarySearchTree and all tree traversals implemented #556

Merged
merged 181 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from 170 commits
Commits
Show all changes
181 commits
Select commit Hold shift + click to select a range
2e8edc2
BST insert(), search() working
Kishan-Ved May 8, 2024
ae518a5
moved files to proper location and added extension: setup2.py no long…
Kishan-Ved May 9, 2024
ae2ca7f
commented out setup2.py to check if CI passes
Kishan-Ved May 9, 2024
e3e57c7
removed whitespaces at line ends
Kishan-Ved May 9, 2024
90669a2
removed setup2.py
Kishan-Ved May 9, 2024
68c94ce
reinterpret cast for BST
Kishan-Ved May 9, 2024
5248055
reinterpret cast for PyObject
Kishan-Ved May 9, 2024
15167fd
added _extension.py file for trees
Kishan-Ved May 9, 2024
4827d6d
name changed from BST.BST to BST
Kishan-Ved May 9, 2024
e94ec24
check key and data for BST()
Kishan-Ved May 9, 2024
ef1142b
Value error message corrected
Kishan-Ved May 9, 2024
37d8262
wi[p
czgdp1807 May 10, 2024
2a78d84
worked on BinaryTree.hpp, done except TreeNode and ArrayForTrees class
Kishan-Ved May 11, 2024
46a65cf
Added C++ backend for Node class
Kishan-Ved May 11, 2024
da8fb74
Added C++ backend for TreeNode class
Kishan-Ved May 11, 2024
b0f44b2
Added TreeNode() to BinaryTree.hpp
Kishan-Ved May 11, 2024
0665403
Added C++ backend for ArrayForTrees
Kishan-Ved May 12, 2024
b9c1974
added trees.cpp file
Kishan-Ved May 12, 2024
2fef090
updated _extensions.py file in trees
Kishan-Ved May 12, 2024
e2d2fc0
removed test.py
Kishan-Ved May 12, 2024
fbfd73f
ArrayForTrees added to arrays.cpp
Kishan-Ved May 12, 2024
a06bc24
added include<map> in ArrayForTrees
Kishan-Ved May 12, 2024
fe04d43
added using namespace std to ArrayForTrees
Kishan-Ved May 12, 2024
51b86a6
checking by replacing ArrayForTrees by DynamicOneDimensionalArray
Kishan-Ved May 13, 2024
2426869
ArrayForTrees restored as before
Kishan-Ved May 13, 2024
0ffcfb5
Added member struct for ArrayForTrees
Kishan-Ved May 13, 2024
a3a3d1d
PyMemberDef for ArrayForTrees
Kishan-Ved May 13, 2024
ccd97a5
Added TreeNode to ArrayForTrees
Kishan-Ved May 13, 2024
d480bb9
fixed a small include error
Kishan-Ved May 13, 2024
d5e8f1b
&TreeNodeType
Kishan-Ved May 13, 2024
765dd01
reinterpret_cast<long> for key and data in TreeNode
Kishan-Ved May 13, 2024
0d22529
reinterpret_cast<PyObject*> for ArrayForTrees
Kishan-Ved May 13, 2024
30fc831
added _dtype to ArrayForTrees
Kishan-Ved May 13, 2024
fbae270
added BinaryTree___str()__
Kishan-Ved May 13, 2024
82c26cf
checking
Kishan-Ved May 14, 2024
512db43
checking
Kishan-Ved May 14, 2024
f1ba50d
check
Kishan-Ved May 14, 2024
66e6890
check
Kishan-Ved May 14, 2024
9fc8c87
check
Kishan-Ved May 14, 2024
62595ad
check
Kishan-Ved May 14, 2024
891c914
check
Kishan-Ved May 14, 2024
ebb5149
uncomment
Kishan-Ved May 14, 2024
46df219
added misc_util.cpp
Kishan-Ved May 14, 2024
49568b4
renamed misc_util.cpp -> nodes.cpp and created _extensions.py file
Kishan-Ved May 14, 2024
b2ebabe
added utils _extensions to setup.py
Kishan-Ved May 14, 2024
fb32ad6
doda in ArrayForTrees and PyMemberDef in TreeNode
Kishan-Ved May 15, 2024
83454fd
commented for checking
Kishan-Ved May 15, 2024
2b09e47
include utils.hpp
Kishan-Ved May 15, 2024
6828c95
nodex to nodes
Kishan-Ved May 15, 2024
80bc634
uncomment ArrayForTrees.hpp
Kishan-Ved May 15, 2024
e929026
TreeNode* conversion for _data[i]->key in ArrayForTrees
Kishan-Ved May 15, 2024
ded0f0b
TreeNode* conversion for _data[i]->key in ArrayForTrees
Kishan-Ved May 15, 2024
7441551
TreeNode* conversion for _data[i]->key in ArrayForTrees
Kishan-Ved May 15, 2024
7e4900f
more reinterpret casts
Kishan-Ved May 15, 2024
e9fcc31
more reinterpret casts
Kishan-Ved May 15, 2024
e88cfa0
more reinterpret casts
Kishan-Ved May 15, 2024
35011d8
more reinterpret casts
Kishan-Ved May 15, 2024
9d8974c
checking without returning map
Kishan-Ved May 15, 2024
89a4f2d
some changes
Kishan-Ved May 15, 2024
966d738
uncomment binary trees
Kishan-Ved May 15, 2024
378c242
uncomment binary trees
Kishan-Ved May 15, 2024
dfa21b1
some reinterpret casts
Kishan-Ved May 15, 2024
0b7a6b0
some reinterpret casts
Kishan-Ved May 15, 2024
96b6c9f
checking
Kishan-Ved May 15, 2024
eb602e6
checking
Kishan-Ved May 15, 2024
0cba5b4
removed many errors
Kishan-Ved May 15, 2024
daf2165
initial work on BST
Kishan-Ved May 17, 2024
2423125
Dictionary corrected in ArrayForTrees
Kishan-Ved May 17, 2024
21d927d
removed PyMemberDef in ArrayForTrees
Kishan-Ved May 17, 2024
7bd1d17
some fixes in ArrayForTrees
Kishan-Ved May 17, 2024
73d14af
some fixes in ArrayForTrees
Kishan-Ved May 17, 2024
c9c7355
ArrayForTrees() call fixed, comparator set to None and some more fixes
Kishan-Ved May 17, 2024
da288b0
All errors fixed :)
Kishan-Ved May 17, 2024
a05b2b3
testing TreeNode
Kishan-Ved May 17, 2024
04195d4
checking
Kishan-Ved May 17, 2024
65d09ed
checking
Kishan-Ved May 17, 2024
205e52e
rearranged in setup.py
Kishan-Ved May 17, 2024
e81e4c9
rearranged in init.py
Kishan-Ved May 17, 2024
c98c95a
rearranged in init.py
Kishan-Ved May 17, 2024
3beddfc
modified init.py
Kishan-Ved May 17, 2024
7511856
checking import
Kishan-Ved May 17, 2024
0a47aa8
reverted import
Kishan-Ved May 17, 2024
ca41991
)
Kishan-Ved May 17, 2024
279dfa5
check
Kishan-Ved May 17, 2024
d74d488
pylong_fromlong
Kishan-Ved May 17, 2024
8c9a717
pylong_aslong
Kishan-Ved May 17, 2024
b18ecf4
TreeNode test added, working correct
Kishan-Ved May 17, 2024
fae502d
TreeNode arg in ArrayForTrees()
Kishan-Ved May 17, 2024
1312929
added cout to check
Kishan-Ved May 17, 2024
d5a055d
included iostream
Kishan-Ved May 17, 2024
7615c0a
added std
Kishan-Ved May 17, 2024
62ba8f9
check
Kishan-Ved May 18, 2024
98f6e59
args,kwds
Kishan-Ved May 18, 2024
47f16f4
fixed _nodes import by adding dummy submodules
Kishan-Ved May 18, 2024
2edcdd1
uncomment
Kishan-Ved May 18, 2024
1792093
removed BT test
Kishan-Ved May 18, 2024
3675a96
added TN for testing
Kishan-Ved May 18, 2024
45ad909
include TN
Kishan-Ved May 18, 2024
89a143a
Fixed TreeNode SegFault :)
Kishan-Ved May 18, 2024
cb6c988
Removed TN includes
Kishan-Ved May 18, 2024
2539107
Removed whitespaces and updated comment
Kishan-Ved May 18, 2024
19175f9
Added dummy submodule for _trees.py and properly redirected BT backen…
Kishan-Ved May 19, 2024
84f81c1
default comparator set in python code and NotImplementedError fixed
Kishan-Ved May 19, 2024
48c392f
white space at line ends
Kishan-Ved May 19, 2024
8e81f38
Finally fixed the error :)
Kishan-Ved May 19, 2024
9a55742
removed debugging cout, include
Kishan-Ved May 19, 2024
821ed65
Temporary fix for ArrayForTrees, everything working correctly includi…
Kishan-Ved May 21, 2024
30bc277
code quality - whitespaces
Kishan-Ved May 21, 2024
4e6bbc7
Fixed self->tree->dynamic_one_dimensional_array, BT working fine now :)
Kishan-Ved May 22, 2024
bd74ae5
Added tests for ArrayForTrees
Kishan-Ved May 22, 2024
ece6bb8
Testing ArrayForTrees
Kishan-Ved May 22, 2024
d21498e
code quality
Kishan-Ved May 22, 2024
132bae5
ArrayForTrees inheritance removed and kwds passed to ArrayForTrees___…
Kishan-Ved May 23, 2024
681d960
test function calls commented
Kishan-Ved May 23, 2024
5656f55
Improved ArrayForTrees C++ test
Kishan-Ved May 23, 2024
1c65434
Fixed ArrayForTrees__modify() in C++ backend
Kishan-Ved May 23, 2024
2dade75
Removed pass from test_cpp_BinaryTree()
Kishan-Ved May 23, 2024
714e394
Started with BinarySearchTree
Kishan-Ved May 23, 2024
6968ba7
BST new() and str() working and tested, BST backend redirected to C++…
Kishan-Ved May 23, 2024
908e915
test code quality functions kept ready and commented
Kishan-Ved May 23, 2024
e18511b
parent keyword parsed successfully in BST_search()
Kishan-Ved May 24, 2024
fb118c5
meeting
Kishan-Ved May 24, 2024
648b21b
Comparator tested and working! Both custom and default
Kishan-Ved May 24, 2024
fe24631
search() for BST done, working and tested
Kishan-Ved May 25, 2024
c9e6747
BST insert() initial work
Kishan-Ved May 25, 2024
f94c33d
TreeNode->data changed to PyObject* from long
Kishan-Ved May 25, 2024
4e912c6
whitespaces
Kishan-Ved May 25, 2024
01c8bde
TreeNode->key changed to PyObject* from long
Kishan-Ved May 25, 2024
ff61280
BST insert() almost done
Kishan-Ved May 25, 2024
0be846e
Commented test function calls
Kishan-Ved May 25, 2024
d4961d7
== to is
Kishan-Ved May 25, 2024
95ea0eb
== to is
Kishan-Ved May 25, 2024
f34aaa4
== to is
Kishan-Ved May 25, 2024
47c131f
== to is
Kishan-Ved May 25, 2024
6287685
BST insert() done and bt->is_order_statistic changed to long
Kishan-Ved May 26, 2024
ac3a699
BST delete() for leaf nodes done and tested
Kishan-Ved May 26, 2024
7d0b804
PYTHON BUG FIXED: BST insert(12,12), delete(12), insert(12,12) gave i…
Kishan-Ved May 27, 2024
09818c4
LAST COMMIT REVERTED and BST delete() for if else if else case 2
Kishan-Ved May 27, 2024
1ae3be7
BST delete() done and tested :)
Kishan-Ved May 27, 2024
ed9c640
check why CI fails
Kishan-Ved May 27, 2024
c0d5e98
check why CI fails
Kishan-Ved May 27, 2024
4ff5d16
check
Kishan-Ved May 28, 2024
0036bd1
BST lower_bound() and upper_bound()
Kishan-Ved May 28, 2024
bda0dd1
BST _simple_path() done and tested
Kishan-Ved May 28, 2024
21c74f5
BST Lowest Common Ancestor by lca1 done and tested
Kishan-Ved May 28, 2024
6aaa009
speed test
Kishan-Ved May 28, 2024
77b9533
BST lca2 and code quality
Kishan-Ved May 29, 2024
654c49f
improved the code quality
Kishan-Ved May 29, 2024
51f36cb
BST rank()
Kishan-Ved May 29, 2024
1159b98
BST select() done and tested :)
Kishan-Ved May 29, 2024
1b2d32d
BST done() :)
Kishan-Ved May 29, 2024
c8697a7
PR ready: improved code quality, removed unnecessary comments
Kishan-Ved May 30, 2024
9c03ed0
comment removed
Kishan-Ved May 30, 2024
1097ccc
BinaryTreeTraversal __new__()
Kishan-Ved May 30, 2024
3c961ae
added preorder traversal and tested
Kishan-Ved May 30, 2024
6adf3d2
BTT depth_first_search() implemented
Kishan-Ved May 30, 2024
9e589f6
backend redirected to C++
Kishan-Ved May 30, 2024
abcf9b6
PR ready for merge
Kishan-Ved May 30, 2024
2e0ea8d
some changes
Kishan-Ved May 30, 2024
bdb42e6
more changes
Kishan-Ved May 30, 2024
e84e9cd
more changes
Kishan-Ved May 30, 2024
6ab65fc
benchmark test added
Kishan-Ved May 30, 2024
c4ecdd0
added inorder traversal
Kishan-Ved May 30, 2024
36bc778
Added out order traversal and tests
Kishan-Ved May 31, 2024
83c74dc
added postorder traversal in C++ backend and its tests
Kishan-Ved May 31, 2024
8026a90
Added breadth first search in C++ backend and its tests
Kishan-Ved May 31, 2024
8dd7f65
All tree travsersals done in C++ backend
Kishan-Ved May 31, 2024
2f0cea7
benchmark tests updated
Kishan-Ved Jun 1, 2024
7a9e27f
removed print
Kishan-Ved Jun 1, 2024
39aa94a
Added separate benchmark tests for BST insert, search and delete
Kishan-Ved Jun 2, 2024
a7da43c
CI check, changed to Py_True
Kishan-Ved Jun 2, 2024
9d20577
CI check, changed to Py_True
Kishan-Ved Jun 2, 2024
5e904c9
minor update
Kishan-Ved Jun 2, 2024
5f4253f
minor update
Kishan-Ved Jun 2, 2024
575b43a
Check CI return
Kishan-Ved Jun 2, 2024
6efc3e5
Check CI return
Kishan-Ved Jun 2, 2024
b1d197a
Check CI return
Kishan-Ved Jun 2, 2024
c6aa701
back to original
Kishan-Ved Jun 2, 2024
d01c8de
small update
Kishan-Ved Jun 3, 2024
e2fad1e
check
Kishan-Ved Jun 3, 2024
ab1dce8
Added support for b.tree
Kishan-Ved Jun 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pydatastructs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .utils import *
from .linear_data_structures import *
from .trees import *
from .miscellaneous_data_structures import *
from .utils import *
from .graphs import *
from .strings import *

Expand Down
3 changes: 2 additions & 1 deletion pydatastructs/linear_data_structures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
from .arrays import (
OneDimensionalArray,
DynamicOneDimensionalArray,
MultiDimensionalArray
MultiDimensionalArray,
ArrayForTrees
)
__all__.extend(arrays.__all__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static bool is_ordered_impl(PyObject* array, size_t lower, size_t upper,
PyObject* i_item = PyObject_GetItem(array, i_PyObject);
PyObject* i1_item = PyObject_GetItem(array, i1_PyObject);
if (i_item == Py_None || i1_item == Py_None) continue;
if( _comp(i_item, i1_item, comp) == 1 ) {
if ( _comp(i_item, i1_item, comp) == 1 ) {
return false;
}
}
Expand All @@ -30,23 +30,23 @@ static PyObject* is_ordered(PyObject* self, PyObject* args, PyObject* kwds) {
args0 = PyObject_GetItem(args, PyZero);
int is_DynamicOneDimensionalArray = _check_type(args0, &DynamicOneDimensionalArrayType);
int is_OneDimensionalArray = _check_type(args0, &OneDimensionalArrayType);
if( !is_DynamicOneDimensionalArray && !is_OneDimensionalArray ) {
if ( !is_DynamicOneDimensionalArray && !is_OneDimensionalArray ) {
raise_exception_if_not_array(args0);
return NULL;
}
comp = PyObject_GetItem(kwds, PyUnicode_FromString("comp"));
if( comp == NULL ) {
if ( comp == NULL ) {
PyErr_Clear();
}
start = PyObject_GetItem(kwds, PyUnicode_FromString("start"));
if( start == NULL ) {
if ( start == NULL ) {
PyErr_Clear();
lower = 0;
} else {
lower = PyLong_AsSize_t(start);
}
end = PyObject_GetItem(kwds, PyUnicode_FromString("end"));
if( end == NULL ) {
if ( end == NULL ) {
PyErr_Clear();
upper = PyObject_Length(args0) - 1;
} else {
Expand All @@ -66,26 +66,26 @@ static PyObject* linear_search(PyObject* self, PyObject* args, PyObject* kwds) {
args0 = PyObject_GetItem(args, PyZero);
int is_DynamicOneDimensionalArray = _check_type(args0, &DynamicOneDimensionalArrayType);
int is_OneDimensionalArray = _check_type(args0, &OneDimensionalArrayType);
if( !is_DynamicOneDimensionalArray && !is_OneDimensionalArray ) {
if ( !is_DynamicOneDimensionalArray && !is_OneDimensionalArray ) {
raise_exception_if_not_array(args0);
return NULL;
}
start = PyObject_GetItem(kwds, PyUnicode_FromString("start"));
if( start == NULL ) {
if ( start == NULL ) {
PyErr_Clear();
lower = 0;
} else {
lower = PyLong_AsSize_t(start);
}
end = PyObject_GetItem(kwds, PyUnicode_FromString("end"));
if( end == NULL ) {
if ( end == NULL ) {
PyErr_Clear();
upper = PyObject_Length(args0) - 1;
} else {
upper = PyLong_AsSize_t(end);
}
value = PyObject_GetItem(args, PyLong_FromSize_t(1));
if( value == NULL ) {
if ( value == NULL ) {
PyErr_Format(PyExc_ValueError,
"Expected Value to be not NULL");
}
Expand Down Expand Up @@ -120,30 +120,30 @@ static PyObject* binary_search(PyObject* self, PyObject* args, PyObject* kwds) {
args0 = PyObject_GetItem(args, PyZero);
int is_DynamicOneDimensionalArray = _check_type(args0, &DynamicOneDimensionalArrayType);
int is_OneDimensionalArray = _check_type(args0, &OneDimensionalArrayType);
if( !is_DynamicOneDimensionalArray && !is_OneDimensionalArray ) {
if ( !is_DynamicOneDimensionalArray && !is_OneDimensionalArray ) {
raise_exception_if_not_array(args0);
return NULL;
}
comp = PyObject_GetItem(kwds, PyUnicode_FromString("comp"));
if( comp == NULL ) {
if ( comp == NULL ) {
PyErr_Clear();
}
start = PyObject_GetItem(kwds, PyUnicode_FromString("start"));
if( start == NULL ) {
if ( start == NULL ) {
PyErr_Clear();
lower = 0;
} else {
lower = PyLong_AsSize_t(start);
}
end = PyObject_GetItem(kwds, PyUnicode_FromString("end"));
if( end == NULL ) {
if ( end == NULL ) {
PyErr_Clear();
upper = PyObject_Length(args0) - 1;
} else {
upper = PyLong_AsSize_t(end);
}
value = PyObject_GetItem(args, PyLong_FromSize_t(1));
if( value == NULL ) {
if ( value == NULL ) {
PyErr_Format(PyExc_ValueError,
"Expected Value to be not NULL");
}
Expand All @@ -169,7 +169,7 @@ static PyObject* binary_search(PyObject* self, PyObject* args, PyObject* kwds) {
Py_INCREF(res);
return res;
}
if( _comp(u, value, comp) == 1 ) {
if ( _comp(u, value, comp) == 1 ) {
left = middle + 1;
} else {
right = middle - 1;
Expand All @@ -187,30 +187,30 @@ static PyObject* jump_search(PyObject* self, PyObject* args, PyObject* kwds) {
args0 = PyObject_GetItem(args, PyZero);
int is_DynamicOneDimensionalArray = _check_type(args0, &DynamicOneDimensionalArrayType);
int is_OneDimensionalArray = _check_type(args0, &OneDimensionalArrayType);
if( !is_DynamicOneDimensionalArray && !is_OneDimensionalArray ) {
if ( !is_DynamicOneDimensionalArray && !is_OneDimensionalArray ) {
raise_exception_if_not_array(args0);
return NULL;
}
comp = PyObject_GetItem(kwds, PyUnicode_FromString("comp"));
if( comp == NULL ) {
if ( comp == NULL ) {
PyErr_Clear();
}
start = PyObject_GetItem(kwds, PyUnicode_FromString("start"));
if( start == NULL ) {
if ( start == NULL ) {
PyErr_Clear();
lower = 0;
} else {
lower = PyLong_AsSize_t(start);
}
end = PyObject_GetItem(kwds, PyUnicode_FromString("end"));
if( end == NULL ) {
if ( end == NULL ) {
PyErr_Clear();
upper = PyObject_Length(args0) - 1;
} else {
upper = PyLong_AsSize_t(end);
}
value = PyObject_GetItem(args, PyLong_FromSize_t(1));
if( value == NULL ) {
if ( value == NULL ) {
PyErr_Format(PyExc_ValueError,
"Expected Value to be not NULL");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ static PyObject* bubble_sort_impl(PyObject* array, size_t lower, size_t upper,
for (size_t j = lower; j < upper; j++) {
PyObject* j_PyObject = PyLong_FromSize_t(j);
PyObject* j1_PyObject = PyLong_FromSize_t(j+1);
if( _comp(PyObject_GetItem(array, j_PyObject),
if ( _comp(PyObject_GetItem(array, j_PyObject),
PyObject_GetItem(array, j1_PyObject), comp) != 1 ) {
PyObject* tmp = PyObject_GetItem(array, j1_PyObject);
PyObject_SetItem(array, j1_PyObject,
Expand All @@ -34,23 +34,23 @@ static PyObject* bubble_sort(PyObject* self, PyObject* args, PyObject* kwds) {
args0 = PyObject_GetItem(args, PyZero);
int is_DynamicOneDimensionalArray = _check_type(args0, &DynamicOneDimensionalArrayType);
int is_OneDimensionalArray = _check_type(args0, &OneDimensionalArrayType);
if( !is_DynamicOneDimensionalArray && !is_OneDimensionalArray ) {
if ( !is_DynamicOneDimensionalArray && !is_OneDimensionalArray ) {
raise_exception_if_not_array(args0);
return NULL;
}
comp = PyObject_GetItem(kwds, PyUnicode_FromString("comp"));
if( comp == NULL ) {
if ( comp == NULL ) {
PyErr_Clear();
}
start = PyObject_GetItem(kwds, PyUnicode_FromString("start"));
if( start == NULL ) {
if ( start == NULL ) {
PyErr_Clear();
lower = 0;
} else {
lower = PyLong_AsSize_t(start);
}
end = PyObject_GetItem(kwds, PyUnicode_FromString("end"));
if( end == NULL ) {
if ( end == NULL ) {
PyErr_Clear();
upper = PyObject_Length(args0) - 1;
} else {
Expand All @@ -59,7 +59,7 @@ static PyObject* bubble_sort(PyObject* self, PyObject* args, PyObject* kwds) {
arr_length = PyObject_Length(args0);

args0 = bubble_sort_impl(args0, lower, upper, comp, arr_length);
if( is_DynamicOneDimensionalArray ) {
if ( is_DynamicOneDimensionalArray ) {
PyObject_CallMethod(args0, "_modify", "O", Py_True);
}
Py_INCREF(args0);
Expand All @@ -75,7 +75,7 @@ static PyObject* selection_sort_impl(PyObject* array, size_t lower, size_t upper
PyObject* i_PyObject = PyLong_FromSize_t(i);
for (size_t j = i + 1; j < upper + 1; j++) {
PyObject* j_PyObject = PyLong_FromSize_t(j);
if( _comp(PyObject_GetItem(array, j_min_PyObject),
if ( _comp(PyObject_GetItem(array, j_min_PyObject),
PyObject_GetItem(array, j_PyObject), comp) != 1 ) {
j_min_PyObject = j_PyObject;
}
Expand All @@ -96,31 +96,31 @@ static PyObject* selection_sort(PyObject* self, PyObject* args, PyObject* kwds)
args0 = PyObject_GetItem(args, PyZero);
int is_DynamicOneDimensionalArray = _check_type(args0, &DynamicOneDimensionalArrayType);
int is_OneDimensionalArray = _check_type(args0, &OneDimensionalArrayType);
if( !is_DynamicOneDimensionalArray && !is_OneDimensionalArray ) {
if ( !is_DynamicOneDimensionalArray && !is_OneDimensionalArray ) {
raise_exception_if_not_array(args0);
return NULL;
}
comp = PyObject_GetItem(kwds, PyUnicode_FromString("comp"));
if( comp == NULL ) {
if ( comp == NULL ) {
PyErr_Clear();
}
start = PyObject_GetItem(kwds, PyUnicode_FromString("start"));
if( start == NULL ) {
if ( start == NULL ) {
PyErr_Clear();
lower = 0;
} else {
lower = PyLong_AsSize_t(start);
}
end = PyObject_GetItem(kwds, PyUnicode_FromString("end"));
if( end == NULL ) {
if ( end == NULL ) {
PyErr_Clear();
upper = PyObject_Length(args0) - 1;
} else {
upper = PyLong_AsSize_t(end);
}

args0 = selection_sort_impl(args0, lower, upper, comp);
if( is_DynamicOneDimensionalArray ) {
if ( is_DynamicOneDimensionalArray ) {
PyObject_CallMethod(args0, "_modify", "O", Py_True);
}
Py_INCREF(args0);
Expand Down Expand Up @@ -153,31 +153,31 @@ static PyObject* insertion_sort(PyObject* self, PyObject* args, PyObject* kwds)
args0 = PyObject_GetItem(args, PyZero);
int is_DynamicOneDimensionalArray = _check_type(args0, &DynamicOneDimensionalArrayType);
int is_OneDimensionalArray = _check_type(args0, &OneDimensionalArrayType);
if( !is_DynamicOneDimensionalArray && !is_OneDimensionalArray ) {
if ( !is_DynamicOneDimensionalArray && !is_OneDimensionalArray ) {
raise_exception_if_not_array(args0);
return NULL;
}
comp = PyObject_GetItem(kwds, PyUnicode_FromString("comp"));
if( comp == NULL ) {
if ( comp == NULL ) {
PyErr_Clear();
}
start = PyObject_GetItem(kwds, PyUnicode_FromString("start"));
if( start == NULL ) {
if ( start == NULL ) {
PyErr_Clear();
lower = 0;
} else {
lower = PyLong_AsSize_t(start);
}
end = PyObject_GetItem(kwds, PyUnicode_FromString("end"));
if( end == NULL ) {
if ( end == NULL ) {
PyErr_Clear();
upper = PyObject_Length(args0) - 1;
} else {
upper = PyLong_AsSize_t(end);
}

args0 = insertion_sort_impl(args0, lower, upper, comp);
if( is_DynamicOneDimensionalArray ) {
if ( is_DynamicOneDimensionalArray ) {
PyObject_CallMethod(args0, "_modify", "O", Py_True);
}
Py_INCREF(args0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
static PyObject* call_pick_pivot_element(PyObject* pick_pivot_element,
size_t low, size_t high, PyObject* array) {
PyObject* high_PyObject = PyLong_FromSize_t(high);
if( pick_pivot_element ) {
if ( pick_pivot_element ) {
return PyObject_CallFunctionObjArgs(pick_pivot_element,
PyLong_FromSize_t(low),
high_PyObject,
Expand All @@ -27,7 +27,7 @@ static size_t quick_sort_partition(size_t low, size_t high,
PyObject* x = call_pick_pivot_element(pick_pivot_element, low, high, array);
for( size_t j = low; j < high; j++ ) {
PyObject* j_PyObject = PyLong_FromSize_t(j);
if( _comp(PyObject_GetItem(array, j_PyObject), x, comp) == 1 ) {
if ( _comp(PyObject_GetItem(array, j_PyObject), x, comp) == 1 ) {
i = i + 1;
PyObject* i_PyObject = PyLong_FromLongLong(i);
PyObject* tmp = PyObject_GetItem(array, i_PyObject);
Expand All @@ -54,18 +54,18 @@ static PyObject* quick_sort_impl(PyObject* array, size_t lower, size_t upper,
rstack.push(lower);
rstack.push(upper);

while( !rstack.empty() ) {
while ( !rstack.empty() ) {
high = rstack.top();
rstack.pop();
low = rstack.top();
rstack.pop();
p = quick_sort_partition(low, high, pick_pivot_element,
comp, array);
if( p - 1 > low ) {
if ( p - 1 > low ) {
rstack.push(low);
rstack.push(p - 1);
}
if( p + 1 < high ) {
if ( p + 1 < high ) {
rstack.push(p + 1);
rstack.push(high);
}
Expand All @@ -81,35 +81,35 @@ static PyObject* quick_sort(PyObject* self, PyObject* args, PyObject* kwds) {
args0 = PyObject_GetItem(args, PyZero);
int is_DynamicOneDimensionalArray = _check_type(args0, &DynamicOneDimensionalArrayType);
int is_OneDimensionalArray = _check_type(args0, &OneDimensionalArrayType);
if( !is_DynamicOneDimensionalArray && !is_OneDimensionalArray ) {
if ( !is_DynamicOneDimensionalArray && !is_OneDimensionalArray ) {
raise_exception_if_not_array(args0);
return NULL;
}
comp = PyObject_GetItem(kwds, PyUnicode_FromString("comp"));
if( comp == NULL ) {
if ( comp == NULL ) {
PyErr_Clear();
}
pick_pivot_element = PyObject_GetItem(kwds, PyUnicode_FromString("pick_pivot_element"));
if( pick_pivot_element == NULL ) {
if ( pick_pivot_element == NULL ) {
PyErr_Clear();
}
start = PyObject_GetItem(kwds, PyUnicode_FromString("start"));
if( start == NULL ) {
if ( start == NULL ) {
PyErr_Clear();
lower = 0;
} else {
lower = PyLong_AsSize_t(start);
}
end = PyObject_GetItem(kwds, PyUnicode_FromString("end"));
if( end == NULL ) {
if ( end == NULL ) {
PyErr_Clear();
upper = PyObject_Length(args0) - 1;
} else {
upper = PyLong_AsSize_t(end);
}

args0 = quick_sort_impl(args0, lower, upper, comp, pick_pivot_element);
if( is_DynamicOneDimensionalArray ) {
if ( is_DynamicOneDimensionalArray ) {
PyObject_CallMethod(args0, "_modify", "O", Py_True);
}
Py_INCREF(args0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static PyObject* Array___new__(PyTypeObject* type, PyObject *args,

static PyObject* Array___str__(Array *self) {
PyObject* self__data = PyObject_GetAttrString(reinterpret_cast<PyObject*>(self), "_data");
if( !self__data ) {
if ( !self__data ) {
return NULL;
}
return PyObject_Str(self__data);
Expand Down
Loading
Loading