diff --git a/src/helpers/util.js b/src/helpers/util.js index 60ee806f15..89e1af92bb 100644 --- a/src/helpers/util.js +++ b/src/helpers/util.js @@ -85,6 +85,20 @@ module.exports = { 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) * diff --git a/src/ui/StepManager.js b/src/ui/StepManager.js index 8faaaf488b..cc7cdc4357 100644 --- a/src/ui/StepManager.js +++ b/src/ui/StepManager.js @@ -64,7 +64,7 @@ function StepManager (_parent, _traceManager) { StepManager.prototype.resolveToReducedTrace = function (value, incr) { 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 return this.parent.callTree.reducedTrace[nextSource] }