Files
Paradise/code/__HELPERS/sorts/MergeSort.dm
S34N 667dd5d4ac 515 Compatibility (#19636)
* 515 compat

* double spaces

* Callback documentation, aa review

* spacing

* NAMEOF_STATIC

* big beta
2022-11-08 23:08:40 +00:00

20 lines
523 B
Plaintext

//merge-sort - gernerally faster than insert sort, for runs of 7 or larger
/proc/sortMerge(list/L, cmp = GLOBAL_PROC_REF(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/sortInstance/SI = GLOB.sortInstance
if(!SI)
SI = new
SI.L = L
SI.cmp = cmp
SI.associative = associative
SI.mergeSort(fromIndex, toIndex)
return L