Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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.

  1. In this one the keys are strings containing 3 x 7 digit integers; and the values are 10 x 7 digits integers delimited by spaces:
    C:\test>p1 Perl> #5.6MB ;; Perl> $h{ "$_ " x 3} = "$_ " x 10 for 1e6 .. 2e6;; Perl> # 299MB ;;

    1 million key/value pairs 300MB

  2. Same thing, but packing the integers to 4-byte binary values:
    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 ;;

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^3: Small Hash a Gateway to Large Hash? by BrowserUk
in thread Small Hash a Gateway to Large Hash? by lsherwood

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-24 09:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found