///|
/// 取与 `query` 最相似的那一个候选。等价于 `top_k(choices, query, 1, 0.0, metric, key)`
/// 的首元素,不做任何额外的检索逻辑。
///
/// - 候选集为空(或 `k` 截断后无结果)时返回 `None`
/// - 分数相同仍按原始下标升序,所以同样的输入必得同样的输出
/// - `Metric::Hamming` 遇到长度不等的候选得到 `None`,该候选被跳过;若全部候选都不等长,
///   同样返回 `None`(不中止)
pub fn[A] extract_one(
  choices : Array[A],
  query : String,
  metric : Metric,
  key : (A) -> String,
) -> (A, Double)? {
  let top = top_k(choices, query, 1, 0.0, metric, key)
  if top.length() == 0 {
    None
  } else {
    Some(top[0])
  }
}

///|
/// 取所有分数 `>= score_cutoff` 的候选,按分数降序、同分按原始下标升序。
///
/// 等价于 `top_k(choices, query, choices.length(), score_cutoff, metric, key)`:
/// 没有返回条数上限,长度等于通过 cutoff 的候选数(`None` 候选不计入)。
pub fn[A] extract_all(
  choices : Array[A],
  query : String,
  score_cutoff : Double,
  metric : Metric,
  key : (A) -> String,
) -> Array[(A, Double)] {
  top_k(choices, query, choices.length(), score_cutoff, metric, key)
}