Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Just for completeness an approach for the unsorted case.¹

/foo/bar/baz/123 aaa /foo/bar/baz/123 aab /foo/bar/baz/123 aac /foo/bar/baz/124 aaa /foo/bar/baz/124 aab

You could still be able to profit from automated swapping of unused data-structures by using more hierarchies of hashes and splitting the paths at '/'.

For instance $duplicates{foo}{bar}{baz}{123}++ would only involve some comparatively small hashes kept in memory.

The drawback would be that swapping to HD costs time! That's why you should try to minimize swapping by concentrating on only some hashes currently loaded.

That means you would need multiple runs scanning your file, while you concentrate on a part of "unfinished" hashes (e.g. all path starting with /foo/bar and so on)

I think always loading 1 million lines into memory (i.e. an array) and scanning them in multiple runs could lead to a balanced mix of time and memory complexity.

And already scanned elements could be marked by delete $arr[$index]

Cheers Rolf

( addicted to the Perl Programming Language)

UPDATE

¹) I just realised that using multiple hash-levels elegantly solves the case of sorted input. You won't need multiple runs, the sorted input will effectively minimize the amount of swapped hashes.


In reply to Re: Large file, multi dimensional hash - out of memory (swapping) by LanX
in thread Large file, multi dimensional hash - out of memory by Anonymous Monk

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 cooling their heels in the Monastery: (4)
As of 2024-04-24 20:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found