in reply to Re^2: Small Hash a Gateway to Large Hash?
in thread Small Hash a Gateway to Large Hash?
Keys are simply short strings of integers.
Hm. Does that mean each key is a single short integer, or each key contains several integers?
Here's why I ask. The following build two hashes with 1 million key/value pairs.
C:\test>p1 Perl> #5.6MB ;; Perl> $h{ "$_ " x 3} = "$_ " x 10 for 1e6 .. 2e6;; Perl> # 299MB ;;
1 million key/value pairs 300MB
C:\test>p1 Perl> # 5.6MB ;; Perl> $h{ pack 'V3', ($_) x 3} = pack 'V10', ($_) x 10 for 1e6 .. 2e6; +; Perl> # 237MB ;;
Voila! You've stored the same information and saved 1/5th of the space.
If the numbers can be stored as shorts or bytes, you can save even more.
I'm also having trouble reconciling your OP mention of a 3GB hash with the description of key/value sizes and total numbers above?
This creates a 3 million key/value pair hash with 21-byte keys and 80-byte values and the total memory requirement is <1GB:
Perl> $h{ "$_ " x 3} = "$_ " x 10 for 1e6 .. 4e6;; Perl> # 912MB ;;
|
|---|