pub struct BufferedSegments { /* private fields */ }Expand description
Buffered segments storage
Matches C++ AGC’s CBufferedSegPart (agc_compressor.h:27-536)
Architecture:
vl_seg_part: Vector of thread-safe lists, indexed by group_id (KNOWN segments)s_seg_part: BTreeSet of NEW segments (not yet assigned group_id)
Workflow:
- During compression: Workers call
add_known()oradd_new() - At registration barrier: Main thread calls
sort_known(),process_new(),distribute_segments() - During storage: Workers call
get_vec_id()andget_part()to read segments - After storage: Main thread calls
clear()
Implementations§
Source§impl BufferedSegments
impl BufferedSegments
Sourcepub fn new(no_raw_groups: usize) -> Self
pub fn new(no_raw_groups: usize) -> Self
Create new buffered segments storage
Matches C++ AGC’s CBufferedSegPart::CBufferedSegPart (agc_compressor.h:308-311)
§Arguments
no_raw_groups- Initial number of group IDs
Sourcepub fn add_known(
&self,
group_id: u32,
kmer1: u64,
kmer2: u64,
sample_name: String,
contig_name: String,
seg_data: Vec<u8>,
is_rev_comp: bool,
seg_part_no: u32,
)
pub fn add_known( &self, group_id: u32, kmer1: u64, kmer2: u64, sample_name: String, contig_name: String, seg_data: Vec<u8>, is_rev_comp: bool, seg_part_no: u32, )
Add segment to KNOWN group
Matches C++ AGC’s CBufferedSegPart::add_known (agc_compressor.h:320-324)
Thread-safe: SegmentPartList::emplace() has internal mutex
Sourcepub fn add_new(
&self,
kmer1: u64,
kmer2: u64,
sample_name: String,
contig_name: String,
seg_data: Vec<u8>,
is_rev_comp: bool,
seg_part_no: u32,
)
pub fn add_new( &self, kmer1: u64, kmer2: u64, sample_name: String, contig_name: String, seg_data: Vec<u8>, is_rev_comp: bool, seg_part_no: u32, )
Add NEW segment (not yet assigned group_id)
Matches C++ AGC’s CBufferedSegPart::add_new (agc_compressor.h:326-331)
Thread-safe: Locks s_seg_part mutex
Sourcepub fn sort_known(&self, _num_threads: usize)
pub fn sort_known(&self, _num_threads: usize)
Sort all KNOWN segments in parallel
Matches C++ AGC’s CBufferedSegPart::sort_known (agc_compressor.h:333-377)
Note: In C++ AGC, this uses std::async for parallelism. For now, we’ll use a simple sequential implementation. Parallelism can be added later with rayon.
§Arguments
_num_threads- Number of threads (unused in sequential version)
Sourcepub fn process_new(
&mut self,
map_segments: &Mutex<AHashMap<(u64, u64), u32>>,
) -> u32
pub fn process_new( &mut self, map_segments: &Mutex<AHashMap<(u64, u64), u32>>, ) -> u32
Process NEW segments: assign group IDs and move to KNOWN
Matches C++ AGC’s CBufferedSegPart::process_new (agc_compressor.h:384-415)
Returns: Number of NEW groups created
Sourcepub fn get_num_new(&self) -> usize
pub fn get_num_new(&self) -> usize
Get the number of NEW segments (not yet assigned group_id)
For testing - count segments in s_seg_part
Sourcepub fn distribute_segments(
&self,
src_id: u32,
dest_id_from: u32,
dest_id_to: u32,
)
pub fn distribute_segments( &self, src_id: u32, dest_id_from: u32, dest_id_to: u32, )
Distribute segments from src_id to range [dest_from, dest_to)
Matches C++ AGC’s CBufferedSegPart::distribute_segments (agc_compressor.h:417-435)
Pattern: Round-robin distribution
Example: distribute_segments(0, 0, num_workers)
- Distributes group 0 segments among workers 0..num_workers
Sourcepub fn clear(&mut self, _num_threads: usize)
pub fn clear(&mut self, _num_threads: usize)
Clear all buffered segments
Matches C++ AGC’s CBufferedSegPart::clear (agc_compressor.h:461-507)
§Arguments
_num_threads- Number of threads (unused in sequential version)
Sourcepub fn restart_read_vec(&self)
pub fn restart_read_vec(&self)
Restart reading from highest group_id
Matches C++ AGC’s CBufferedSegPart::restart_read_vec (agc_compressor.h:509-514)
Sourcepub fn get_vec_id(&self) -> i32
pub fn get_vec_id(&self) -> i32
Atomically get next group_id to process (decrements from size-1 to 0)
Matches C++ AGC’s CBufferedSegPart::get_vec_id (agc_compressor.h:516-520)
Returns: group_id to process, or negative if done
Sourcepub fn is_empty_part(&self, group_id: i32) -> bool
pub fn is_empty_part(&self, group_id: i32) -> bool
Check if group is empty
Matches C++ AGC’s CBufferedSegPart::is_empty_part (agc_compressor.h:527-530)
Sourcepub fn get_part(
&self,
group_id: i32,
) -> Option<(u64, u64, String, String, Vec<u8>, bool, u32)>
pub fn get_part( &self, group_id: i32, ) -> Option<(u64, u64, String, String, Vec<u8>, bool, u32)>
Pop next segment from group
Matches C++ AGC’s CBufferedSegPart::get_part (agc_compressor.h:532-535)
Returns: (kmer1, kmer2, sample_name, contig_name, seg_data, is_rev_comp, seg_part_no)
Sourcepub fn get_no_parts(&self) -> usize
pub fn get_no_parts(&self) -> usize
Get current number of groups
Auto Trait Implementations§
impl !Freeze for BufferedSegments
impl RefUnwindSafe for BufferedSegments
impl Send for BufferedSegments
impl Sync for BufferedSegments
impl Unpin for BufferedSegments
impl UnwindSafe for BufferedSegments
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