findMarker = (yarray, index) => {
  if (yarray._start === null || index === 0 || yarray._searchMarker === null) {
    return null;
  }

  const marker = yarray._searchMarker.length === 0 ? null : yarray._searchMarker.reduce((a, b) => math.abs(index - a.index) < math.abs(index - b.index) ? a : b);
  let p = yarray._start;
  let pindex = 0;

  if (marker !== null) {
    p = marker.p;
    pindex = marker.index;
    refreshMarkerTimestamp(marker); // we used it, we might need to use it again
  } // iterate to right if possible


  while (p.right !== null && pindex < index) {
    if (!p.deleted && p.countable) {
      if (index < pindex + p.length) {
        break;
      }

      pindex += p.length;
    }

    p = p.right;
  } // iterate to left if necessary (might be that pindex > index)


  while (p.left !== null && pindex > index) {
    p = p.left;

    if (!p.deleted && p.countable) {
      pindex -= p.length;
    }
  } // we want to make sure that p can't be merged with left, because that would screw up everything
  // in that cas just return what we have (it is most likely the best marker anyway)
  // iterate to left until p can't be merged with left


  while (p.left !== null && p.left.id.client === p.id.client && p.left.id.clock + p.left.length === p.id.clock) {
    p = p.left;

    if (!p.deleted && p.countable) {
      pindex -= p.length;
    }
  } // @todo remove!
  // assure position
  // {
  //   let start = yarray._start
  //   let pos = 0
  //   while (start !== p) {
  //     if (!start.deleted && start.countable) {
  //       pos += start.length
  //     }
  //     start = /** @type {Item} */ (start.right)
  //   }
  //   if (pos !== pindex) {
  //     debugger
  //     throw new Error('Gotcha position fail!')
  //   }
  // }
  // if (marker) {
  //   if (window.lengthes == null) {
  //     window.lengthes = []
  //     window.getLengthes = () => window.lengthes.sort((a, b) => a - b)
  //   }
  //   window.lengthes.push(marker.index - pindex)
  //   console.log('distance', marker.index - pindex, 'len', p && p.parent.length)
  // }


  if (marker !== null && math.abs(marker.index - pindex) <
  /** @type {YText|YArray<any>} */
  p.parent.length / maxSearchMarker) {
    // adjust existing marker
    overwriteMarker(marker, p, pindex);
    return marker;
  } else {
    // create new marker
    return markPosition(yarray._searchMarker, p, pindex);
  }
}
Search marker help us to find positions in the associative array faster.

They speed up the process of finding a position without much bookkeeping.

A maximum of `maxSearchMarker` objects are created.

This function always returns a refreshed marker (updated timestamp)

@param {AbstractType<any>} yarray
@param {number} index