Re: "dumping" a map
- Posted by cjnwl Feb 22, 2023
- 1336 views
For what it's worth, here is my quick and dirty map_dump function. It relies on the key being prefixed with "m_" :
-- map investigation include std/io.e include std/map.e procedure map_dump(map m, integer offset) integer s = map:size(m) sequence k = map:keys(m) sequence v = map:values(m) for i = 1 to s do if sequence(k[i]) and equal("m_", k[i][1..2]) then writefln("[]>[]", {repeat(32, offset), k[i]}) map_dump(v[i], offset+2) else writefln("[][] = []", {repeat(32, offset), k[i], v[i]}) end if end for return end procedure map tables = new() -- map to hold tables data map kids = new() -- map to hold kids map smap = new() -- map to hold submap map:put(tables, "id", 1) map:put(tables, "name", "aaa") map:put(kids, 1, "alice") map:put(kids, 2, "tom") map:put(kids, 3, "wendy") map:put(tables, "m_kids", kids) map:put(smap, "test", "test") map:put(smap, "description", "long description") map:put(kids, "m_test", smap) map_dump(tables, 0)
This gives the following output :
id = 1 >m_kids 1 = alice >m_test description = long description test = test 3 = wendy 2 = tom name = aaa