| Crates.io | nthash-rs |
| lib.rs | nthash-rs |
| version | 0.1.3 |
| created_at | 2025-05-08 13:35:54.198682+00 |
| updated_at | 2025-07-25 06:29:42.323603+00 |
| description | Pure‑Rust port of ntHash |
| homepage | https://github.com/haradama/nthash-rs |
| repository | https://github.com/haradama/nthash-rs |
| max_upload_size | |
| id | 1665351 |
| size | 123,098 |
Pure‑Rust port of ntHash rolling‑hash suite, focused on contiguous k‑mer hashing for DNA sequences.
cargo add nthash-rs
use nthash_rs::{NtHashBuilder, NtHashError};
fn main() -> Result<(), NtHashError> {
let seq = b"ACGTCAGTNNNNACGTACGT";
let k = 4u16;
let m = 2u8; // number of hashes per k-mer
// Build an iterator over all valid k-mers
let iter = NtHashBuilder::new(seq)
.k(k)
.num_hashes(m)
.pos(0)
.finish()?;
for (pos, hashes) in iter {
// slice out the current k-mer
let kmer = &seq[pos..pos + k as usize];
println!("{} → {:x?}", kmer, hashes);
}
Ok(())
}
If you prefer to manage the rolling yourself:
use nthash_rs::NtHash;
let seq = b"ACGTCAGTNNNNACGTACGT";
let k = 4u16;
let m = 2u8;
let mut h = NtHash::new(seq, k, m, 0)?;
if h.roll() {
println!("first hash: {:#x}", h.hashes()[0]);
}
while h.roll() {
println!("next hash: {:#x}", h.forward_hash());
}
This project is MIT‑licensed (see LICENSE).