This is a known problem in the literature. It's called a
stabbing query into line segments. The entries in datafile1
can be considered as line segments, while the entries in
datafile2 are the points you query with. So, if you are looking
for an efficient algorithm, you'd need to build a segment tree
(or an interval tree) from the data in datafile1, and perform
queries with the data in datafile2.
IIRC, you can build a segment tree in O (n log2 n) time, while
queries take O (log2 n + k) time. So, if you have N entries
in datafile1 and M entries in datafile2, your total running
time would be O ((N + M) log2 N + K), where K is the number
of matches. It might be that it's actually a factor of O (log N) less.
This surely beats the O (N * M) approach of trying to match
everything with everything.
Unfortunally, I don't think there's a module available that
implements segment trees.
Abigail
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.