Kind, Gentle Folk,

I have a need to sort a bunch of geometric boxes in two ways, and I'm not sure how to do it in perl efficiently. Here are the starting conditions of this problem:-

1. I have a text string (the name of a box)

2. I have the lower left coordinates of a box

3. I have the upper right coordinates of a box

4. I have the area of a box

I have several million overlapping boxes within the area of one large, master box. Here is what I need to do:-

1. Sort all of the areas, from largest to smallest

2. Once the sort completes, I need the N largest boxes that do not overlap at all.

I am not looking for a detailed solution, just a rough idea on the best approach. Can someone help fill in these blanks?

%NetAreaHash = (); $LL = join (" ",$MinX,$MinY); #$MinX and $MinY are decimals $UR = join (" ",$MaxX,$MaxY); #$MaxX and $MaxY are decimals $Area = abs($MaxX - $MinX) * abs($MaxY - $MinY); $NetAreaHash{$Area} = join (" ",$NetName,$LL,$UR,$Area); #$NetName is +a string #how do I numerically sort $NetAreaHash by $Area? #how do I take the sorted $NetAreaHash and identify the N largest area +s that do not overlap? N will usually be 2, 4 or 8.

Again, I'm just looking for some guidance here. The numerical sort of the hash probably won't be that tough, but identifying the N largest, non-overlapping boxes has me stumped at the moment!

Thanks,

Fiddler42


In reply to Sorting hashes... by fiddler42

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.