in reply to searching a vector array
So you would have to create two arrays (e.g. @min and @max) holding respectively the lower and higher bounds of all intervals. Then:
Would give the coverage of $_[0]. Of course, it can be optimized further by sorting @min and @max beforehand and using dichotomy, which would get you an O(ln(X)).my $count = 0; foreach $min (@min) { $count++ if ($_[0] >= $min) } foreach $max (@max) { $count-- if ($_[0] > $max) } return $count;
|
|---|