pub struct Index { /* private fields */ }
Expand description
A chunk file providing a table into the parent data.
Implementations§
source§impl Index
impl Index
sourcepub const ENTRY_SIZE: usize = 12usize
pub const ENTRY_SIZE: usize = 12usize
The size of a single index entry in bytes
sourcepub const EMPTY_SIZE: usize = 12usize
pub const EMPTY_SIZE: usize = 12usize
The smallest possible size of an index, consisting only of the sentinel value pointing past itself.
sourcepub const fn size_for_entries(num_entries: usize) -> usize
pub const fn size_for_entries(num_entries: usize) -> usize
Returns the size in bytes an index with num_entries
would take.
sourcepub fn offset_by_id(&self, kind: Id) -> Result<Range<Offset>, Error>
pub fn offset_by_id(&self, kind: Id) -> Result<Range<Offset>, Error>
Find a chunk of kind
and return its offset into the data if found
sourcepub fn usize_offset_by_id(&self, kind: Id) -> Result<Range<usize>, Error>
pub fn usize_offset_by_id(&self, kind: Id) -> Result<Range<usize>, Error>
Find a chunk of kind
and return its offset as usize range into the data if found.
§Panics
- if the usize conversion fails, which isn’t expected as memory maps can’t be created if files are too large to require such offsets.
sourcepub fn validated_usize_offset_by_id<T>(
&self,
kind: Id,
validate: impl FnOnce(Range<usize>) -> T,
) -> Result<T, Error>
pub fn validated_usize_offset_by_id<T>( &self, kind: Id, validate: impl FnOnce(Range<usize>) -> T, ) -> Result<T, Error>
Like Index::usize_offset_by_id()
but with support for validation and transformation using a function.
sourcepub fn data_by_id<'a>(
&self,
data: &'a [u8],
kind: Id,
) -> Result<&'a [u8], Error>
pub fn data_by_id<'a>( &self, data: &'a [u8], kind: Id, ) -> Result<&'a [u8], Error>
Find a chunk of kind
and return its data slice based on its offset.
sourcepub fn highest_offset(&self) -> Offset
pub fn highest_offset(&self) -> Offset
Return the end offset lf the last chunk, which is the highest offset as well. It’s definitely available as we have one or more chunks.
source§impl Index
impl Index
Writing
sourcepub fn for_writing() -> Self
pub fn for_writing() -> Self
Create a new index whose sole purpose is to be receiving chunks using plan_chunk()
and to be written to
an output using into_write()
sourcepub fn plan_chunk(&mut self, chunk: Id, exact_size_on_disk: u64)
pub fn plan_chunk(&mut self, chunk: Id, exact_size_on_disk: u64)
Plan to write a new chunk as part of the index when into_write()
is called.
sourcepub fn planned_storage_size(&self) -> u64
pub fn planned_storage_size(&self) -> u64
Return the total size of all planned chunks thus far.
sourcepub fn num_chunks(&self) -> usize
pub fn num_chunks(&self) -> usize
Return the amount of chunks we currently know.
sourcepub fn into_write<W>(self, out: W, current_offset: usize) -> Result<Chunk<W>>where
W: Write,
pub fn into_write<W>(self, out: W, current_offset: usize) -> Result<Chunk<W>>where
W: Write,
After planning all chunks call this method with the destination to write the chunks to.
Use the Chunk writer to write each chunk in order.
current_offset
is the byte position at which out
will continue writing.