For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > October 2004 > how to search for intervals in multiple columns?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author how to search for intervals in multiple columns?
Martin A. Hansen

2004-10-28, 3:57 pm

hi

i have a dataset consisting of an array of arrays.

$data = [
[q_beg1, q_end1, s_beg1, s_end1]
[q_beg2, q_end2, s_beg2, s_end2]
[q_beg3, q_end3, s_beg3, s_end3]
...
]

q_beg, q_end, s_beg, s_end are all integers.


now, i would like to find all rows where q_beg and q_end are within one
interval (int1_beg, int1_end) while s_beg and s_end are within another
interval (int2_beg, int2_end).

this can be done with grep:

grep {$_->[0] < int1_beg and $_->[1] > int1_end and
$_->[2] < int2_beg and $_->[3] > int2_end} @$data;


however, this is too slow for my purpose. so how to speed up such
selection?

the query would be simple enough in a relational database, however i
want to avoid using a database using tables on disk.

i should think this was a pretty generic problem.


ideas are most welcome !


best regards


martin
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com