basic array bisect accessor implementation for #451
This commit is contained in:
Родитель
ad76418aee
Коммит
5f66b67c66
|
@ -201,13 +201,17 @@ function d3_zipLength(d) {
|
||||||
// The returned insertion point i partitions the array a into two halves so that
|
// The returned insertion point i partitions the array a into two halves so that
|
||||||
// all v < x for v in a[lo:i] for the left side and all v >= x for v in a[i:hi]
|
// all v < x for v in a[lo:i] for the left side and all v >= x for v in a[i:hi]
|
||||||
// for the right side.
|
// for the right side.
|
||||||
d3.bisectLeft = function(a, x, lo, hi) {
|
d3.bisectLeft = function(a, x, lo, hi, f) {
|
||||||
if (arguments.length < 3) lo = 0;
|
if (arguments.length < 3) lo = 0;
|
||||||
if (arguments.length < 4) hi = a.length;
|
if (arguments.length < 4) hi = a.length;
|
||||||
while (lo < hi) {
|
if (arguments.length < 5) while (lo < hi) {
|
||||||
var mid = (lo + hi) >> 1;
|
var mid = (lo + hi) >> 1;
|
||||||
if (a[mid] < x) lo = mid + 1;
|
if (a[mid] < x) lo = mid + 1;
|
||||||
else hi = mid;
|
else hi = mid;
|
||||||
|
} else while (lo < hi) {
|
||||||
|
var mid = (lo + hi) >> 1;
|
||||||
|
if (f.call(a, a[mid], mid) < x) lo = mid + 1;
|
||||||
|
else hi = mid;
|
||||||
}
|
}
|
||||||
return lo;
|
return lo;
|
||||||
};
|
};
|
||||||
|
@ -219,13 +223,17 @@ d3.bisectLeft = function(a, x, lo, hi) {
|
||||||
// all v <= x for v in a[lo:i] for the left side and all v > x for v in a[i:hi]
|
// all v <= x for v in a[lo:i] for the left side and all v > x for v in a[i:hi]
|
||||||
// for the right side.
|
// for the right side.
|
||||||
d3.bisect =
|
d3.bisect =
|
||||||
d3.bisectRight = function(a, x, lo, hi) {
|
d3.bisectRight = function(a, x, lo, hi, f) {
|
||||||
if (arguments.length < 3) lo = 0;
|
if (arguments.length < 3) lo = 0;
|
||||||
if (arguments.length < 4) hi = a.length;
|
if (arguments.length < 4) hi = a.length;
|
||||||
while (lo < hi) {
|
if (arguments.length < 5) while (lo < hi) {
|
||||||
var mid = (lo + hi) >> 1;
|
var mid = (lo + hi) >> 1;
|
||||||
if (x < a[mid]) hi = mid;
|
if (x < a[mid]) hi = mid;
|
||||||
else lo = mid + 1;
|
else lo = mid + 1;
|
||||||
|
} else while (lo < hi) {
|
||||||
|
var mid = (lo + hi) >> 1;
|
||||||
|
if (x < f.call(a, a[mid], mid)) hi = mid;
|
||||||
|
else lo = mid + 1;
|
||||||
}
|
}
|
||||||
return lo;
|
return lo;
|
||||||
};
|
};
|
||||||
|
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -8,13 +8,17 @@
|
||||||
// The returned insertion point i partitions the array a into two halves so that
|
// The returned insertion point i partitions the array a into two halves so that
|
||||||
// all v < x for v in a[lo:i] for the left side and all v >= x for v in a[i:hi]
|
// all v < x for v in a[lo:i] for the left side and all v >= x for v in a[i:hi]
|
||||||
// for the right side.
|
// for the right side.
|
||||||
d3.bisectLeft = function(a, x, lo, hi) {
|
d3.bisectLeft = function(a, x, lo, hi, f) {
|
||||||
if (arguments.length < 3) lo = 0;
|
if (arguments.length < 3) lo = 0;
|
||||||
if (arguments.length < 4) hi = a.length;
|
if (arguments.length < 4) hi = a.length;
|
||||||
while (lo < hi) {
|
if (arguments.length < 5) while (lo < hi) {
|
||||||
var mid = (lo + hi) >> 1;
|
var mid = (lo + hi) >> 1;
|
||||||
if (a[mid] < x) lo = mid + 1;
|
if (a[mid] < x) lo = mid + 1;
|
||||||
else hi = mid;
|
else hi = mid;
|
||||||
|
} else while (lo < hi) {
|
||||||
|
var mid = (lo + hi) >> 1;
|
||||||
|
if (f.call(a, a[mid], mid) < x) lo = mid + 1;
|
||||||
|
else hi = mid;
|
||||||
}
|
}
|
||||||
return lo;
|
return lo;
|
||||||
};
|
};
|
||||||
|
@ -26,13 +30,17 @@ d3.bisectLeft = function(a, x, lo, hi) {
|
||||||
// all v <= x for v in a[lo:i] for the left side and all v > x for v in a[i:hi]
|
// all v <= x for v in a[lo:i] for the left side and all v > x for v in a[i:hi]
|
||||||
// for the right side.
|
// for the right side.
|
||||||
d3.bisect =
|
d3.bisect =
|
||||||
d3.bisectRight = function(a, x, lo, hi) {
|
d3.bisectRight = function(a, x, lo, hi, f) {
|
||||||
if (arguments.length < 3) lo = 0;
|
if (arguments.length < 3) lo = 0;
|
||||||
if (arguments.length < 4) hi = a.length;
|
if (arguments.length < 4) hi = a.length;
|
||||||
while (lo < hi) {
|
if (arguments.length < 5) while (lo < hi) {
|
||||||
var mid = (lo + hi) >> 1;
|
var mid = (lo + hi) >> 1;
|
||||||
if (x < a[mid]) hi = mid;
|
if (x < a[mid]) hi = mid;
|
||||||
else lo = mid + 1;
|
else lo = mid + 1;
|
||||||
|
} else while (lo < hi) {
|
||||||
|
var mid = (lo + hi) >> 1;
|
||||||
|
if (x < f.call(a, a[mid], mid)) hi = mid;
|
||||||
|
else lo = mid + 1;
|
||||||
}
|
}
|
||||||
return lo;
|
return lo;
|
||||||
};
|
};
|
||||||
|
|
Загрузка…
Ссылка в новой задаче