use crate::dictionary::Dictionary;
use crate::kmer::{Kmer, KmerBits};
use crate::streaming_query::{LookupResult, StreamingQueryEngine};
pub trait KmerStreamingQuery {
const PREFERS_BITS: bool;
fn reset(&mut self);
fn lookup(&mut self, kmer_bytes: &[u8]) -> LookupResult;
fn lookup_bits(
&mut self,
canonical_bits: u64,
fw_is_canonical: bool,
fw_bytes: &[u8],
) -> LookupResult;
fn num_searches(&self) -> u64;
fn num_extensions(&self) -> u64;
#[inline]
fn skip_anchor_along_string(&mut self, _read_offset: i32) -> bool {
false
}
}
pub trait KmerDictionary {
type Query<'a, const K: usize>: KmerStreamingQuery
where
Self: 'a,
Kmer<K>: KmerBits;
fn k(&self) -> usize;
fn m(&self) -> usize;
fn num_strings(&self) -> u64;
fn canonical(&self) -> bool;
fn kmer_at_pos<const K: usize>(&self, absolute_base_pos: usize) -> Kmer<K>
where
Kmer<K>: KmerBits;
fn create_streaming_query<const K: usize>(&self) -> Self::Query<'_, K>
where
Kmer<K>: KmerBits;
}
impl<'a, const K: usize> KmerStreamingQuery for StreamingQueryEngine<'a, K>
where
Kmer<K>: KmerBits,
{
const PREFERS_BITS: bool = false;
#[inline]
fn reset(&mut self) {
StreamingQueryEngine::reset(self)
}
#[inline]
fn lookup(&mut self, kmer_bytes: &[u8]) -> LookupResult {
StreamingQueryEngine::lookup(self, kmer_bytes)
}
#[inline]
fn lookup_bits(
&mut self,
_canonical_bits: u64,
_fw_is_canonical: bool,
fw_bytes: &[u8],
) -> LookupResult {
StreamingQueryEngine::lookup(self, fw_bytes)
}
#[inline]
fn num_searches(&self) -> u64 {
StreamingQueryEngine::num_searches(self)
}
#[inline]
fn num_extensions(&self) -> u64 {
StreamingQueryEngine::num_extensions(self)
}
}
impl KmerDictionary for Dictionary {
type Query<'a, const K: usize>
= StreamingQueryEngine<'a, K>
where
Self: 'a,
Kmer<K>: KmerBits;
#[inline]
fn k(&self) -> usize {
Dictionary::k(self)
}
#[inline]
fn m(&self) -> usize {
Dictionary::m(self)
}
#[inline]
fn num_strings(&self) -> u64 {
Dictionary::num_strings(self)
}
#[inline]
fn canonical(&self) -> bool {
Dictionary::canonical(self)
}
#[inline]
fn kmer_at_pos<const K: usize>(&self, absolute_base_pos: usize) -> Kmer<K>
where
Kmer<K>: KmerBits,
{
Dictionary::kmer_at_pos::<K>(self, absolute_base_pos)
}
#[inline]
fn create_streaming_query<const K: usize>(&self) -> Self::Query<'_, K>
where
Kmer<K>: KmerBits,
{
Dictionary::create_streaming_query::<K>(self)
}
}