<commit_before>/** @flow */

/**
 * Just-in-time calculates and caches size and position information for a collection of cells.
 */
export default class CellSizeAndPositionManager {
  constructor ({
    cellCount,
    cellSizeGetter,
    estimatedCellSize
  }: CellSizeAndPositionManagerConstructorParams) {
    this._cellSizeGetter = cellSizeGetter
    this._cellCount = cellCount
    this._estimatedCellSize = estimatedCellSize

    // Cache of size and position data for cells, mapped by cell index.
    // Note that invalid values may exist in this map so only rely on cells up to this._lastMeasuredIndex
    this._cellSizeAndPositionData = {}

    // Measurements for cells up to this index can be trusted; cells afterward should be estimated.
    this._lastMeasuredIndex = -1
  }

  configure ({
    cellCount,
    estimatedCellSize
  }: ConfigureParams): void {
    this._cellCount = cellCount
    this._estimatedCellSize = estimatedCellSize
  }

  /**
   * Searches for the cell (index) nearest the specified offset.
   *
   * If no exact match is found the next lowest cell index will be returned.
   * This allows partially visible cells (with offsets just before/above the fold) to be visible.
   */
  findNearestCell (offset: number): number {
    if (Number.isNaN(offset)) {
      throw Error(`Invalid offset ${offset} specified`)
    }

    // Our search algorithms find the nearest match at or below the specified offset.
    // So make sure the offset is at least 0 or no match will be found.
    offset = Math.max(0, offset)

    const lastMeasuredCellSizeAndPosition = this.getSizeAndPositionOfLastMeasuredCell()
    const lastMeasuredIndex = Math.max(0, this._lastMeasuredIndex)

    if (lastMeasuredCellSizeAndPosition.offset >= offset) {
      // If we've already measured cells within this range just use a binary search as it's faster.
      return this._binarySearch({
        high: lastMeasuredIndex,
        low: 0,
        offset
      })<commit_msg>Replace `Number.isNaN` call with `isNaN` call.<commit_after>/** @flow */

/**
 * Just-in-time calculates and caches size and position information for a collection of cells.
 */
export default class CellSizeAndPositionManager {
  constructor ({
    cellCount,
    cellSizeGetter,
    estimatedCellSize
  }: CellSizeAndPositionManagerConstructorParams) {
    this._cellSizeGetter = cellSizeGetter
    this._cellCount = cellCount
    this._estimatedCellSize = estimatedCellSize

    // Cache of size and position data for cells, mapped by cell index.
    // Note that invalid values may exist in this map so only rely on cells up to this._lastMeasuredIndex
    this._cellSizeAndPositionData = {}

    // Measurements for cells up to this index can be trusted; cells afterward should be estimated.
    this._lastMeasuredIndex = -1
  }

  configure ({
    cellCount,
    estimatedCellSize
  }: ConfigureParams): void {
    this._cellCount = cellCount
    this._estimatedCellSize = estimatedCellSize
  }

  /**
   * Searches for the cell (index) nearest the specified offset.
   *
   * If no exact match is found the next lowest cell index will be returned.
   * This allows partially visible cells (with offsets just before/above the fold) to be visible.
   */
  findNearestCell (offset: number): number {
    if (isNaN(offset)) {
      throw Error(`Invalid offset ${offset} specified`)
    }

    // Our search algorithms find the nearest match at or below the specified offset.
    // So make sure the offset is at least 0 or no match will be found.
    offset = Math.max(0, offset)

    const lastMeasuredCellSizeAndPosition = this.getSizeAndPositionOfLastMeasuredCell()
    const lastMeasuredIndex = Math.max(0, this._lastMeasuredIndex)

    if (lastMeasuredCellSizeAndPosition.offset >= offset) {
      // If we've already measured cells within this range just use a binary search as it's faster.
      return this._binarySearch({
        high: lastMeasuredIndex,
        low: 0,
        offset
      })
{'fraction_non_alphanumeric': 0.07261306532663317, 'fraction_numerical': 0.002512562814070352, 'mean_word_length': 3.2396166134185305, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2882780', 'n_tokens_mistral': 1088, 'n_tokens_neox': 1043, 'n_words': 401}