I have an array of name arrays that can be represented in Ruby as follows:
samples = [
%w[a],
%w[a c],
%w[a],
%w[a],
%w[b],
%w[b],
%w[a],
%w[a e],
%w[a e],
%w[a c d],
%w[a c d],
%w[b],
%w[b c e],
%w[b c e],
%w[a c],
%w[a e],
%w[a e]
]
This is the output of the sampler, where each list of names represents a call stack for a particular pattern. I want to show them as a drop-down tree with named values, where the value in each node is the sum of the calls to this particular call path.
In the above input example, the output tree should be:
root:0
a:4
e:4
c:2
d:2
b:3
c:0
e:2
(I do not want to output ASCII as shown above, but is a tree structure that represents this.)
What is simple, efficient code that produces this output?
I have my own solution, which I will lay out as an answer, but which seems less ideal to me.
. , . , .