sorts.odd_even_transposition_parallel

This is an implementation of odd-even transposition sort.

It works by performing a series of parallel swaps between odd and even pairs of variables in the list.

This implementation represents each variable in the list with a process and each process communicates with its neighboring processes in the list to perform comparisons. They are synchronized with locks and message passing but other forms of synchronization could be used.

Functions

main()

odd_even_transposition(arr)

oe_process(position, value, l_send, r_send, lr_cv, ...)

Module Contents

sorts.odd_even_transposition_parallel.main()
sorts.odd_even_transposition_parallel.odd_even_transposition(arr)
>>> odd_even_transposition(list(range(10)[::-1])) == sorted(list(range(10)[::-1]))
True
>>> odd_even_transposition(["a", "x", "c"]) == sorted(["x", "a", "c"])
True
>>> odd_even_transposition([1.9, 42.0, 2.8]) == sorted([1.9, 42.0, 2.8])
True
>>> odd_even_transposition([False, True, False]) == sorted([False, False, True])
True
>>> odd_even_transposition([1, 32.0, 9]) == sorted([False, False, True])
False
>>> odd_even_transposition([1, 32.0, 9]) == sorted([1.0, 32, 9.0])
True
>>> unsorted_list = [-442, -98, -554, 266, -491, 985, -53, -529, 82, -429]
>>> odd_even_transposition(unsorted_list) == sorted(unsorted_list)
True
>>> unsorted_list = [-442, -98, -554, 266, -491, 985, -53, -529, 82, -429]
>>> odd_even_transposition(unsorted_list) == sorted(unsorted_list + [1])
False
sorts.odd_even_transposition_parallel.oe_process(position, value, l_send, r_send, lr_cv, rr_cv, result_pipe, multiprocessing_context)