1
0

Refactored analyse_structure, and improved the quality of gotten depths.

This commit is contained in:
Jon Michael Aanes 2017-06-06 00:24:24 +02:00
parent f0670897bd
commit 4d3cf18797

View File

@ -159,6 +159,7 @@ local function get_table_info (t)
local key_types = get_key_types(t)
local info = {}
info.address = tostring(t):sub(8)
info.nr_elems = nr_elements_in_table(t)
info.seq_elems, info.has_holes = nr_elements_in_seq(t)
info.map_elems = info.nr_elems - info.seq_elems
@ -191,21 +192,25 @@ local function analyze_structure (root)
queue.bottom = queue.bottom + 1
local node = queue[queue.bottom-1]
-- Who've been visited? Bookkeeping
visited[node] = (visited[node] or 0) + 1
visited[node], info[node] = (visited[node] or 0) + 1, info[node] or get_table_info(node)
if visited[node] == 2 then
info[node].marker, next_mark = next_mark, next_mark + 1
end
-- Get table info & visit children.
if visited[node] < 2 then
info[node] = get_table_info(node)
info[node].depth = depth[node]
for k, v in pairs(node) do
if type(k) == 'table' then queue[queue.top], queue.top, depth[k] = k, queue.top + 1, depth[node] + 1 end
if type(v) == 'table' then queue[queue.top], queue.top, depth[v] = v, queue.top + 1, depth[node] + 1 end
if type(k) == 'table' then queue[queue.top], queue.top, depth[k] = k, queue.top + 1, math.min(depth[k] or math.huge, depth[node] + 1) end
if type(v) == 'table' then queue[queue.top], queue.top, depth[v] = v, queue.top + 1, math.min(depth[v] or math.huge, depth[node] + 1) end
end
end
end
-- Use depth collected
for node in pairs(depth) do
info[node].depth = depth[node]
info[node].address = info[node].address .. ': ' .. info[node].depth
end
assert(type(info) == 'table')
return info
end