mirror of
https://github.com/ruvnet/RuVector.git
synced 2026-05-23 12:55:26 +00:00
fix(acorn): clippy clean-up — sort_by_key, is_empty, redundant closures
CI's `Clippy (deny warnings)` flagged three lints introduced by the previous optimization commit: - `unnecessary_sort_by` (graph.rs:158, 176) → use `sort_by_key` - `len_without_is_empty` (graph.rs) → add `AcornGraph::is_empty` and `if graph.is_empty()` in search.rs - `redundant_closure` (main.rs:65, 159, 160) → pass the predicate directly to `recall_at_k` instead of `|id| pred(id)` No semantic change. Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
parent
eb88176bd5
commit
f5913b783d
3 changed files with 10 additions and 6 deletions
|
|
@ -126,6 +126,10 @@ impl AcornGraph {
|
|||
self.data.len() / self.dim.max(1)
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.len() == 0
|
||||
}
|
||||
|
||||
/// Borrow vector `i` as a contiguous slice — the hot path for L2².
|
||||
#[inline(always)]
|
||||
pub fn row(&self, i: usize) -> &[f32] {
|
||||
|
|
@ -155,7 +159,7 @@ pub fn flat_k_nearest(data: &[Vec<f32>], query: &[f32], k: usize) -> Vec<u32> {
|
|||
}
|
||||
}
|
||||
let mut out: Vec<(OrdF32, u32)> = heap.into_sorted_vec();
|
||||
out.sort_by(|a, b| a.0.cmp(&b.0));
|
||||
out.sort_by_key(|a| a.0);
|
||||
out.into_iter().map(|(_, id)| id).collect()
|
||||
}
|
||||
|
||||
|
|
@ -173,7 +177,7 @@ pub fn exact_filtered_knn(
|
|||
.filter(|&i| predicate(i as u32))
|
||||
.map(|i| (OrdF32(l2_sq(&data[i], query)), i as u32))
|
||||
.collect();
|
||||
scored.sort_by(|a, b| a.0.cmp(&b.0));
|
||||
scored.sort_by_key(|a| a.0);
|
||||
scored.truncate(k);
|
||||
scored.into_iter().map(|(_, id)| id).collect()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ fn run_variant(
|
|||
sel_pct: f64,
|
||||
predicate: &(dyn Fn(u32) -> bool + Sync),
|
||||
) {
|
||||
let recall = recall_at_k(data, queries, K, |id| predicate(id), index);
|
||||
let recall = recall_at_k(data, queries, K, predicate, index);
|
||||
let qps = bench_qps(index, queries, K, predicate);
|
||||
let mem_mb = index.memory_bytes() as f64 / 1_048_576.0;
|
||||
println!(
|
||||
|
|
@ -156,8 +156,8 @@ fn main() {
|
|||
println!("{}", "-".repeat(44));
|
||||
for sel_frac in [0.50, 0.20, 0.10, 0.05, 0.02, 0.01] {
|
||||
let pred = selectivity_predicate(N, sel_frac);
|
||||
let r_flat = recall_at_k(&data, &queries, K, |id| pred(id), &flat);
|
||||
let r_acorn = recall_at_k(&data, &queries, K, |id| pred(id), &acorng);
|
||||
let r_flat = recall_at_k(&data, &queries, K, pred, &flat);
|
||||
let r_acorn = recall_at_k(&data, &queries, K, pred, &acorng);
|
||||
println!(
|
||||
"{:>7.0}% {:>16.1}% {:>16.1}%",
|
||||
sel_frac * 100.0,
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ pub fn acorn_search(
|
|||
ef: usize,
|
||||
predicate: impl Fn(u32) -> bool,
|
||||
) -> Vec<(u32, f32)> {
|
||||
if graph.len() == 0 {
|
||||
if graph.is_empty() {
|
||||
return vec![];
|
||||
}
|
||||
let n = graph.len();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue