I have a big number of SortedSet<Long> structures:
1, 2, 5, 8, 10, 35, 77, ...
5, 9, 35, 50, 132, ...
2, 4, 8, 15, 17, 23, ...
... hundreds of thousands of such rows...
I need to find a number that goes after, say, 50. In this example (if there are just three sets) it is 77. The number of sets is huge – hundreds of thousands. What algorithm would you suggest?
If I understand correctly here is my idea:
Here is the idea:
UPDATE (based on @beerbajay comment): if SortedSet is actually a
TreeSet, the following code might perform better. Also I am making sure that there is any value greater than 50 in each and every set: