Trait for BINSEQ readers that can process records in parallel This is implemented by the **reader** not by the **processor**. For the **processor**, see the [`ParallelProcessor`] trait.
| 133 | /// This is implemented by the **reader** not by the **processor**. |
| 134 | /// For the **processor**, see the [`ParallelProcessor`] trait. |
| 135 | pub trait ParallelReader { |
| 136 | fn process_parallel<P: ParallelProcessor + Clone + 'static>( |
| 137 | self, |
| 138 | processor: P, |
| 139 | num_threads: usize, |
| 140 | ) -> Result<()>; |
| 141 | |
| 142 | /// Process records in parallel within a specified range |
| 143 | /// |
| 144 | /// This method allows parallel processing of a subset of records within the file, |
| 145 | /// defined by a start and end index. The range is distributed across the specified |
| 146 | /// number of threads. |
| 147 | /// |
| 148 | /// # Arguments |
| 149 | /// |
| 150 | /// * `processor` - The processor to use for each record |
| 151 | /// * `num_threads` - The number of threads to spawn |
| 152 | /// * `range` - The range of record indices to process |
| 153 | /// |
| 154 | /// # Returns |
| 155 | /// |
| 156 | /// * `Ok(())` - If all records were processed successfully |
| 157 | /// * `Err(Error)` - If an error occurred during processing |
| 158 | fn process_parallel_range<P: ParallelProcessor + Clone + 'static>( |
| 159 | self, |
| 160 | processor: P, |
| 161 | num_threads: usize, |
| 162 | range: Range<usize>, |
| 163 | ) -> Result<()>; |
| 164 | |
| 165 | /// Validate the specified range for the file. |
| 166 | /// |
| 167 | /// This method checks if the provided range is valid for the file, ensuring that |
| 168 | /// the start index is less than the end index and both indices are within the |
| 169 | /// bounds of the file. |
| 170 | /// |
| 171 | /// # Arguments |
| 172 | /// |
| 173 | /// * `total_records` - The total number of records in the file |
| 174 | /// * `range` - The range of record indices to validate |
| 175 | /// |
| 176 | /// # Returns |
| 177 | /// |
| 178 | /// * `Ok(())` - If the range is valid |
| 179 | /// * `Err(Error)` - If the range is invalid |
| 180 | fn validate_range(&self, total_records: usize, range: &Range<usize>) -> Result<()> { |
| 181 | if range.start >= total_records { |
| 182 | Err(ReadError::OutOfRange { |
| 183 | requested_index: range.start, |
| 184 | max_index: total_records, |
| 185 | } |
| 186 | .into()) |
| 187 | } else if range.end > total_records { |
| 188 | Err(ReadError::OutOfRange { |
| 189 | requested_index: range.end, |
| 190 | max_index: total_records, |
| 191 | } |
| 192 | .into()) |
no outgoing calls
no test coverage detected