Skip to main content

FmIndex

Struct FmIndex 

Source
pub struct FmIndex { /* private fields */ }
Expand description

An FM-index over a byte string: BWT, C array, and Occ rank table, with the suffix array retained for locate.

Build with FmIndex::new. The index supports exact-occurrence FmIndex::count, position FmIndex::locate, and full text recovery via FmIndex::inverse_bwt (the BWT round-trips).

§Examples

use oxicuda_seq::string::FmIndex;

let fm = FmIndex::new(b"banana").expect("non-empty");
assert_eq!(fm.count(b"ana"), 2);
assert_eq!(fm.locate(b"ana"), vec![1, 3]);
assert_eq!(fm.count(b"xyz"), 0);
assert_eq!(fm.inverse_bwt(), b"banana");

Implementations§

Source§

impl FmIndex

Source

pub fn new(s: &[u8]) -> SeqResult<Self>

Build the FM-index of s.

Internally appends a unique sentinel, derives the BWT from the reused SA-IS suffix array, and precomputes the C and Occ tables.

§Errors

Returns SeqError::EmptyInput for an empty s, consistent with the sibling string modules.

Source

pub fn text_len(&self) -> usize

Length of the original text (excluding the sentinel).

Source

pub fn bwt_bytes(&self, sentinel_byte: u8) -> Vec<u8>

Borrow the BWT as raw bytes, mapping the sentinel to sentinel_byte.

The sentinel has no byte value of its own, so the caller supplies the placeholder used to render it. The placeholder is not required to be absent from the text; it is purely cosmetic for inspection/printing.

Source

pub fn inverse_bwt(&self) -> Vec<u8>

Recover the original text by inverting the BWT through the LF-mapping.

Starts at the sentinel row (row 0, since the sentinel sorts first) and walks LF backwards, emitting characters right-to-left.

Source

pub fn count(&self, pattern: &[u8]) -> usize

Number of occurrences of pattern in the text (backward search).

Returns 0 for an empty pattern or when the pattern does not occur.

Source

pub fn locate(&self, pattern: &[u8]) -> Vec<usize>

Sorted text positions of every occurrence of pattern.

Each row in the final backward-search range maps to a text position through the stored suffix array. Returns an empty vector for an empty or absent pattern.

Trait Implementations§

Source§

impl Clone for FmIndex

Source§

fn clone(&self) -> FmIndex

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FmIndex

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.