Struct noodles_bgzf::virtual_position::VirtualPosition
source · pub struct VirtualPosition(/* private fields */);
Expand description
A BGZF virtual position.
A virtual position is a 64-bit unsigned integer representing both the position in the compressed stream and position in the uncompressed block data. The compressed position is typically at the start of a block.
The compressed position is the first six most significant bytes; and the uncompressed position, the last two least significant bytes. For example, for the virtual position 10253313912875616487:
compressed position
| |
10253313912875616487 = 8e 4b 16 ad eb 85 88 e7
| |
uncompressed position
The compressed position is at 156453154188165 (8e 4b 16 ad eb 85
); and the uncompressed
position, 35047 (88 e7
).
This is also called a virtual file offset; or, simply, a virtual offset.
Implementations§
source§impl VirtualPosition
impl VirtualPosition
sourcepub const fn new(compressed_pos: u64, uncompressed_pos: u16) -> Option<Self>
pub const fn new(compressed_pos: u64, uncompressed_pos: u16) -> Option<Self>
Creates a virtual position if the compressed position is valid.
§Examples
use noodles_bgzf::VirtualPosition;
assert_eq!(VirtualPosition::new(0, 0), Some(VirtualPosition::MIN));
assert!(VirtualPosition::new(1 << 48, 0).is_none());
sourcepub const fn compressed(self) -> u64
pub const fn compressed(self) -> u64
The position in the compressed BGZF stream.
This is typically at the start of a block.
The maximum value of a compressed position is 281474976710655 (2^48 - 1).
§Examples
use noodles_bgzf as bgzf;
let virtual_position = bgzf::VirtualPosition::from(3741638);
assert_eq!(virtual_position.compressed(), 57);
sourcepub const fn uncompressed(self) -> u16
pub const fn uncompressed(self) -> u16
The position in the uncompressed block data.
The maximum value of an uncompressed position is 65535 (2^16 - 1).
§Examples
use noodles_bgzf as bgzf;
let virtual_position = bgzf::VirtualPosition::from(3741638);
assert_eq!(virtual_position.uncompressed(), 6086);
Trait Implementations§
source§impl Clone for VirtualPosition
impl Clone for VirtualPosition
source§fn clone(&self) -> VirtualPosition
fn clone(&self) -> VirtualPosition
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for VirtualPosition
impl Debug for VirtualPosition
source§impl Default for VirtualPosition
impl Default for VirtualPosition
source§fn default() -> VirtualPosition
fn default() -> VirtualPosition
source§impl From<VirtualPosition> for (u64, u16)
impl From<VirtualPosition> for (u64, u16)
source§fn from(pos: VirtualPosition) -> Self
fn from(pos: VirtualPosition) -> Self
source§impl From<VirtualPosition> for u64
impl From<VirtualPosition> for u64
source§fn from(pos: VirtualPosition) -> Self
fn from(pos: VirtualPosition) -> Self
source§impl From<u64> for VirtualPosition
impl From<u64> for VirtualPosition
source§impl Ord for VirtualPosition
impl Ord for VirtualPosition
source§fn cmp(&self, other: &VirtualPosition) -> Ordering
fn cmp(&self, other: &VirtualPosition) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl PartialEq for VirtualPosition
impl PartialEq for VirtualPosition
source§impl PartialOrd for VirtualPosition
impl PartialOrd for VirtualPosition
source§impl TryFrom<(u64, u16)> for VirtualPosition
impl TryFrom<(u64, u16)> for VirtualPosition
source§fn try_from(pos: (u64, u16)) -> Result<Self, Self::Error>
fn try_from(pos: (u64, u16)) -> Result<Self, Self::Error>
Converts a (compressed position, uncompressed position)
tuple to a virtual position.
§Examples
use noodles_bgzf as bgzf;
let virtual_position = bgzf::VirtualPosition::try_from((57, 6086));
assert_eq!(virtual_position, Ok(bgzf::VirtualPosition::from(3741638)));
source§type Error = TryFromU64U16TupleError
type Error = TryFromU64U16TupleError
impl Copy for VirtualPosition
impl Eq for VirtualPosition
impl StructuralPartialEq for VirtualPosition
Auto Trait Implementations§
impl Freeze for VirtualPosition
impl RefUnwindSafe for VirtualPosition
impl Send for VirtualPosition
impl Sync for VirtualPosition
impl Unpin for VirtualPosition
impl UnwindSafe for VirtualPosition
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)