Files
Citadel-Station-13-RP/code/__HELPERS/sorts/MergeSort.dm
Zandario ed05e01a95 __HELPERS Cleaning and other things I decided to do. (#4584)
* Schizoposting

* The Crungly

* Tabbin' the JSON y'all

* Strings
2022-10-21 01:56:59 -07:00

23 lines
522 B
Plaintext

/**
* MergeSort
* - Gernerally faster than insert sort, for runs of 7 or larger.
*/
/proc/merge_sort(list/L, cmp=/proc/cmp_numeric_asc, associative, fromIndex=1, toIndex)
if(L && L.len >= 2)
fromIndex = fromIndex % L.len
toIndex = toIndex % (L.len+1)
if(fromIndex <= 0)
fromIndex += L.len
if(toIndex <= 0)
toIndex += L.len + 1
var/datum/sort_instance/SI = GLOB.sort_instance
if(!SI)
SI = new
SI.L = L
SI.cmp = cmp
SI.associative = associative
SI.sort_merge(fromIndex, toIndex)
return L