in reply to Re: calculate average from range of hash values (optimize)
in thread calculate average from range of hash values (optimize)

Thanks for the reply, cleverett, but there are a few reasons it is not exactly applicable to my situation. One, which I specifically mentioned in my post, is I would like to avoid using an array. The keys are Quite Large Numbers (for example '1059159920'), and trying to add even one array entry with an index that high runs out of memory. Another reason that I didn't mention, or even think about when I first made my post, is the keys are relatively sparse. I can't simply roll through the range in sequence; I have to make sure the keys exist.

That said, your post does give me some food for thought, and I might just steal some of your ideas. :)

  • Comment on Re: Re: calculate average from range of hash values (optimize)

Replies are listed 'Best First'.
Re: Re: Re: calculate average from range of hash values (optimize)
by cleverett (Friar) on Jul 27, 2003 at 16:05 UTC
    Perhaps keep an index to the original data hash, thusly:
    use strict; ## simulate original %data hash my %data = map { (int(rand(10**10) + 10**9) => rand } (0 .. 2*10**5); my ($keys, $values) = ([], []); ## remember what goes where foreach (sort keys %data) { push @$keys, $_; push @$values, $data{$_}; } ## now obtain rolling averages