Permalink
Browse files

Merge branch 'bisect-large' of git://github.com/jasondavies/d3 into 2…

….9.7
  • Loading branch information...
2 parents cb832c1 + 65a4645 commit ea48a4a5af7d9822210dfb12fbef79bcb947de5e @mbostock mbostock committed Jul 31, 2012
Showing with 71 additions and 5 deletions.
  1. +2 −2 d3.v2.js
  2. +1 −1 d3.v2.min.js
  3. +2 −2 src/core/bisect.js
  4. +66 −0 test/core/bisect-test.js
View
4 d3.v2.js
@@ -234,7 +234,7 @@
if (arguments.length < 3) lo = 0;
if (arguments.length < 4) hi = a.length;
while (lo < hi) {
- var mid = lo + hi >> 1;
+ var mid = lo + hi >>> 1;
if (f.call(a, a[mid], mid) < x) lo = mid + 1; else hi = mid;
}
return lo;
@@ -243,7 +243,7 @@
if (arguments.length < 3) lo = 0;
if (arguments.length < 4) hi = a.length;
while (lo < hi) {
- var mid = lo + hi >> 1;
+ var mid = lo + hi >>> 1;
if (x < f.call(a, a[mid], mid)) hi = mid; else lo = mid + 1;
}
return lo;
View
2 d3.v2.min.js
1 addition, 1 deletion not shown because the diff is too large. Please use a local Git client to view these changes.
View
4 src/core/bisect.js
@@ -4,7 +4,7 @@ d3.bisector = function(f) {
if (arguments.length < 3) lo = 0;
if (arguments.length < 4) hi = a.length;
while (lo < hi) {
- var mid = lo + hi >> 1;
+ var mid = lo + hi >>> 1;
if (f.call(a, a[mid], mid) < x) lo = mid + 1;
else hi = mid;
}
@@ -14,7 +14,7 @@ d3.bisector = function(f) {
if (arguments.length < 3) lo = 0;
if (arguments.length < 4) hi = a.length;
while (lo < hi) {
- var mid = lo + hi >> 1;
+ var mid = lo + hi >>> 1;
if (x < f.call(a, a[mid], mid)) hi = mid;
else lo = mid + 1;
}
View
66 test/core/bisect-test.js
@@ -5,6 +5,8 @@ var vows = require("vows"),
var suite = vows.describe("d3.bisect");
+var i30 = 1 << 30;
+
suite.addBatch({
"bisectLeft": {
topic: function() {
@@ -48,6 +50,22 @@ suite.addBatch({
assert.equal(bisect(array, 4, 2, 3), 3);
assert.equal(bisect(array, 5, 2, 3), 3);
assert.equal(bisect(array, 6, 2, 3), 3);
+ },
+ "large arrays": function(bisect) {
+ var array = [],
+ i = i30;
+ array[i++] = 1;
+ array[i++] = 2;
+ array[i++] = 3;
+ array[i++] = 4;
+ array[i++] = 5;
+ assert.equal(bisect(array, 0, i - 5, i), i - 5);
+ assert.equal(bisect(array, 1, i - 5, i), i - 5);
+ assert.equal(bisect(array, 2, i - 5, i), i - 4);
+ assert.equal(bisect(array, 3, i - 5, i), i - 3);
+ assert.equal(bisect(array, 4, i - 5, i), i - 2);
+ assert.equal(bisect(array, 5, i - 5, i), i - 1);
+ assert.equal(bisect(array, 6, i - 5, i), i - 0);
}
}
});
@@ -95,6 +113,22 @@ suite.addBatch({
assert.equal(bisect(array, 4, 2, 3), 3);
assert.equal(bisect(array, 5, 2, 3), 3);
assert.equal(bisect(array, 6, 2, 3), 3);
+ },
+ "large arrays": function(bisect) {
+ var array = [],
+ i = i30;
+ array[i++] = 1;
+ array[i++] = 2;
+ array[i++] = 3;
+ array[i++] = 4;
+ array[i++] = 5;
+ assert.equal(bisect(array, 0, i - 5, i), i - 5);
+ assert.equal(bisect(array, 1, i - 5, i), i - 4);
+ assert.equal(bisect(array, 2, i - 5, i), i - 3);
+ assert.equal(bisect(array, 3, i - 5, i), i - 2);
+ assert.equal(bisect(array, 4, i - 5, i), i - 1);
+ assert.equal(bisect(array, 5, i - 5, i), i - 0);
+ assert.equal(bisect(array, 6, i - 5, i), i - 0);
}
}
});
@@ -146,6 +180,22 @@ suite.addBatch({
assert.equal(bisect(array, 4, 2, 3), 3);
assert.equal(bisect(array, 5, 2, 3), 3);
assert.equal(bisect(array, 6, 2, 3), 3);
+ },
+ "large arrays": function(bisect) {
+ var array = [],
+ i = i30;
+ array[i++] = {key: 1};
+ array[i++] = {key: 2};
+ array[i++] = {key: 3};
+ array[i++] = {key: 4};
+ array[i++] = {key: 5};
+ assert.equal(bisect(array, 0, i - 5, i), i - 5);
+ assert.equal(bisect(array, 1, i - 5, i), i - 5);
+ assert.equal(bisect(array, 2, i - 5, i), i - 4);
+ assert.equal(bisect(array, 3, i - 5, i), i - 3);
+ assert.equal(bisect(array, 4, i - 5, i), i - 2);
+ assert.equal(bisect(array, 5, i - 5, i), i - 1);
+ assert.equal(bisect(array, 6, i - 5, i), i - 0);
}
},
"right": {
@@ -190,6 +240,22 @@ suite.addBatch({
assert.equal(bisect(array, 4, 2, 3), 3);
assert.equal(bisect(array, 5, 2, 3), 3);
assert.equal(bisect(array, 6, 2, 3), 3);
+ },
+ "large arrays": function(bisect) {
+ var array = [],
+ i = i30;
+ array[i++] = {key: 1};
+ array[i++] = {key: 2};
+ array[i++] = {key: 3};
+ array[i++] = {key: 4};
+ array[i++] = {key: 5};
+ assert.equal(bisect(array, 0, i - 5, i), i - 5);
+ assert.equal(bisect(array, 1, i - 5, i), i - 4);
+ assert.equal(bisect(array, 2, i - 5, i), i - 3);
+ assert.equal(bisect(array, 3, i - 5, i), i - 2);
+ assert.equal(bisect(array, 4, i - 5, i), i - 1);
+ assert.equal(bisect(array, 5, i - 5, i), i - 0);
+ assert.equal(bisect(array, 6, i - 5, i), i - 0);
}
}
}

0 comments on commit ea48a4a

Please sign in to comment.