Given a sorted array of chunks, returns the index of the first chunk in the
array that overlaps with a specified window.

@param chunks
@param windowStartIndex
@param windowEndIndex

@returns {number}
336108
function findFirstOverlappingChunk(chunks, windowStartIndex, windowEndIndex)
{
  var helper = function(chunks,
                        chunkIndexLeft,
                        chunkIndexRight,
                        windowStartIndex,
                        windowEndIndex)
  {
    var result;
    var chunkIndexMiddle;
    var middleChunk;
    var middleChunkEndIndex;

    // initialize the return value to -1
    result = -1;

    // compute the index of the middle chunk and get the middle chunk
    chunkIndexMiddle = Math.floor((chunkIndexLeft + chunkIndexRight) / 2);
    middleChunk = chunks[chunkIndexMiddle];

    // if we have two or fewer chunks
    if ((chunkIndexMiddle === chunkIndexLeft) ||
        (chunkIndexMiddle === chunkIndexRight))
    {
      // if we have just one chunk, and it overlaps with the specified window,
      // we've found the chunk we were looking for
      if (chunkIndexLeft === chunkIndexRight)
      {
        if (middleChunk.overlapsWithWindow(windowStartIndex, windowEndIndex))
        {
          result = chunkIndexLeft;
        }
      }
      else // we just have two chunks left to check
      {
        // if the first chunk overlaps with the specified window, that's the
        // chunk we were looking for
        if (chunks[chunkIndexLeft].overlapsWithWindow(
                windowStartIndex, windowEndIndex))
        {
          result = chunkIndexLeft;
        }

        // otherwise, if the second chunk overlaps with the specified window,
        // that's the chunk we were looking for
        else if (chunks[chunkIndexRight].overlapsWithWindow(
                windowStartIndex, windowEndIndex))
        {
          result = chunkIndexRight;
        }
      }

      return result;
    }

    // if the middle chunk does not overlap with the specified window
    if (!middleChunk.overlapsWithWindow(windowStartIndex, windowEndIndex))
    {
      middleChunkEndIndex = middleChunk.getEndIndex();

      // if the window is to the right of the middle chunk,
      // recurse on the right half
      if (windowStartIndex > middleChunkEndIndex)
      {
        return helper(
            chunks,
            chunkIndexMiddle,
            chunkIndexRight,
            windowStartIndex,
            windowEndIndex);
      }
      else
      {
        // recurse on the left half
        return helper(
            chunks,
            chunkIndexLeft,
            chunkIndexMiddle,
            windowStartIndex,
            windowEndIndex);
      }
    }
    else
    {
      // if the middle chunk overlaps but the chunk before it does not, the
      // middle chunk is the one we were looking
      if ((chunkIndexMiddle === 0) ||
          !chunks[chunkIndexMiddle - 1].overlapsWithWindow(
              windowStartIndex, windowEndIndex))
      {
        return chunkIndexMiddle;
      }
      else
      {
        // recurse on the left half
        return helper(
            chunks,
            chunkIndexLeft,
            chunkIndexMiddle,
            windowStartIndex,
            windowEndIndex);
      }
    }
  };

  return helper(chunks, 0, chunks.length - 1, windowStartIndex, windowEndIndex);
}
681848
function(chunk)
  {
    // get all the rows in the current chunk that overlap with the requested
    // window
    var chunkStart = chunk.getStartIndex();
    var chunkEnd   = chunk.getEndIndex();
    var rows       = chunk.getRows().slice(
        Math.max(chunkStart, start) - chunkStart,
        Math.min(chunkEnd, end) + 1 - chunkStart);

    var rowIndex = 0;
    var rowsLength = rows.length;

    // create a function that can be called to batch-process rows
    var processRows = function()
    {
      // get the start position and start time
      var startIndex = rowIndex;
      var startTime  = Date.now();

      var each = options.each;
      while (rowIndex < rowsLength)
      {
        // invoke the each() callback on the current row
        var ret = each(rows[rowIndex++]);

        context.numRowsProcessed++;

        // if the callback returned false, stop processing rows
        if (ret === false)
        {
          var stoppedProcessingRows = true;
          break;
        }

        // use the current position and current time to check if we've been
        // processing rows for too long; if so, leave the rest for the next
        // tick of the event loop
        if ((rowIndex - startIndex) >= context.rowBatchSize &&
            (Date.now() - startTime) > context.rowBatchDuration)
        {
          process.nextTick(processRows);
          break;
        }
      }

      // if there are no more rows for us to process in this chunk
      if (!(rowIndex < rowsLength) || stoppedProcessingRows)
      {
        // if we exhausted all the rows in this chunk and we haven't yet
        // processed all the rows we want to process, ask the result stream to
        // do another read
        if (!(rowIndex < rowsLength) &&
            context.numRowsProcessed !== context.maxNumRowsToProcess)
        {
          resultStream.read();
        }
        else
        {
          // we've either processed all the rows we wanted to process or we
          // were told to stop processing rows by the each() callback; either
          // way, close the result stream to complete the operation
          resultStream.asyncClose();
        }
      }
    };

    // start processing rows
    processRows();
  }
