Skip to main content

kira_cdh_compat_lsh/
lib.rs

1//! kira_cdh_compat_lsh
2//!
3//! Candidate search primitive for high-identity clustering pipelines
4//! (e.g., CD-HIT-like). This crate provides:
5//! - MinHash and KMV (bottom-k) sketches over pre-hashed k-mers (u64),
6//! - Classic LSH banding to retrieve candidate neighbors,
7//! - Parallel bulk build & queries (feature `parallel`).
8//!
9//! The crate **does not** parse FASTA/FASTQ and **does not** write `.clstr`;
10//! it focuses solely on sketching and candidate retrieval.
11//!
12//! # Quick Start
13//!
14//! ```rust
15//! use kira_cdh_compat_lsh::*;
16//!
17//! // Suppose you already have hashed k-mers for sequences:
18//! let seq_a: Vec<u64> = vec![1, 2, 3, 10, 11, 12];
19//! let seq_b: Vec<u64> = vec![2, 3, 4, 11, 12, 13];
20//!
21//! // Build a KMV sketch (fast single-hash approach):
22//! let mut kmv = kmv::KmvSketch::new(128);
23//! for h in &seq_a { kmv.update(*h); }
24//! let sig_a = kmv.finish(); // Vec<u64> of length <= k (exactly k if enough items)
25//!
26//! let mut kmv2 = kmv::KmvSketch::new(128);
27//! for h in &seq_b { kmv2.update(*h); }
28//! let sig_b = kmv2.finish();
29//!
30//! // LSH parameters: 32 bands x 4 rows = 128
31//! let params = lsh::LshParams::new(32, 4).unwrap();
32//!
33//! let mut index = lsh::LshIndex::with_params(params.clone());
34//! index.insert(0, &sig_a);
35//! index.insert(1, &sig_b);
36//! index.build(); // finalize buckets (optional no-op for current implementation)
37//!
38//! // Query candidates for seq_a's signature:
39//! let cands = index.query_candidates(&sig_a, 1); // min 1 band collision
40//! // cands is Vec<(id, collisions)>
41//! assert!(cands.iter().any(|(id, _)| *id == 1));
42//!
43//! // Jaccard estimate (KMV or MinHash signatures):
44//! let j_est = sketch::jaccard_from_signatures(&sig_a, &sig_b);
45//! eprintln!("Estimated Jaccard: {:.3}", j_est);
46//! ```
47//!
48//! # Notes
49//! - For MinHash, use `minhash::MinHash` with `num_hashes = bands * rows`.
50//! - For KMV, you might prefer slightly larger k to reach stable estimates.
51//! - LSH banding is deterministic and uses splitmix64 to map bands to buckets.
52
53pub mod errors;
54pub mod kmv;
55pub mod lsh;
56pub mod minhash;
57pub mod sketch;
58pub mod util;
59
60pub use lsh::{LshIndex, LshParams};