function _rangeSearch()

in src/lib/intervalTree.js [193:231]


function _rangeSearch(start, end, arr) {
  if (end - start <= 0) {
    throw new Error('end must be greater than start. start: ' + start + ', end: ' + end);
  }
  var resultHash = {};

  var wholeWraps = [];
  _pointSearch.call(this, this.root, (start + end) >> 1, wholeWraps, true);

  wholeWraps.forEach(function(result) {
    resultHash[result.id] = true;
  });


  var idx1 = this.pointTree.bsearch([start, null]);
  var pointTreeArray = this.pointTree;
  while (idx1 >= 0 && pointTreeArray[idx1][0] == start) {
    idx1--;
  }

  var idx2 = this.pointTree.bsearch([end,   null]);
  if (idx2 >= 0)
  {
    var len = pointTreeArray.length -1;
    while (idx2 <= len && pointTreeArray[idx2][0] <= end) {
      idx2++;
    }

    pointTreeArray.slice(idx1 + 1, idx2).forEach(function(point) {
      var id = point[1];
      resultHash[id] = true;
    }, this);

    Object.keys(resultHash).forEach(function(id) {
      var itvl = this.intervalHash[id];
      arr.push(itvl.result(start, end));
    }, this);
  }
}