47207
public static INDArrayIndex interval(int begin, int stride, int end, boolean inclusive) {
        Preconditions.checkArgument(begin <= end, "Beginning index (%s) in range must be less than or equal to end (%s)", begin, end);
        INDArrayIndex index = new IntervalIndex(inclusive, stride);
        index.init(begin, end);
        return index;
    }
781267
function findLastCommonIndex(xs, ys) {
    for (let i = Math.min(xs.length, ys.length) - 1; i >= 0; --i) {
        if (xs[i] === ys[i]) {
            return i
        }
    }
    return -1
}
321486
function onResultStreamData(chunk)
  {
    // unsubscribe from the result stream's 'data' and 'close' events
    resultStream.removeListener('data', onResultStreamData);
    resultStream.removeListener('close', onResultStreamClose);

    // get all the rows in the chunk that overlap with the requested window,
    // and use the resulting array as the new row buffer
    var chunkStart = chunk.getStartIndex();
    var chunkEnd = chunk.getEndIndex();
    rowBuffer = chunk.getRows().slice(
        Math.max(chunkStart, start) - chunkStart,
        Math.min(chunkEnd, end) + 1 - chunkStart);

    // reset the row index
    rowIndex = 0;

    // process the row buffer
    processRowBuffer();
  }
1112314
@Override public long indexOf(byte b, long fromIndex) {
    if (fromIndex < 0) throw new IllegalArgumentException("fromIndex < 0");

    Segment s = head;
    if (s == null) return -1L;
    long offset = 0L;
    do {
      int segmentByteCount = s.limit - s.pos;
      if (fromIndex >= segmentByteCount) {
        fromIndex -= segmentByteCount;
      } else {
        byte[] data = s.data;
        for (int pos = (int) (s.pos + fromIndex), limit = s.limit; pos < limit; pos++) {
          if (data[pos] == b) return offset + pos - s.pos;
        }
        fromIndex = 0;
      }
      offset += segmentByteCount;
      s = s.next;
    } while (s != head);
    return -1L;
  }
657382
private int nextTopLevelArgStart(int partIndex) {
        if (partIndex != 0) {
            partIndex = msgPattern.getLimitPartIndex(partIndex);
        }
        for (;;) {
            MessagePattern.Part.Type type = msgPattern.getPartType(++partIndex);
            if (type == MessagePattern.Part.Type.ARG_START) {
                return partIndex;
            }
            if (type == MessagePattern.Part.Type.MSG_LIMIT) {
                return -1;
            }
        }
    }
935867
function findTokenIndex(tokens, offset) {
  var min = 0;
  var max = tokens.length - 1;

  while (min <= max) {
    var ptr = (min + max) / 2 | 0;
    var token = tokens[ptr];
    if (token.end <= offset) {
      min = ptr + 1;
    } else if (token.start > offset) {
      max = ptr - 1;
    } else {
      return ptr;
    }
  }

  return ptr;
}
320306
public int indexOf(byte[] srcBytes, byte[] searchBytes, int startIndex) {
		final int endIndex = srcBytes.length - 1;
		return indexOf(srcBytes, searchBytes, startIndex, endIndex);
	}
59691
public int loadIndeces(List<RowIndexEntry> rowIndexEntries, int startIndex) {
    int updatedStartIndex = input.loadIndeces(rowIndexEntries, startIndex);

    int numIndeces = rowIndexEntries.size();
    indeces = new int[numIndeces + 1];
    int i = 0;
    for (RowIndexEntry rowIndexEntry : rowIndexEntries) {
      indeces[i] = (int) rowIndexEntry.getPositions(updatedStartIndex);
      i++;
    }
    return updatedStartIndex + 1;
  }
