C
ctcgag
Michele Dondi said:I'm writing a script to do a few arithmetic computations. The code is
highly factorized in small subs and I'd like to do some "manual"
memoizing, i.e. not using the Memoize module of which I'm aware.
FWIW *one* of the reasons why I do not want to use Memoize is that
values to be cached (1) are not the return values of the subs, (2)
they can be "produced" by different subs.
So then couldn't they be pulled into a sub sub which is used by the all
the subs?
The data to be saved correspond to couples of integers $a, $b with
$a<$b and the question is: should I store them in a hash indexed, say,
by keys like $a.','.$b or in an AoA? Is there any advantage of one
method over the other?
What are the legal bounds on $a and $b, and how dense do you expect the
memoized data to get? If the number that will actually be stored is sparce
WRT the number of legal pairs, that would favor hashes. If the number
stored is dense WRT all legal pairs, that would favor arrays.
(If you use AoA, it should be $mem[$b][$a], not $mem[$a][$b])
Xho