Hi, new to functional programming question:
I'm building a structure to store a "graph", lets pretend the algorithm
is say GADDAG (
http://en.wikipedia.org/wiki/GADDAG)
Now one of the space saving techniques in such a structure is where
several sub graphs are identical, to replace them with pointers to each
other. I'm unsure how to achieve this in Erlang/Elixir.
Phrased another way
a = [1,2,3,4]
t1 = {:something, a}
t2 = {:something2, a}
Is the storage for "a" allocated more than once (or twice)?
If the answer is it stores it once, then will this also work via matching?
a = [1,2,3,4]
t1 = {:something, a}
{_, b} = t1
t2 = {:something2, b}
Again in this instance is my list stored just the once?
I'm hoping that the VM is smart enough to combine these and store the
data just once. My proposed solution then to reducing allocation side in
my GODDAG is presumably then to find sub graphs which are "identical" in
turns of node contents and then "copy" one sub graph to the other (I'm
not sure what the correct word would be in a functional sense for
"copy", but hopefully the above illustrates the action)
Thanks for advice
Ed W