Last active
March 9, 2023 07:28
-
-
Save Floofies/d81f4d13dc47a49c234c277a624ac12c to your computer and use it in GitHub Desktop.
Return string representation of every value in the given list. Traverses sub-lists to provide every reachable value.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Return string representation of every value in the given list. | |
/// Traverses sub-lists to provide every reachable value. | |
/proc/list2string(root) | |
var/str = "Travsersal Tree for `[root]`:\n" | |
var/list/seen_lists = list("\ref[root]") | |
var/list/runqueue = list() | |
var/list/waitqueue = list() | |
waitqueue[root] = list("root", " ") | |
while(length(waitqueue)) | |
runqueue = waitqueue.Copy() | |
waitqueue.Cut() | |
for(var/node in runqueue) | |
var/node_accessor = runqueue[node][1] | |
var/indent = runqueue[node][2] | |
runqueue -= node | |
if(!length(node)) | |
str += ">[indent][node_accessor]: (empty list)\n" | |
continue | |
str += ">[indent][node_accessor]:\n" | |
for(var/accessor as anything in node) | |
var/value = node[accessor] | |
if(islist(value)) | |
var/hash = "\ref[value]" | |
if(hash in seen_lists) | |
continue | |
waitqueue[value] = list(accessor, "[indent] ") | |
seen_lists += hash | |
else | |
str += " [indent][accessor]: [isnull(value) ? "null" : value]\n" | |
return str |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment