Struct iroh_blobs::protocol::RangeSpecSeq
source · pub struct RangeSpecSeq(/* private fields */);
Expand description
A chunk range specification for a sequence of blobs.
To select chunks in a sequence of blobs this is encoded as a sequence of (blob_offset, range_spec)
tuples. Offsets are interpreted in an accumulating fashion.
§Example:
Suppose two RangeSpec
s range_a
and range_b
.
[(0, range_a), (2, empty), (3, range_b), (1, empty)]
encodes:- Select
range_a
for children in the range[0, 2)
- do no selection (empty) for children in the range
[2, 2+3) = [2, 5)
(3 children) - Select
range_b
for children in the range[5, 5+1) = [5, 6)
(1 children) - do no selection (empty) for children in the open range
[6, inf)
- Select
Another way to understand this is that offsets represent the number of times the previous range appears.
Other examples:
-
Select
range_a
from all blobs after the 5th one in the sequence:[(5, range_a)]
. -
Select
range_a
from all blobs in the sequence:[(0, range_a)]
. -
Select
range_a
from blob 1234:[(1234, range_a), (1, empty)]
. -
Select nothing:
[]
.
This is a smallvec so that we can avoid allocations in the common case of a single child range.
Implementations§
source§impl RangeSpecSeq
impl RangeSpecSeq
sourcepub const fn empty() -> Self
pub const fn empty() -> Self
A RangeSpecSeq
containing no chunks from any blobs in the sequence.
RangeSpecSeq::iter
, will return an empty range forever.
sourcepub fn as_single(&self) -> Option<(u64, &RangeSpec)>
pub fn as_single(&self) -> Option<(u64, &RangeSpec)>
If this range seq describes a range for a single item, returns the offset and range spec for that item
sourcepub fn all() -> Self
pub fn all() -> Self
A RangeSpecSeq
containing all chunks from all blobs.
RangeSpecSeq::iter
, will return a full range forever.
sourcepub fn from_ranges(
ranges: impl IntoIterator<Item = impl AsRef<ChunkRangesRef>>
) -> Self
pub fn from_ranges( ranges: impl IntoIterator<Item = impl AsRef<ChunkRangesRef>> ) -> Self
Convenience function to create a RangeSpecSeq
from a finite sequence of range sets.
sourcepub fn from_ranges_infinite(
ranges: impl IntoIterator<Item = impl AsRef<ChunkRangesRef>>
) -> Self
pub fn from_ranges_infinite( ranges: impl IntoIterator<Item = impl AsRef<ChunkRangesRef>> ) -> Self
Convenience function to create a RangeSpecSeq
from a sequence of range sets.
Compared to RangeSpecSeq::from_ranges
, this will not add an empty range spec at the end, so the final
range spec will repeat forever.
sourcepub fn new(children: impl IntoIterator<Item = RangeSpec>) -> Self
pub fn new(children: impl IntoIterator<Item = RangeSpec>) -> Self
Creates a new range spec sequence from a sequence of range specs.
This will merge adjacent range specs with the same value and thus make sure that the resulting sequence is as compact as possible.
sourcepub fn iter(&self) -> RequestRangeSpecIter<'_>
pub fn iter(&self) -> RequestRangeSpecIter<'_>
An infinite iterator of range specs for blobs in the sequence.
Each item yielded by the iterator is the RangeSpec
for a blob in the sequence.
Thus the first call to .next()
returns the range spec for the first blob, the next
call returns the range spec of the second blob, etc.
sourcepub fn iter_non_empty(&self) -> NonEmptyRequestRangeSpecIter<'_> ⓘ
pub fn iter_non_empty(&self) -> NonEmptyRequestRangeSpecIter<'_> ⓘ
An iterator over blobs in the sequence with a non-empty range spec.
This iterator will only yield items for blobs which have at least one chunk selected.
This iterator is infinite if the RangeSpecSeq
ends on a non-empty RangeSpec
,
that is all further blobs have selected chunks spans.
Trait Implementations§
source§impl Clone for RangeSpecSeq
impl Clone for RangeSpecSeq
source§fn clone(&self) -> RangeSpecSeq
fn clone(&self) -> RangeSpecSeq
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for RangeSpecSeq
impl Debug for RangeSpecSeq
source§impl<'de> Deserialize<'de> for RangeSpecSeq
impl<'de> Deserialize<'de> for RangeSpecSeq
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl Hash for RangeSpecSeq
impl Hash for RangeSpecSeq
source§impl PartialEq for RangeSpecSeq
impl PartialEq for RangeSpecSeq
source§fn eq(&self, other: &RangeSpecSeq) -> bool
fn eq(&self, other: &RangeSpecSeq) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl Serialize for RangeSpecSeq
impl Serialize for RangeSpecSeq
impl Eq for RangeSpecSeq
impl StructuralPartialEq for RangeSpecSeq
Auto Trait Implementations§
impl Freeze for RangeSpecSeq
impl RefUnwindSafe for RangeSpecSeq
impl Send for RangeSpecSeq
impl Sync for RangeSpecSeq
impl Unpin for RangeSpecSeq
impl UnwindSafe for RangeSpecSeq
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.