The demand is like this ...
if ( $foo > 0 && $foo < 100 ) $bar = 1;elseif ( $foo > 99 && $foo < 212 ) $bar = 2;elseif ( $foo > 211 && $foo < 324 ) $bar = 3;elseif ( $foo > 323 && $foo < 382 ) $bar = 4;elseif ( $foo > 381 && $foo < 465 ) $bar = 5;elseif ( $foo > 464 && $foo < 552 ) $bar = 6;# ...
There are thousands of such rules ... So the full screen is $foo > __ && $foo < __ $bar = __ ...
Efficiency and aesthetics are problematic ...
The value of the critical point is near random ... I can't think of a formula that can be extrapolated $bar by $foo ...
The current idea is to divide all the rules into two ... This can improve efficiency ... But aesthetics is still a problem ...
If it is sealed in a function ... It looks really beautiful ... But efficiency is worse than this ...
Is there a more perfect solution for both?
Additional... I wrote a scheme with array sorting ...
Efficiency and self-realization functions are almost ... Still less than two points ...
Reply content:
The demand is like this ...
if ( $foo > 0 && $foo < 100 ) $bar = 1;elseif ( $foo > 99 && $foo < 212 ) $bar = 2;elseif ( $foo > 211 && $foo < 324 ) $bar = 3;elseif ( $foo > 323 && $foo < 382 ) $bar = 4;elseif ( $foo > 381 && $foo < 465 ) $bar = 5;elseif ( $foo > 464 && $foo < 552 ) $bar = 6;# ...
There are thousands of such rules ... So the full screen is $foo > __ && $foo < __ $bar = __ ...
Efficiency and aesthetics are problematic ...
The value of the critical point is near random ... I can't think of a formula that can be extrapolated $bar by $foo ...
The current idea is to divide all the rules into two ... This can improve efficiency ... But aesthetics is still a problem ...
If it is sealed in a function ... It looks really beautiful ... But efficiency is worse than this ...
Is there a more perfect solution for both?
Additional... I wrote a scheme with array sorting ...
Efficiency and self-realization functions are almost ... Still less than two points ...
Assuming that your range is contiguous (in fact discontinuous and easy to implement), there is no overlap (this is OK), then by sorting the starting position of the range, it can be easily achieved by two points.
$ranges = array(1, 100, 212, 324, 382, 465, 552);
And then what you have to do is find a satisfaction in the ranges with a binary search a[i]
a[i] <= t && t < a[i+1]
.
P.S. Spit your range, I see a little schizophrenic.