use crate::{
FmIndex, HalfOpenInterval, Hit, IndexStorage, text_with_rank_support::TextWithRankSupport,
};
pub struct Cursor<'a, I, R> {
pub(crate) index: &'a FmIndex<I, R>,
pub(crate) interval: HalfOpenInterval,
}
impl<'a, I, R> Clone for Cursor<'a, I, R> {
fn clone(&self) -> Self {
*self
}
}
impl<'a, I, R> Copy for Cursor<'a, I, R> {}
impl<'a, I: IndexStorage, R: TextWithRankSupport<I>> Cursor<'a, I, R> {
pub fn extend_query_front(&mut self, symbol: u8) {
let symbol = self.index.alphabet.io_to_dense_representation(symbol);
self.extend_front_without_alphabet_translation(symbol);
}
pub(crate) fn extend_front_without_alphabet_translation(&mut self, symbol: u8) {
let (start, end) = if self.interval.start != self.interval.end {
(
self.index.lf_mapping_step(symbol, self.interval.start),
self.index.lf_mapping_step(symbol, self.interval.end),
)
} else {
(self.interval.start, self.interval.end)
};
self.interval = HalfOpenInterval { start, end };
}
pub(crate) fn interval(&self) -> HalfOpenInterval {
self.interval
}
pub fn count(&self) -> usize {
self.interval.end - self.interval.start
}
pub fn locate(&self) -> impl Iterator<Item = Hit> {
self.index.locate_interval(self.interval)
}
}