Fast sorting algorithm implemented in Motoko language
- initialize the sorting
rangeto[0, length - 1] - iterate through the
rangeand findminandmaxvalues- fast return if no cases with
(prev value > value)found
- fast return if no cases with
- set all items from the
rangein thecountsarray to0 - for each
itemfrom therangein the input array- calculate a new
indexasrangeFrom + (item - min) / ((max - min) / (rangeTo - rangeFrom)) - increment
countsarray at thisindex
- calculate a new
- initialize
totalCounttorangeFrom - for each
countfrom therangein thecountsarray which is not0- set
shiftedCountsarray at indextotalCounttocount - replace
countin thecountsarray withtotalCount - add
counttototalCount
- set
- for each
itemfrom therangein the input array- calculate a new
indexasrangeFrom + (item - min) / ((max - min) / (rangeTo - rangeFrom)) - get
countfromcountsarray at thisindex - set
twinArrayat indexcountto currentitem - increment
countsarray atindex
- calculate a new
- update all items from the
rangein the input array with values fromtwinArray - for each
indexandcountfrom therangein theshiftedCountsarray wherecountis greater than1run steps2-9with therangeset to[index, index + count - 1]