Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Counter - number of tags per interval

by Laurent_R (Prior)
on May 04, 2013 at 14:30 UTC ( #1032046=note: print w/ replies, xml ) Need Help??


in reply to Counter - number of tags per interval

Hi

I do not know if this will help and also don't know if this will be faster, but I would try to use a different data structure: a hash of arrays with each array containing 3 elements: the interval lower limit, the interval upper limit and the tag count.

As a (very light) proof of concept, I will simplify the problem by simply forgetting about the a, b et so on, but just using a simple list of ranges. Or, if you prefer, I will deal only with your data related to letter a. Since I do not understand what your tags are about, I will just add 1 to the count when the value of the variable falls within the range.

This gives me the following session under the Perl debugger:

DB<49> @c = ([12,15], [12,17], [13,14], [14,19]) DB<50> x @c 0 ARRAY(0x20498b98) 0 12 1 15 1 ARRAY(0x20499588) 0 12 1 17 2 ARRAY(0x2049c428) 0 13 1 14 3 ARRAY(0x2049c488) 0 14 1 19 DB<51> $e = 17 DB<52> $_->[2]++ foreach grep {$e <= $_->[1]} grep {$e >= $_->[0]} @ +c DB<53> x @c 0 ARRAY(0x20498b98) 0 12 1 15 1 ARRAY(0x20499588) 0 12 1 17 2 1 2 ARRAY(0x2049c428) 0 13 1 14 3 ARRAY(0x2049c488) 0 14 1 19 2 1 DB<54> $e = 13; DB<55> $_->[2]++ foreach grep {$e <= $_->[1]} grep {$e >= $_->[0]} @ +c DB<56> x @c 0 ARRAY(0x20498b98) 0 12 1 15 2 1 1 ARRAY(0x20499588) 0 12 1 17 2 2 2 ARRAY(0x2049c428) 0 13 1 14 2 1 3 ARRAY(0x2049c488) 0 14 1 19 2 1 DB<57>


Comment on Re: Counter - number of tags per interval
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1032046]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2015-07-06 08:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (70 votes), past polls