I am looking at a possible "time/space" trade-off problem. I am evaluating storing a set of data that is keyed by 3 attributes:
attr1 is a number in the range 200-35000The hash key is "attr1.attr2.attr3", The hash content is a ref to an anon array.
Could there be a significant performance improvement by maintaining a second hash of just 'attr1' to pre-determine if any keys start with attr1?
vsmy $arrayRef; if ( defined ?attr1Hash{$attr1}){ my $key ="attr1.attr2.attr3"; $arrayRef = $fullHash{$key}; } if ( defined $arrayRef){ ... }
UPDATE:my $arrayRef; my $key ="attr1.attr2.attr3"; $arrayRef = $fullHash{$key}; if ( defined $arrayRef){ ... }
I have a process that is watching (ala 'less') the system syslog file for pre-determined message keywords, which are reported across the net to a higher authority. Some of the tests done on a record may cause sub-shells to be spawned to determine system state.
But basicly pretty straight forward.
Generate a special event report if any unique process(pid), in a specified time period, creates more than 3 of the syslog messages. I have gone from statless scan to a time limited historic context.
The module I am working on holds the 'state'
$EventHash{$pid} = [ create_ts, last_upt, $ev_cnt];
It is always better to have seen your target for yourself, rather than depend upon someone else's description.
In reply to Hash space/ time tradeoff by Wiggins
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |