Fast sorting algorithm implemented in Motoko language
- initialize the sorting range to [0, length - 1]
- iterate through the range and find min and max values
- fast return if no cases with (prev value > value) found
- set all items from the range in the counts array to 0
- for each item from the range in the input array
- calculate a new index as
rangeFrom + (item - min) / ((max - min) / (rangeTo - rangeFrom))
- increment counts array at this index
- calculate a new index as
- initialize totalCount to rangeFrom
- for each count from the range in the counts array which is not 0
- set shifterCounts array at index totalCount to count
- replace count in the counts array with totalCount
- add count to totalCount
- for each item from the range in the input array
- calculate a new index as
rangeFrom + (item - min) / ((max - min) / (rangeTo - rangeFrom))
- get count from counts array at this index
- set twinArray at index count to current item
- increment counts array at index
- calculate a new index as
- update all items from the range in the input array with values from twinArray
- for each index and count from the range in the shifterCounts array where count is greater than 1 run steps 2-9 with the range set to [index, index + count - 1]