in reply to How to create a compact data structure?
My approach with such things is to use a tied hash (Berkeley DB in my case), and to pack and unpack the flag and count. It works well enough and is simple enough so I don't make ugly programming errors:
my $mask = "NN"; foreach my $item (LARGE_LIST) { $key = property($item); my $val = $record{ $key } || pack $mask, 0,0; my ($count, $flag) = unpack $mask, $val; $count++; $flag ||= condition_is_true($item); $record{ $key } = pack $mask, $count, $flag; }
Even without using a tied hash, you'll almost cut your memory use by half as you don't need to allocate the anonymous hash and the scalar for the flag anymore.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to create a compact data structure?
by shmem (Chancellor) on Dec 19, 2006 at 23:08 UTC | |
|
Re^2: How to create a compact data structure?
by bart (Canon) on Dec 19, 2006 at 20:58 UTC | |
by chromatic (Archbishop) on Dec 20, 2006 at 09:14 UTC |