<commit_before>class FibInterval
  attr_reader :holding_capacity, :fibs

  HOLDING_CAPACITY_MIN = 4

  def initialize(holding_capacity)
    raise TypeError unless holding_capacity.is_a? Integer
    if holding_capacity < HOLDING_CAPACITY_MIN
      raise "holding_capacity >= #{HOLDING_CAPACITY_MIN}"
    end
    @holding_capacity = holding_capacity
    @holding_capacity.freeze
    @intervals_capacity = holding_capacity - 1
    @intervals_capacity.freeze
    @fibs = generate_fibs(holding_capacity)
    @fibs.freeze
  end

  def indexes_to_delete(intervals)
    raise ArgumentError unless valid_intervals? intervals
    ivals = intervals.dup
    result = []
    # while ivals.size >= @holding_capacity
    #   idx = get_index(ivals)
    #   break if idx.nil?
    #   result << idx
    #   virtual_delete(ivals, idx)
    # end
    result
  end

  alias indices_to_delete indexes_to_delete

  private
  def generate_fibs(n) # [1, 2, 3, 5, 8, 13, 21, ...]
    ary = []
    x,y = 1,1
    n.times { ary << y; x, y = y, x+y }
    ary
  end

  def valid_intervals?(intervals)
    return false unless intervals.is_a? Array
    prev = nil
    intervals.each { |x|
      return false unless x.is_a? Integer
      return false if x < 0
      return false if prev && (prev < x)
      prev = x
    }
    true
  end

  def get_index(intervals)
    return nil if intervals.size < @intervals_capacity

    i = intervals.index(0)
    return i if i

    return 1 if intervals[0] <= 2
    return 0 if (intervals[-2] == 2) && (intervals[-1] <= 1)
  
    jprev = nil
    j0 = nil

    @fibs.each_with_index { | fib, i |
      j = intervals.index(fib)
      if jprev
        case j
        when nil
          return 1 + jprev
        when 0
          return 1
        end
      else
        j0 = j
      end

      jprev = j
    }

    0 # safety-net
  end
<commit_msg>good in my brain<commit_after>class FibInterval
  attr_reader :holding_capacity, :fibs

  HOLDING_CAPACITY_MIN = 4

  def initialize(holding_capacity)
    raise TypeError unless holding_capacity.is_a? Integer
    if holding_capacity < HOLDING_CAPACITY_MIN
      raise "holding_capacity >= #{HOLDING_CAPACITY_MIN}"
    end
    @holding_capacity = holding_capacity
    @holding_capacity.freeze
    @intervals_capacity = holding_capacity - 1
    @intervals_capacity.freeze
    @fibs = generate_fibs(holding_capacity)
    @fibs.freeze
  end

  def indexes_to_delete(intervals)
    raise ArgumentError unless valid_intervals? intervals
    ivals = intervals.dup
    result = []
    while ivals.size >= @holding_capacity
      idx = get_index(ivals)
      break if idx.nil?
      result << idx
      virtual_delete(ivals, idx)
    end
    result
  end

  alias indices_to_delete indexes_to_delete

  private
  def generate_fibs(n) # [1, 2, 3, 5, 8, 13, 21, ...]
    ary = []
    x,y = 1,1
    n.times { ary << y; x, y = y, x+y }
    ary
  end

  def valid_intervals?(intervals)
    return false unless intervals.is_a? Array
    prev = nil
    intervals.each { |x|
      return false unless x.is_a? Integer
      return false if x < 0
      return false if prev && (prev < x)
      prev = x
    }
    true
  end

  def get_index(intervals)
    return nil if intervals.size < @intervals_capacity

    j = intervals.index(0)
    return j if j

    return 1 if intervals[0] <= 2
    return 0 if (intervals[-2] == 2) && (intervals[-1] <= 1)
  
    jprev = nil
    @fibs.each { | fib |
      j = intervals.index(fib)
      if jprev
        case j
        when nil
          return 1 + jprev
        when 0
          return 1
        end
      end
      jprev = j
    }

    nil # safety-net
  end

{'fraction_non_alphanumeric': 0.08562775330396476, 'fraction_numerical': 0.0151431718061674, 'mean_word_length': 2.2907608695652173, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 7, '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': '6387677', 'n_tokens_mistral': 1303, 'n_tokens_neox': 1202, 'n_words': 337}