///|
pub(all) struct VcfIndex {
  entries : Array[(String, Int, VcfRecord)]
} derive(Debug, Eq)

///|
pub fn build_index(document : VcfDocument) -> VcfIndex {
  let entries : Array[(String, Int, VcfRecord)] = []
  for record in document.records {
    entries.push((record.chrom, record.pos, record))
  }
  { entries, }
}

///|
pub fn query_index(
  index : VcfIndex,
  chrom : String,
  start : Int,
  end : Int,
) -> Array[VcfRecord] {
  let matches : Array[VcfRecord] = []
  if start <= end {
    for entry in index.entries {
      let (item_chrom, pos, record) = entry
      if item_chrom == chrom && pos >= start && pos <= end {
        matches.push(record)
      }
    }
  }
  matches
}