1039886
public static int indexOf(ByteBuf buffer, int fromIndex, int toIndex, byte value) {
        if (fromIndex <= toIndex) {
            return firstIndexOf(buffer, fromIndex, toIndex, value);
        } else {
            return lastIndexOf(buffer, fromIndex, toIndex, value);
        }
    }
768655
function segmentNew(start, end){
		return {
			id: buildLog ? buildLog.segmentId() : -1,
			start: start,
			end: end,
			myFill: {
				above: null, // is there fill above us?
				below: null  // is there fill below us?
			},
			otherFill: null
		};
	}
348612
def rolling_window(a, axis, window, center, fill_value):
    
    orig_shape = a.shape
    if axis < 0:
        axis = a.ndim + axis
    depth = {d: 0 for d in range(a.ndim)}
    depth[axis] = int(window / 2)
    # For evenly sized window, we need to crop the first point of each block.
    offset = 1 if window % 2 == 0 else 0

    if depth[axis] > min(a.chunks[axis]):
        raise ValueError(
            "For window size %d, every chunk should be larger than %d, "
            "but the smallest chunk size is %d. Rechunk your array\n"
            "with a larger chunk size or a chunk size that\n"
            "more evenly divides the shape of your array." %
            (window, depth[axis], min(a.chunks[axis])))

    # Although dask.overlap pads values to boundaries of the array,
    # the size of the generated array is smaller than what we want
    # if center == False.
    if center:
        start = int(window / 2)  # 10 -> 5,  9 -> 4
        end = window - 1 - start
    else:
        start, end = window - 1, 0
    pad_size = max(start, end) + offset - depth[axis]
    drop_size = 0
    # pad_size becomes more than 0 when the overlapped array is smaller than
    # needed. In this case, we need to enlarge the original array by padding
    # before overlapping.
    if pad_size > 0:
        if pad_size < depth[axis]:
            # overlapping requires each chunk larger than depth. If pad_size is
            # smaller than the depth, we enlarge this and truncate it later.
            drop_size = depth[axis] - pad_size
            pad_size = depth[axis]
        shape = list(a.shape)
        shape[axis] = pad_size
        chunks = list(a.chunks)
        chunks[axis] = (pad_size, )
        fill_array = da.full(shape, fill_value, dtype=a.dtype, chunks=chunks)
        a = da.concatenate([fill_array, a], axis=axis)

    boundary = {d: fill_value for d in range(a.ndim)}

    # create overlap arrays
    ag = overlap(a, depth=depth, boundary=boundary)

    # apply rolling func
    def func(x, window, axis=-1):
        x = np.asarray(x)
        rolling = nputils._rolling_window(x, window, axis)
        return rolling[(slice(None), ) * axis + (slice(offset, None), )]

    chunks = list(a.chunks)
    chunks.append(window)
    out = ag.map_blocks(func, dtype=a.dtype, new_axis=a.ndim, chunks=chunks,
                        window=window, axis=axis)

    # crop boundary.
    index = (slice(None),) * axis + (slice(drop_size,
                                           drop_size + orig_shape[axis]), )
    return out[index]
1359276
function getNumElementsFromNonIndexedArrays(arrays) {
    var key = Object.keys(arrays)[0];
    var array = arrays[key];
    if (isArrayBuffer(array)) {
      return array.numElements;
    } else {
      return array.data.length / array.numComponents;
    }
  }
313909
function (start, end) {
    var offsetStart;
    var offsetEnd;

    loadBufferIfRequired(start, end);

    offsetStart = start - currentRange.start;
    offsetEnd = offsetStart + (end - start);

    return buffer.slice(offsetStart, offsetEnd);
  }
1289731
@Override
  public void part(int start, int end) {
    blockNumbers[count][0] = start;
    blockNumbers[count][1] = end - 1;
    count++;
  }
1275853
function getSparseArrayIndexes(arr, fromIndex, loop, fromRight) {
  var indexes = [], i;
  for (i in arr) {
    // istanbul ignore next
    if (isArrayIndex(i) && (loop || (fromRight ? i <= fromIndex : i >= fromIndex))) {
      indexes.push(+i);
    }
  }
  indexes.sort(function(a, b) {
    var aLoop = a > fromIndex;
    var bLoop = b > fromIndex;
    // This block cannot be reached unless ES5 methods are being shimmed.
    // istanbul ignore if
    if (aLoop !== bLoop) {
      return aLoop ? -1 : 1;
    }
    return a - b;
  });
  return indexes;
}