proc
get_ListDimensions(var/list/current)
if(!islist(current)) CRASH("Not a valid list")
var/list/dimensions = new()
while(islist(current))
dimensions += length(current)
current = current[1]
return dimensions
ID:891677
Jul 26 2012, 4:39 pm
|
|
I was just experimenting a bit and wanted to see if there was a good way to get the size of a multidimensional list. This is what I came up with: Code:
|
Actually, I was working on a making a datum to hold a multidimensional list in a single list (because I keep reading that BYOND is bad at multidimensional lists).
This proc was going to be used to help convert a traditional multidimensional list to the new matrix datum. If the list is a jagged list it can't be converted and I would need break out of it. Edit: For clarity this is the islist() proc proc/islist(list/l) |
It seems I may have found a solution although it is a bit recursion happy:
proc Here is a test: client I am not sure I am happy with all the recursion and all the variables I am creating to test this. Anyone else have any ideas? Profile results (total time) |
I have to ask, though, in what context are you working that you can't always control if the list will be a true multidimensional list or not?