Skip to main content

TemplateRecordBuffer

Struct TemplateRecordBuffer 

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

Template-coordinate record buffer with inline headers.

Uses inline headers to store full sort keys in the data buffer, allowing minimal refs (16 bytes) while maintaining fast comparison.

Memory layout:

data: [Header0][Record0][Header1][Record1]...
refs: [Ref0][Ref1]...

During sorting, we use a custom comparator that:

  1. Compares primary keys from refs (fast, O(1))
  2. On ties, fetches full keys from inline headers

Implementations§

Source§

impl TemplateRecordBuffer

Source

pub fn with_capacity(estimated_records: usize, estimated_bytes: usize) -> Self

Create a new buffer with estimated capacity.

Source

pub fn push(&mut self, record: &[u8], key: TemplateKey)

Push a record with a pre-computed template key.

§Panics

Panics if the record length exceeds u32::MAX.

Source

pub fn sort(&mut self)

Sort the index by cached key using stable LSD radix sort.

Uses multi-field radix sort which is stable (preserves relative order of records with equal keys). This ensures deterministic output that matches samtools when records have identical sort keys.

Source

pub fn par_sort(&mut self)

Sort using parallel radix sort with stable k-way merge.

Each chunk is sorted with stable radix sort, then merged with a heap that uses chunk_idx as tie-breaker to preserve input order.

Source

pub fn get_record(&self, r: &TemplateRecordRef) -> &[u8]

Get record bytes by reference.

Source

pub fn iter_sorted(&self) -> impl Iterator<Item = &[u8]>

Iterate over sorted records.

Source

pub fn refs(&self) -> &[TemplateRecordRef]

Get the sorted record references.

Source

pub fn memory_usage(&self) -> usize

Memory usage in bytes (actual data stored, not capacity).

Source

pub fn len(&self) -> usize

Number of records.

Source

pub fn is_empty(&self) -> bool

Check if buffer is empty.

Source

pub fn get_key(&self, r: &TemplateRecordRef) -> TemplateKey

Get the key for a record reference (returns cached key from ref).

Source

pub fn iter_sorted_keyed(&self) -> impl Iterator<Item = (TemplateKey, &[u8])>

Iterate over sorted (key, record) pairs. Used for writing keyed temp chunks that preserve sort keys.

Source

pub fn clear(&mut self)

Clear the buffer for reuse.

Source

pub fn data(&self) -> &[u8]

Get underlying data buffer (for direct access to raw bytes).

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> 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> 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, 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.