Skip to main content

SpectrumPreservingStringSet

Struct SpectrumPreservingStringSet 

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

The spectrum-preserving string set

Stores all strings in a bit-packed format with offsets to each string. This allows for both memory-efficient storage and efficient access patterns.

Offsets are stored using Elias-Fano encoding (via sux-rs) for compact representation and O(1) locate() via successor queries with Cursor.

Implementations§

Source§

impl SpectrumPreservingStringSet

Source

pub fn new(k: usize, m: usize) -> Self

Create a new empty SPSS

Source

pub fn from_parts( strings: Vec<u8>, offsets: OffsetsVector, k: usize, m: usize, ) -> Self

Create a new SPSS from existing strings and offsets

Converts the OffsetsVector to Elias-Fano encoding for compact storage.

§Arguments
  • strings - Encoded string data (2-bit packed)
  • offsets - Offset vector for string boundaries (will be converted to EF)
  • k - K-mer size
  • m - Minimizer size
Source

pub fn string_offsets(&self, string_id: u32) -> (u64, u64)

Get the string offsets (begin, end) for a string ID

Source

pub fn num_strings(&self) -> u64

Get the number of strings stored

Source

pub fn string_offset(&self, string_id: u64) -> u64

Get the starting offset (in bases) of a string

Source

pub fn k(&self) -> usize

Get the k-mer size

Source

pub fn m(&self) -> usize

Get the minimizer size

Source

pub fn total_bases(&self) -> u64

Get the total number of bases stored

Source

pub fn locate(&self, absolute_pos: u64) -> Option<(u64, u64)>

Locate which string contains a given absolute position. Returns (string_id, string_begin) or None if out of bounds.

Source

pub fn locate_with_end(&self, absolute_pos: u64) -> Option<(u64, u64, u64)>

Locate which string contains a given absolute position, returning (string_id, string_begin, string_end) in a single EF traversal. This is more efficient than calling locate() + string_offsets().

Source

pub fn num_bits(&self) -> u64

Get memory usage in bits

Source

pub fn strings_bytes(&self) -> usize

Get the byte size of the packed strings data

Source

pub fn offsets_bytes(&self) -> usize

Get the byte size of the offsets vector

Source

pub fn string_length(&self, string_id: u64) -> usize

Get the length of a specific string in bases

Source

pub fn decode_kmer<const K: usize>( &self, string_id: u64, kmer_pos: usize, ) -> Kmer<K>
where Kmer<K>: KmerBits,

Decode a k-mer from a specific position in a string

Uses word-level loads from the packed buffer for efficiency.

Source

pub fn decode_kmer_at<const K: usize>(&self, absolute_pos: usize) -> Kmer<K>
where Kmer<K>: KmerBits,

Decode a k-mer at an absolute base position in the concatenated strings. Avoids the need for string_id (no binary search needed). This matches the C++ util::read_kmer_at approach with decoded_offsets.

Source

pub fn serialize_to<W: Write>(&self, writer: &mut W) -> Result<()>

Serialize the SPSS to a writer using a custom binary format.

Format:

  • k: u64 (LE)
  • m: u64 (LE)
  • strings_len: u64 (LE)
  • strings: [u8; strings_len]
  • offsets: epserde Elias-Fano binary format
Source

pub fn deserialize_from<R: Read>(reader: &mut R) -> Result<Self>

Deserialize an SPSS from a reader.

Trait Implementations§

Source§

impl Debug for SpectrumPreservingStringSet

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> CastableFrom<T> for T

Source§

fn cast_from(value: T) -> T

Call Self as W
Source§

impl<T, U> CastableInto<U> for T
where U: CastableFrom<T>,

Source§

fn cast(self) -> U

Call W::cast_from(self)
Source§

impl<T> DowncastableFrom<T> for T

Source§

fn downcast_from(value: T) -> T

Truncate the current UnsignedInt to a possibly smaller size
Source§

impl<T, U> DowncastableInto<U> for T
where U: DowncastableFrom<T>,

Source§

fn downcast(self) -> U

Call W::downcast_from(self)
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Splat<T> for T

Source§

fn splat(value: T) -> T

Source§

impl<T> To<T> for T

Source§

fn to(self) -> T

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.
Source§

impl<T> UpcastableFrom<T> for T

Source§

fn upcast_from(value: T) -> T

Extend the current UnsignedInt to a possibly bigger size.
Source§

impl<T, U> UpcastableInto<U> for T
where U: UpcastableFrom<T>,

Source§

fn upcast(self) -> U

Call W::upcast_from(self)
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more