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

Bricksort parallel implemented #221

Merged
merged 17 commits into from
Mar 30, 2020
Merged
Changes from 1 commit
Commits
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
9 changes: 5 additions & 4 deletions pydatastructs/linear_data_structures/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def brick_sort(array, **kwargs):
array._modify(force=True)

def _brick_sort_swap(array, i, j, comp, is_sorted):
if(_comp(array[j], array[i], comp)):
if _comp(array[j], array[i], comp):
czgdp1807 marked this conversation as resolved.
Show resolved Hide resolved
array[i], array[j] = array[j], array[i]
is_sorted[0] = False

Expand All @@ -177,7 +177,7 @@ def brick_sort_parallel(array, num_threads, **kwargs):
Parameters
==========

array: Array
array: Array/list
The array which is to be sorted.
num_threads: int
The maximum number of threads
Expand Down Expand Up @@ -212,7 +212,8 @@ def brick_sort_parallel(array, num_threads, **kwargs):

References
==========
czgdp1807 marked this conversation as resolved.
Show resolved Hide resolved
.. [1] https://www.geeksforgeeks.org/odd-even-sort-brick-sort/

.. [1] https://en.wikipedia.org/wiki/Odd%E2%80%93even_sort
"""

start = kwargs.get('start', 0)
Expand All @@ -223,7 +224,7 @@ def brick_sort_parallel(array, num_threads, **kwargs):
with ThreadPoolExecutor(max_workers=num_threads) as executor:
while is_sorted[0] is False:
is_sorted[0] = True
for i in range(start+1, end, 2):
for i in range(start + 1, end, 2):
executor.submit(_brick_sort_swap, array, i, i + 1, comp, is_sorted).result()

for i in range(start, end, 2):
Expand Down