Skip to main content

dispatch_on_k

Macro dispatch_on_k 

Source
macro_rules! dispatch_on_k {
    ($k:expr, $K:ident => $body:expr) => { ... };
}
Expand description

Dispatch to the correct const generic K based on a runtime k value.

The const generic K determines both the storage type (u64 for K ≤ 31, u128 for K > 31) and the k-mer length used in operations like reverse_complement(), from_str(), and decode_kmer(). Therefore K must always equal the actual k value, not merely the maximum for the storage class.

k must be an odd value in [3, 63]; these are the only values for which KmerBits is implemented.

§Usage

use sshash_lib::dispatch_on_k;

dispatch_on_k!(k, K => {
    let kmer = Kmer::<K>::from_string(s)?;
    dict.lookup::<K>(&kmer)
})

§Panics

Panics at runtime if k is even or outside the [3, 63] range.