# cython: language_level=3

"""Module provides nothing but a simple bubble sort."""

ifdef(`m4purepy',`@profile')
ifdef(`m4pyx',cp)def bubblesort(ifdef(`m4pyx',list )list_, ifdef(`m4pyx',unsigned int )left, ifdef(`m4pyx',unsigned int) right):
    """Perform an bubble sort on a subregion of a list."""
ifdef(`m4pyx',`    cdef unsigned int i')
ifdef(`m4pyx',`    cdef unsigned int j')
ifdef(`m4pyx',`    cdef unsigned int out_of_order_found')
    out_of_order_found = 1
    while out_of_order_found:
        out_of_order_found = 0
        for i in range(left, right):
            if list_[i] > list_[i+1]:
                list_[i], list_[i+1] = list_[i+1], list_[i]
                out_of_order_found = True