Skip to content

Commit

Permalink
Add PieceIndex::source_position()
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Nov 19, 2024
1 parent 8fe5849 commit 9a47e2f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions crates/subspace-core-primitives/src/pieces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ impl PieceIndex {
(self.0 % ArchivedHistorySegment::NUM_PIECES as u64) as u32
}

/// Position of a source piece in the source pieces for a segment.
/// Panics if the piece is not a source piece.
#[inline]
pub const fn source_position(&self) -> u32 {
assert!(self.is_source());
self.position() / (Self::source_ratio() as u32)
}

/// Is this piece index a source piece?
#[inline]
pub const fn is_source(&self) -> bool {
Expand Down

0 comments on commit 9a47e2f

Please sign in to comment.