Files
Paradise/code/__HELPERS/sorts/MergeSort.dm
T
warriorstar-orion 0ffa8303a7 Rename all non-snake_case types. (#27268)
* refactor: Rename all non-snake_case types (not procs or vars (yet)).

* completely dynamic update script

* might help to include the data

* update aa's scuffed python

* oh

* set script PR number

* run updatepaths again

* Add other table updates with JSON columns

* bump SQL version

* just fucking end my life

* move JSON data
2024-11-30 19:08:45 +00:00

20 lines
544 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 && length(L) >= 2)
fromIndex = fromIndex % length(L)
toIndex = toIndex % (length(L) + 1)
if(fromIndex <= 0)
fromIndex += length(L)
if(toIndex <= 0)
toIndex += length(L) + 1
var/datum/sort_instance/SI = GLOB.sortInstance
if(!SI)
SI = new
SI.L = L
SI.cmp = cmp
SI.associative = associative
SI.mergeSort(fromIndex, toIndex)
return L