Files
Paradise/code/__HELPERS/sorts/InsertSort.dm
tigercat2000 f5940155ca Spacing fixes.
2018-03-20 19:12:55 -07:00

19 lines
532 B
Plaintext

//simple insertion sort - generally faster than merge for runs of 7 or smaller
/proc/sortInsert(list/L, cmp = /proc/cmp_numeric_asc, associative, fromIndex = 1, toIndex = 0)
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.binarySort(fromIndex, toIndex, fromIndex)
return L