mirror of
https://github.com/KabKebab/GS13.git
synced 2026-07-17 10:58:19 +01:00
Time to Build a Wall, a BORDER WALL
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user