I am having a problem finding all overlapping ranges in two lists efficiently.
This problem is similar to This question, but with different inputs.
I have 2 input files, one that contains many lines of range and data pairs, and another that contains a list of ranges to find the intersections to.
I already wrote a file reader class that reads from the data file, returning objects, one at a time, that hold a list of range and data pairs, but am running into trouble when I try to find the overlaps of the two range lists.
Currently what I am doing is brute forcing it, comparing every range in the data list to every other range in the intersection list, but because the data file is very large, it is taking a long time.
Sample Objects:
This is the object in the data list:
public DataModel {
private int start; {set; get;}
private int end; {set; get;}
//Other Data
}
The range Model is just a list of paired integers (start, end).
while (fileParser.hasNext()) {
dataList = fileParser.next();
for (DataModel data : dataList)
for (RangeModel range : rangeList)
if(overlaps(data, range))
print(range.getString + " " + data.getString);
}
Edit for clarity:
The DataModel is given in smaller packets of similar ranges of varying length, but they are mostly under 20, so the comparison will be run repeatedly on the same RangeModel and each new DataModel. The total ranges in all the data is around 2 billion, but it doesn't really matter. Thanks for the help.