in reply to Re: How to create a compact data structure?
in thread How to create a compact data structure?

(in the HoIVs variant):

if( condition_is_true( $item ) ) { $records{ $key } = - $records{ $key }; }

Minor nitpick: if condition happens to be true more than once, the flag / sign bit would act like a flip-flop (the electronic circuit, not the shoes style, that is :), i.e. being reset on every other turn of the condition being true. Not sure if this can happen in the OPs data, though.

While being irrelevant for testing memory consumption, it might yield unexpected results when used as is in production code.

Anyway, it's easy to fix:

$records{ $key } = - $records{ $key } if $records{ $key } > 0;

Other than that, ++ for your analysis and comments, of course :)