in reply to How to create a compact data structure?
You could use a single integer to encode both the count and the flag, e.g. by using the lowest bit for the flag, and counting in steps of two. Then you'd only need one hash for the whole shebang.
foreach my $item (LARGE_LIST) { $key = property($item); $record{$key} += 2; if(condition_is_true($item)) { $record{$key} |= 1; } }
Then later, to extract $count and $flag, something like
for my $key (keys %record) { my $count = $record{$key} >> 1; my $flag = $record{$key} & 1; print "$key\n" if $count >= 2 and $flag; # ... }
Not the most readable and easily maintable code, but if size is all that matters...
|
|---|