mirror of
https://github.com/fulpstation/fulpstation.git
synced 2025-12-10 10:01:40 +00:00
19 lines
505 B
Plaintext
19 lines
505 B
Plaintext
//merge-sort - gernerally faster than insert sort, for runs of 7 or larger
|
|
/proc/sortMerge(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/sortInstance/SI = GLOB.sortInstance
|
|
if(!SI)
|
|
SI = new
|
|
SI.L = L
|
|
SI.cmp = cmp
|
|
SI.associative = associative
|
|
|
|
SI.mergeSort(fromIndex, toIndex)
|
|
return L |