Skip to content

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

License

Notifications You must be signed in to change notification settings

haradama/nthash-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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).

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages