function SortedIndex() {
    let index = array32(0),
      value = [],
      size = 0;
    function insert(key, data, base) {
      if (!data.length) return [];
      const n0 = size,
        n1 = data.length,
        addi = array32(n1);
      let addv = Array(n1),
        oldv,
        oldi,
        i;
      for (i = 0; i < n1; ++i) {
        addv[i] = key(data[i]);
        addi[i] = i;
      }
      addv = sort$1(addv, addi);
      if (n0) {
        oldv = value;
        oldi = index;
        value = Array(n0 + n1);
        index = array32(n0 + n1);
        merge$1(base, oldv, oldi, n0, addv, addi, n1, value, index);
      } else {
        if (base > 0) for (i = 0; i < n1; ++i) {
          addi[i] += base;
        }
        value = addv;
        index = addi;
      }
      size = n0 + n1;
      return {
        index: addi,
        value: addv
      };
    }
    function remove(num, map) {
      // map: index -> remove
      const n = size;
      let idx, i, j;

      // seek forward to first removal
      for (i = 0; !map[index[i]] && i < n; ++i);

      // condense index and value arrays
      for (j = i; i < n; ++i) {
        if (!map[idx = index[i]]) {
          index[j] = idx;
          value[j] = value[i];
          ++j;
        }
      }
      size = n - num;
    }
    function reindex(map) {
      for (let i = 0, n = size; i < n; ++i) {
        index[i] = map[index[i]];
      }
    }
    function bisect(range, array) {
      let n;
      if (array) {
        n = array.length;
      } else {
        array = value;
        n = size;
      }
      return [d3Array.bisectLeft(array, range[0], 0, n), d3Array.bisectRight(array, range[1], 0, n)];
    }
    return {
      insert: insert,
      remove: remove,
      bisect: bisect,
      reindex: reindex,
      index: () => index,
      size: () => size
    };
  }
Maintains a list of values, sorted by key.