Is there a method faster in performance than doing this:
var value = 2432;
if (value >= 20 && value <= 31) return true;
else if (value >= 45 && value <= 47) return true;
else if (value >= 82 && value <= 86) return true;
...
else if (value >= 1052 && value <= 1065) return true;
else if (value >= 2400 && value <= 2500) return true;
The conditional statements contain numbers that aren't in a pattern. The numbers go up to 65,000. Also the ranges are variable and don't intersect each other. The range is stored in a SQL database:
columns: from, to
rows: [21, 59], [92, 280], etc...
I was initially thinking of creating a lookup table containing all the numbers between the ranges (e.g., [20, 21, 21, 23, ... 31, -> 45, 46 47]
).
Is there a better way?
So if ranges are unique and don't intersect with each other. The fastest way to check I see to be next algo:
start
value that is larger than your reference numberIf sorting is done on DB side, then this algo will be O(logN) that is fast enough.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With