Skip to content

Commit

Permalink
catches up repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Higgin committed May 25, 2024
1 parent 2431f63 commit 2a78188
Show file tree
Hide file tree
Showing 23 changed files with 2,546 additions and 0 deletions.
19 changes: 19 additions & 0 deletions code/__HELPERS/sorts/InsertSort.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//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/sort_instance/SI = GLOB.sortInstance
if(!SI)
SI = new
SI.L = L
SI.cmp = cmp
SI.associative = associative

SI.binarySort(fromIndex, toIndex, fromIndex)
return L
19 changes: 19 additions & 0 deletions code/__HELPERS/sorts/MergeSort.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//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/sort_instance/SI = GLOB.sortInstance
if(!SI)
SI = new
SI.L = L
SI.cmp = cmp
SI.associative = associative

SI.mergeSort(fromIndex, toIndex)
return L
20 changes: 20 additions & 0 deletions code/__HELPERS/sorts/TimSort.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//TimSort interface
/proc/sortTim(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/sort_instance/SI = GLOB.sortInstance
if(!SI)
SI = new

SI.L = L
SI.cmp = cmp
SI.associative = associative

SI.timSort(fromIndex, toIndex)
return L
Loading

0 comments on commit 2a78188

Please sign in to comment.