The 515 MegaPR early downport (#7783)

Co-authored-by: Selis <selis@xynolabs.com>
Co-authored-by: Selis <sirlionfur@hotmail.de>
Co-authored-by: Kashargul <144968721+Kashargul@users.noreply.github.com>
Co-authored-by: SatinIsle <thesatinisle@gmail.com>
Co-authored-by: Heroman <alesha3000@list.ru>
Co-authored-by: Casey <a.roaming.shadow@gmail.com>
Co-authored-by: Raeschen <rycoop29@gmail.com>
This commit is contained in:
Cadyn
2024-02-27 20:17:32 +01:00
committed by GitHub
co-authored by Selis Selis Kashargul SatinIsle Heroman Casey Raeschen
parent 96a43a09c1
commit b90f7ec922
254 changed files with 2135 additions and 1576 deletions
+8 -4
View File
@@ -8,10 +8,14 @@
if(toIndex <= 0)
toIndex += L.len + 1
sortInstance.L = L
sortInstance.cmp = cmp
sortInstance.associative = associative
var/datum/sort_instance/SI = GLOB.sortInstance
if(!SI)
SI = new
sortInstance.timSort(fromIndex, toIndex)
SI.L = L
SI.cmp = cmp
SI.associative = associative
SI.timSort(fromIndex, toIndex)
return L
+16 -16
View File
@@ -9,13 +9,13 @@
#define MIN_GALLOP 7
//This is a global instance to allow much of this code to be reused. The interfaces are kept separately
var/datum/sortInstance/sortInstance = new()
/datum/sortInstance
GLOBAL_DATUM_INIT(sortInstance, /datum/sort_instance, new())
/datum/sort_instance
//The array being sorted.
var/list/L
//The comparator proc-reference
var/cmp = /proc/cmp_numeric_asc
var/cmp = GLOBAL_PROC_REF(cmp_numeric_asc)
//whether we are sorting list keys (0: L[i]) or associated values (1: L[L[i]])
var/associative = 0
@@ -32,7 +32,7 @@ var/datum/sortInstance/sortInstance = new()
var/list/runLens = list()
/datum/sortInstance/proc/timSort(start, end)
/datum/sort_instance/proc/timSort(start, end)
runBases.Cut()
runLens.Cut()
@@ -97,7 +97,7 @@ lo the index of the first element in the range to be sorted
hi the index after the last element in the range to be sorted
start the index of the first element in the range that is not already known to be sorted
*/
/datum/sortInstance/proc/binarySort(lo, hi, start)
/datum/sort_instance/proc/binarySort(lo, hi, start)
//ASSERT(lo <= start && start <= hi)
if(start <= lo)
start = lo + 1
@@ -134,7 +134,7 @@ For its intended use in a stable mergesort, the strictness of the
definition of "descending" is needed so that the call can safely
reverse a descending sequence without violating stability.
*/
/datum/sortInstance/proc/countRunAndMakeAscending(lo, hi)
/datum/sort_instance/proc/countRunAndMakeAscending(lo, hi)
//ASSERT(lo < hi)
var/runHi = lo + 1
@@ -164,7 +164,7 @@ reverse a descending sequence without violating stability.
//Returns the minimum acceptable run length for an array of the specified length.
//Natural runs shorter than this will be extended with binarySort
/datum/sortInstance/proc/minRunLength(n)
/datum/sort_instance/proc/minRunLength(n)
//ASSERT(n >= 0)
var/r = 0 //becomes 1 if any bits are shifted off
while(n >= MIN_MERGE)
@@ -177,7 +177,7 @@ reverse a descending sequence without violating stability.
// runLen[i-2] > runLen[i-1]
//This method is called each time a new run is pushed onto the stack.
//So the invariants are guaranteed to hold for i<stackSize upon entry to the method
/datum/sortInstance/proc/mergeCollapse()
/datum/sort_instance/proc/mergeCollapse()
while(runBases.len >= 2)
var/n = runBases.len - 1
if(n > 1 && runLens[n-1] <= runLens[n] + runLens[n+1])
@@ -192,7 +192,7 @@ reverse a descending sequence without violating stability.
//Merges all runs on the stack until only one remains.
//Called only once, to finalise the sort
/datum/sortInstance/proc/mergeForceCollapse()
/datum/sort_instance/proc/mergeForceCollapse()
while(runBases.len >= 2)
var/n = runBases.len - 1
if(n > 1 && runLens[n-1] < runLens[n+1])
@@ -203,7 +203,7 @@ reverse a descending sequence without violating stability.
//Merges the two consecutive runs at stack indices i and i+1
//Run i must be the penultimate or antepenultimate run on the stack
//In other words, i must be equal to stackSize-2 or stackSize-3
/datum/sortInstance/proc/mergeAt(i)
/datum/sort_instance/proc/mergeAt(i)
//ASSERT(runBases.len >= 2)
//ASSERT(i >= 1)
//ASSERT(i == runBases.len - 1 || i == runBases.len - 2)
@@ -257,7 +257,7 @@ reverse a descending sequence without violating stability.
Returns the index at which to insert element 'key'
*/
/datum/sortInstance/proc/gallopLeft(key, base, len, hint)
/datum/sort_instance/proc/gallopLeft(key, base, len, hint)
//ASSERT(len > 0 && hint >= 0 && hint < len)
var/lastOffset = 0
@@ -316,7 +316,7 @@ reverse a descending sequence without violating stability.
* @param c the comparator used to order the range, and to search
* @return the int k, 0 <= k <= n such that a[b + k - 1] <= key < a[b + k]
*/
/datum/sortInstance/proc/gallopRight(key, base, len, hint)
/datum/sort_instance/proc/gallopRight(key, base, len, hint)
//ASSERT(len > 0 && hint >= 0 && hint < len)
var/offset = 1
@@ -368,7 +368,7 @@ reverse a descending sequence without violating stability.
//Merges two adjacent runs in-place in a stable fashion.
//For performance this method should only be called when len1 <= len2!
/datum/sortInstance/proc/mergeLo(base1, len1, base2, len2)
/datum/sort_instance/proc/mergeLo(base1, len1, base2, len2)
//ASSERT(len1 > 0 && len2 > 0 && base1 + len1 == base2)
var/cursor1 = base1
@@ -470,7 +470,7 @@ reverse a descending sequence without violating stability.
//ASSERT(len1 > 1)
/datum/sortInstance/proc/mergeHi(base1, len1, base2, len2)
/datum/sort_instance/proc/mergeHi(base1, len1, base2, len2)
//ASSERT(len1 > 0 && len2 > 0 && base1 + len1 == base2)
var/cursor1 = base1 + len1 - 1 //start at end of sublists
@@ -570,7 +570,7 @@ reverse a descending sequence without violating stability.
//ASSERT(len2 > 0)
/datum/sortInstance/proc/mergeSort(start, end)
/datum/sort_instance/proc/mergeSort(start, end)
var/remaining = end - start
//If array is small, do an insertion sort
@@ -615,7 +615,7 @@ reverse a descending sequence without violating stability.
return L
/datum/sortInstance/proc/mergeAt2(i)
/datum/sort_instance/proc/mergeAt2(i)
var/cursor1 = runBases[i]
var/cursor2 = runBases[i+1]