Time to Build a Wall, a BORDER WALL

This commit is contained in:
Krer-Grimpaw
2023-12-23 14:08:32 -08:00
parent 0b2d9e41a3
commit 8330afa338
8 changed files with 235 additions and 1 deletions
+22
View File
@@ -17,6 +17,7 @@
#define LAZYFIND(L, V) L ? L.Find(V) : 0
#define LAZYACCESS(L, I) (L ? (isnum(I) ? (I > 0 && I <= length(L) ? L[I] : null) : L[I]) : null)
#define LAZYSET(L, K, V) if(!L) { L = list(); } L[K] = V;
#define LAZYISIN(L, V) L ? (V in L) : FALSE
#define LAZYLEN(L) length(L)
#define LAZYCLEARLIST(L) if(L) L.Cut()
#define SANITIZE_LIST(L) ( islist(L) ? L : list() )
@@ -577,3 +578,24 @@
for(var/key in input)
ret += key
return ret
// Insert an object A into a sorted list using cmp_proc (/code/_helpers/cmp.dm) for comparison.
#define ADD_SORTED(list, A, cmp_proc) if(!list.len) {list.Add(A)} else {list.Insert(FindElementIndex(A, list, cmp_proc), A)}
// Return the index using dichotomic search
/proc/FindElementIndex(atom/A, list/L, cmp)
var/i = 1
var/j = L.len
var/mid
while(i < j)
mid = round((i+j)/2)
if(call(cmp)(L[mid],A) < 0)
i = mid + 1
else
j = mid
if(i == 1 || i == L.len) // Edge cases
return (call(cmp)(L[i],A) > 0) ? i : i+1
else
return i