<commit_before>class Jobs
  
  def initialize(db_file)
    @db = SQLite3::Database.new db_file
    @job_list = get_jobs
    
    puts resolve_order_all(@job_list,self).map{|j|j.name}.join("\n")
    # resolve_order_all(@job_list,self)
    
  end

  def by_id(id)
    (@job_list.select{ |j| j.id == id })[0]
  end
  def by_name(name)
    (@job_list.select{ |j| j.name == name })[0]
  end
  def by_proc(proc)
    (@job_list.select{ |j| j.proc == proc })[0]
  end
  
  protected 
  
  def get_jobs
    jobs = []
    rows = @db.execute("SELECT hex(id) FROM jobinfo WHERE name LIKE '<%>%'")
    rows.each { |r|
      id = r[0]
      jobs.push( Job.new(@db, :id => id) )
    }
    jobs
  end
  
  def resolve_order_all(job_list, jobs)
    order = []
    job_list.each{ |j|
      order = resolve_order(j, self, order)
    }
    order
  end
  
  def resolve_order(job, jobs, resolved, unresolved = [])
    if job.not_in? resolved
      unresolved << job
      job.deps.each { |dep|
        abort "ERROR: at '#{job.name}:#{dep[:start]}', the procedure <#{dep.proc}> is used but not defined." if jobs.by_proc(dep[:proc]).nil?
        if jobs.by_proc(dep[:proc]).not_in? resolved
          abort "ERROR: circular dependency detected: <#{job.proc}> -> <#{dep.proc}>." if jobs.by_proc(dep[:proc]).is_in? unresolved
          resolved = resolve_order(jobs.by_proc(dep[:proc]), jobs, resolved, unresolved)
          unresolved -= resolved
        end
      }
      resolved << job
    end
    return resolved
  end
  
  
  
end<commit_msg>Minor refactor of dep resolution to reduce required arguments.<commit_after>class Jobs
  
  def initialize(db_file)
    @db = SQLite3::Database.new db_file
    @job_list = get_jobs
    
    puts resolve_order_all(@job_list).map{|j|j.name}.join("\n")
    # resolve_order_all(@job_list,self)
    
  end

  def by_id(id)
    (@job_list.select{ |j| j.id == id })[0]
  end
  def by_name(name)
    (@job_list.select{ |j| j.name == name })[0]
  end
  def by_proc(proc)
    (@job_list.select{ |j| j.proc == proc })[0]
  end
  
  protected 
  
  def get_jobs
    jobs = []
    rows = @db.execute("SELECT hex(id) FROM jobinfo WHERE name LIKE '<%>%'")
    rows.each { |r|
      id = r[0]
      jobs.push( Job.new(@db, :id => id) )
    }
    jobs
  end
  
  def resolve_order_all(job_list)
    order = []
    job_list.each{ |j|
      order = resolve_order(j, order)
    }
    order
  end
  
  def resolve_order(job, resolved = [], unresolved = [])
    if job.not_in? resolved
      unresolved << job
      job.deps.each { |dep|
        abort "ERROR: at '#{job.name}:#{dep[:start]}', the procedure <#{dep.proc}> is used but not defined." if by_proc(dep[:proc]).nil?
        if by_proc(dep[:proc]).not_in? resolved
          abort "ERROR: circular dependency detected: <#{job.proc}> -> <#{dep.proc}>." if by_proc(dep[:proc]).is_in? unresolved
          resolved = resolve_order(by_proc(dep[:proc]), resolved, unresolved)
          unresolved -= resolved
        end
      }
      resolved << job
    end
    return resolved
  end
  
  
  
end
{'fraction_non_alphanumeric': 0.1504424778761062, 'fraction_numerical': 0.0032776138970829235, 'mean_word_length': 2.5821596244131455, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 15, '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': '4180307', 'n_tokens_mistral': 1109, 'n_tokens_neox': 1103, 'n_words': 253}