nthash-rs

Crates.ionthash-rs
lib.rsnthash-rs
version0.1.3
created_at2025-05-08 13:35:54.198682+00
updated_at2025-07-25 06:29:42.323603+00
descriptionPure‑Rust port of ntHash
homepagehttps://github.com/haradama/nthash-rs
repositoryhttps://github.com/haradama/nthash-rs
max_upload_size
id1665351
size123,098
haradama (haradama)

documentation

https://docs.rs/nthash-rs

README

nthsash‑rs

github crates.io docs.rs build status

Pure‑Rust port of ntHash rolling‑hash suite, focused on contiguous k‑mer hashing for DNA sequences.

Installation

cargo add nthash-rs

Quick Start

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(())
}

Low‑Level API

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());
}

License

This project is MIT‑licensed (see LICENSE).

Commit count: 23

cargo fmt