anchor.diff:  	definition of "descending" is needed so that the call can safely
   	reverse a descending sequence without violating stability.
   	*/
  -	proc/countRunAndMakeAscending(lo, hi)
  -		//ASSERT(lo < hi)
  -
  -		var/runHi = lo + 1
  -		if(runHi >= hi)
  -			return 1
  -
  -		var/last = fetchElement(L,lo)
  -		var/current = fetchElement(L,runHi++)
  -
  -		if(call(cmp)(current, last) < 0)
  -			while(runHi < hi)
  -				last = current
  -				current = fetchElement(L,runHi)
  -				if(call(cmp)(current, last) >= 0)
  -					break
  -				++runHi
  -			reverseRange(L, lo, runHi)
  -		else
  -			while(runHi < hi)
  -				last = current
  -				current = fetchElement(L,runHi)
  -				if(call(cmp)(current, last) < 0)
  -					break
  -				++runHi
  -
  -		return runHi - lo
  +/datum/sortInstance/proc/countRunAndMakeAscending(lo, hi)
  +	//ASSERT(lo < hi)
  +
  +	var/runHi = lo + 1
  +	if(runHi >= hi)
  +		return 1
  +
  +	var/last = fetchElement(L,lo)
  +	var/current = fetchElement(L,runHi++)
  +
  +	if(call(cmp)(current, last) < 0)
  +		while(runHi < hi)
  +			last = current
  +			current = fetchElement(L,runHi)
  +			if(call(cmp)(current, last) >= 0)
  +				break
  +			++runHi
  +		reverseRange(L, lo, runHi)
  +	else
  +		while(runHi < hi)
  +			last = current
  +			current = fetchElement(L,runHi)
  +			if(call(cmp)(current, last) < 0)
  +				break
  +			++runHi
  +
  +	return runHi - lo
   
   	//Returns the minimum acceptable run length for an array of the specified length.
   	//Natural runs shorter than this will be extended with binarySort
  -	proc/minRunLength(n)
  -		//ASSERT(n >= 0)
  -		var/r = 0	//becomes 1 if any bits are shifted off
  -		while(n >= MIN_MERGE)
  -			r |= (n & 1)
  -			n >>= 1
  -		return n + r
  +/datum/sortInstance/proc/minRunLength(n)
  +	//ASSERT(n >= 0)
  +	var/r = 0	//becomes 1 if any bits are shifted off
  +	while(n >= MIN_MERGE)
  +		r |= (n & 1)
  +		n >>= 1
  +	return n + r
   
   	//Examines the stack of runs waiting to be merged and merges adjacent runs until the stack invariants are reestablished:
   	//	runLen[i-3] > runLen[i-2] + runLen[i-1]
   	//	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
  -	proc/mergeCollapse()
  -		while(runBases.len >= 2)
  -			var/n = runBases.len - 1
  -			if(n > 1 && runLens[n-1] <= runLens[n] + runLens[n+1])
  -				if(runLens[n-1] < runLens[n+1])
  -					--n
  -				mergeAt(n)
  -			else if(runLens[n] <= runLens[n+1])
  -				mergeAt(n)
  -			else
  -				break	//Invariant is established
  +/datum/sortInstance/proc/mergeCollapse()
  +	while(runBases.len >= 2)
  +		var/n = runBases.len - 1
  +		if(n > 1 && runLens[n-1] <= runLens[n] + runLens[n+1])
  +			if(runLens[n-1] < runLens[n+1])
  +				--n
  +			mergeAt(n)
  +		else if(runLens[n] <= runLens[n+1])
  +			mergeAt(n)
  +		else
  +			break	//Invariant is established
   
   
   	//Merges all runs on the stack until only one remains.
   	//Called only once, to finalise the sort
  -	proc/mergeForceCollapse()
  -		while(runBases.len >= 2)
  -			var/n = runBases.len - 1
  -			if(n > 1 && runLens[n-1] < runLens[n+1])
  -				--n
  -			mergeAt(n)
  +/datum/sortInstance/proc/mergeForceCollapse()
  +	while(runBases.len >= 2)
  +		var/n = runBases.len - 1
  +		if(n > 1 && runLens[n-1] < runLens[n+1])
  +			--n
  +		mergeAt(n)
   
   
   	//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
  -	proc/mergeAt(i)
  -		//ASSERT(runBases.len >= 2)
  -		//ASSERT(i >= 1)
  -		//ASSERT(i == runBases.len - 1 || i == runBases.len - 2)
  -
  -		var/base1 = runBases[i]
  -		var/base2 = runBases[i+1]
  -		var/len1 = runLens[i]
  -		var/len2 = runLens[i+1]
  -
  -		//ASSERT(len1 > 0 && len2 > 0)
  -		//ASSERT(base1 + len1 == base2)
  -
  -		//Record the legth of the combined runs. If i is the 3rd last run now, also slide over the last run
  -		//(which isn't involved in this merge). The current run (i+1) goes away in any case.
  -		runLens[i] += runLens[i+1]
  -		runLens.Cut(i+1, i+2)
  -		runBases.Cut(i+1, i+2)
  -
  -
  -		//Find where the first element of run2 goes in run1.
  -		//Prior elements in run1 can be ignored (because they're already in place)
  -		var/k = gallopRight(fetchElement(L,base2), base1, len1, 0)
  -		//ASSERT(k >= 0)
  -		base1 += k
  -		len1 -= k
  -		if(len1 == 0)
  -			return
  -
  -		//Find where the last element of run1 goes in run2.
  -		//Subsequent elements in run2 can be ignored (because they're already in place)
  -		len2 = gallopLeft(fetchElement(L,base1 + len1 - 1), base2, len2, len2-1)
  -		//ASSERT(len2 >= 0)
  -		if(len2 == 0)
  -			return
  -
  -		//Merge remaining runs, using tmp array with min(len1, len2) elements
  -		if(len1 <= len2)
  -			mergeLo(base1, len1, base2, len2)
  -		else
  -			mergeHi(base1, len1, base2, len2)
  +/datum/sortInstance/proc/mergeAt(i)
  +	//ASSERT(runBases.len >= 2)
  +	//ASSERT(i >= 1)
  +	//ASSERT(i == runBases.len - 1 || i == runBases.len - 2)
  +
  +	var/base1 = runBases[i]
  +	var/base2 = runBases[i+1]
  +	var/len1 = runLens[i]
  +	var/len2 = runLens[i+1]
  +
  +	//ASSERT(len1 > 0 && len2 > 0)
  +	//ASSERT(base1 + len1 == base2)
  +
  +	//Record the legth of the combined runs. If i is the 3rd last run now, also slide over the last run
  +	//(which isn't involved in this merge). The current run (i+1) goes away in any case.
  +	runLens[i] += runLens[i+1]
  +	runLens.Cut(i+1, i+2)
  +	runBases.Cut(i+1, i+2)
  +
  +
  +	//Find where the first element of run2 goes in run1.
  +	//Prior elements in run1 can be ignored (because they're already in place)
  +	var/k = gallopRight(fetchElement(L,base2), base1, len1, 0)
  +	//ASSERT(k >= 0)
  +	base1 += k
  +	len1 -= k
  +	if(len1 == 0)
  +		return
  +
  +	//Find where the last element of run1 goes in run2.
  +	//Subsequent elements in run2 can be ignored (because they're already in place)
  +	len2 = gallopLeft(fetchElement(L,base1 + len1 - 1), base2, len2, len2-1)
  +	//ASSERT(len2 >= 0)
  +	if(len2 == 0)
  +		return
  +
  +	//Merge remaining runs, using tmp array with min(len1, len2) elements
  +	if(len1 <= len2)
  +		mergeLo(base1, len1, base2, len2)
  +	else
  +		mergeHi(base1, len1, base2, len2)
   
   
   	/*
  
positive.code: 
  		Returns the index at which to insert element 'key'
  	*/
  	proc/gallopLeft(key, base, len, hint)
  		//ASSERT(len > 0 && hint >= 0 && hint < len)
  
  		var/lastOffset = 0
  		var/offset = 1
  		if(call(cmp)(key, fetchElement(L,base+hint)) > 0)
  			var/maxOffset = len - hint
  			while(offset < maxOffset && call(cmp)(key, fetchElement(L,base+hint+offset)) > 0)
  				lastOffset = offset
  				offset = (offset << 1) + 1
  
  			if(offset > maxOffset)
  				offset = maxOffset
  
  			lastOffset += hint
  			offset += hint
  
  		else
  			var/maxOffset = hint + 1
  			while(offset < maxOffset && call(cmp)(key, fetchElement(L,base+hint-offset)) <= 0)
  				lastOffset = offset
  				offset = (offset << 1) + 1
  
  			if(offset > maxOffset)
  				offset = maxOffset
  
  			var/temp = lastOffset
  			lastOffset = hint - offset
  			offset = hint - temp
  
  			//ASSERT(-1 <= lastOffset && lastOffset < offset && offset <= len)
  
  		//Now L[base+lastOffset] < key <= L[base+offset], so key belongs somewhere to the right of lastOffset but no farther than
  		//offset. Do a binary search with invariant L[base+lastOffset-1] < key <= L[base+offset]
  		++lastOffset
  		while(lastOffset < offset)
  			var/m = lastOffset + ((offset - lastOffset) >> 1)
  
  			if(call(cmp)(key, fetchElement(L,base+m)) > 0)
  				lastOffset = m + 1
  			else
  				offset = m
  
  		//ASSERT(lastOffset == offset)
  		return offset
  
  	/**
  	 * Like gallopLeft, except that if the range contains an element equal to
  
negative.code: 	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)
  	//ASSERT(lo <= start && start <= hi)
  	if(start <= lo)
  		start = lo + 1
  
  	for(,start < hi, ++start)
  		var/pivot = fetchElement(L,start)
  
  		//set left and right to the index where pivot belongs
  		var/left = lo
  		var/right = start
  		//ASSERT(left <= right)
  
  		//[lo, left) elements <= pivot < [right, start) elements
  		//in other words, find where the pivot element should go using bisection search
  		while(left < right)
  			var/mid = (left + right) >> 1	//round((left+right)/2)
  			if(call(cmp)(fetchElement(L,mid), pivot) > 0)
  				right = mid
  			else
  				left = mid+1
  
  		//ASSERT(left == right)
  		moveElement(L, start, left)	//move pivot element to correct location in the sorted range
  
  	/*
  	Returns the length of the run beginning at the specified position and reverses the run if it is back-to-front
  