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:
- Compares primary keys from refs (fast, O(1))
- On ties, fetches full keys from inline headers
Implementations§
Source§impl TemplateRecordBuffer
impl TemplateRecordBuffer
Sourcepub fn with_capacity(estimated_records: usize, estimated_bytes: usize) -> Self
pub fn with_capacity(estimated_records: usize, estimated_bytes: usize) -> Self
Create a new buffer with estimated capacity.
Sourcepub fn push(&mut self, record: &[u8], key: TemplateKey)
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.
Sourcepub fn sort(&mut self)
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.
Sourcepub fn par_sort(&mut self)
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.
Sourcepub fn get_record(&self, r: &TemplateRecordRef) -> &[u8] ⓘ
pub fn get_record(&self, r: &TemplateRecordRef) -> &[u8] ⓘ
Get record bytes by reference.
Sourcepub fn iter_sorted(&self) -> impl Iterator<Item = &[u8]>
pub fn iter_sorted(&self) -> impl Iterator<Item = &[u8]>
Iterate over sorted records.
Sourcepub fn refs(&self) -> &[TemplateRecordRef]
pub fn refs(&self) -> &[TemplateRecordRef]
Get the sorted record references.
Sourcepub fn memory_usage(&self) -> usize
pub fn memory_usage(&self) -> usize
Memory usage in bytes (actual data stored, not capacity).
Sourcepub fn get_key(&self, r: &TemplateRecordRef) -> TemplateKey
pub fn get_key(&self, r: &TemplateRecordRef) -> TemplateKey
Get the key for a record reference (returns cached key from ref).
Sourcepub fn iter_sorted_keyed(&self) -> impl Iterator<Item = (TemplateKey, &[u8])>
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.
Auto Trait Implementations§
impl Freeze for TemplateRecordBuffer
impl RefUnwindSafe for TemplateRecordBuffer
impl Send for TemplateRecordBuffer
impl Sync for TemplateRecordBuffer
impl Unpin for TemplateRecordBuffer
impl UnsafeUnpin for TemplateRecordBuffer
impl UnwindSafe for TemplateRecordBuffer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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