Commit 3bad42ce authored by yann300's avatar yann300

round instead of floor

parent d0f0bd05
...@@ -85,6 +85,20 @@ module.exports = { ...@@ -85,6 +85,20 @@ module.exports = {
return index >= 0 ? array[index] : null return index >= 0 ? array[index] : null
}, },
/*
Binary Search:
Assumes that @arg array is sorted increasingly
return (saying middle=(array[i] + array[i + 1]) / 2 <= target) return i if target < middle; return i + 1 if target >= middle; return array.length - 1 if index > array.length; return null if array[0] > target || array is empty
*/
findLowerClosestBound: function (target, array) {
var index = this.findLowerBound(target, array)
if (index > array.length) {
return index
}
var middle = (array[index] + array[index + 1]) / 2
return target >= middle ? index + 1 : index
},
/** /**
* Find the call from @args rootCall which contains @args index (recursive) * Find the call from @args rootCall which contains @args index (recursive)
* *
......
...@@ -64,7 +64,7 @@ function StepManager (_parent, _traceManager) { ...@@ -64,7 +64,7 @@ function StepManager (_parent, _traceManager) {
StepManager.prototype.resolveToReducedTrace = function (value, incr) { StepManager.prototype.resolveToReducedTrace = function (value, incr) {
if (this.parent.callTree.reducedTrace.length) { if (this.parent.callTree.reducedTrace.length) {
var nextSource = utils.findLowerBound(value, this.parent.callTree.reducedTrace) var nextSource = utils.findLowerClosestBound(value, this.parent.callTree.reducedTrace)
nextSource = nextSource < this.parent.callTree.reducedTrace.length - 1 ? nextSource + incr : nextSource nextSource = nextSource < this.parent.callTree.reducedTrace.length - 1 ? nextSource + incr : nextSource
return this.parent.callTree.reducedTrace[nextSource] return this.parent.callTree.reducedTrace[nextSource]
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment