pub struct ZstdVec<I, T>(/* private fields */);Expand description
Compressed storage using Zstd for maximum general-purpose compression.
Zstd (Zstandard) provides the best compression ratios among general-purpose algorithms, with good decompression speed. Ideal when storage is expensive.
§Performance Characteristics
- Highest compression ratios (typically 3-5x, better than LZ4)
- Fast decompression (slower compression than LZ4)
- Works well with any data type
§When to Use
- Storage space is expensive
- Can tolerate slower compression (decompression is fast)
Implementations§
Source§impl<I, T> ZstdVec<I, T>where
I: VecIndex,
T: ZstdVecValue,
impl<I, T> ZstdVec<I, T>where
I: VecIndex,
T: ZstdVecValue,
pub fn iter(&self) -> Result<ZstdVecIterator<'_, I, T>>
pub fn clean_iter(&self) -> Result<CleanZstdVecIterator<'_, I, T>>
pub fn dirty_iter(&self) -> Result<DirtyZstdVecIterator<'_, I, T>>
pub fn boxed_iter(&self) -> Result<BoxedVecIterator<'_, I, T>>
Trait Implementations§
Source§impl<I, T> AnyStoredVec for ZstdVec<I, T>where
I: VecIndex,
T: ZstdVecValue,
impl<I, T> AnyStoredVec for ZstdVec<I, T>where
I: VecIndex,
T: ZstdVecValue,
fn db_path(&self) -> PathBuf
fn region(&self) -> &Region
fn header(&self) -> &Header
fn mut_header(&mut self) -> &mut Header
Source§fn saved_stamped_changes(&self) -> u16
fn saved_stamped_changes(&self) -> u16
Number of stamped change files to keep for rollback support.
Source§fn real_stored_len(&self) -> usize
fn real_stored_len(&self) -> usize
The actual length stored on disk.
Source§fn stored_len(&self) -> usize
fn stored_len(&self) -> usize
The effective stored length (may differ from real_stored_len during truncation).
fn serialize_changes(&self) -> Result<Vec<u8>>
fn flush(&mut self) -> Result<()>
Source§fn safe_flush(&mut self, exit: &Exit) -> Result<()>
fn safe_flush(&mut self, exit: &Exit) -> Result<()>
Flushes while holding the exit lock to ensure consistency during shutdown.
Source§fn safe_write(&mut self, exit: &Exit) -> Result<()>
fn safe_write(&mut self, exit: &Exit) -> Result<()>
Writes to mmap without fsync, holding the exit lock.
Data is visible to readers immediately but not durable until sync.
Use this for performance when durability can be deferred.
fn update_stamp(&mut self, stamp: Stamp)
fn stamp(&self) -> Stamp
fn stamped_flush(&mut self, stamp: Stamp) -> Result<()>
Source§impl<I, T> AnyVec for ZstdVec<I, T>where
I: VecIndex,
T: ZstdVecValue,
impl<I, T> AnyVec for ZstdVec<I, T>where
I: VecIndex,
T: ZstdVecValue,
fn version(&self) -> Version
fn name(&self) -> &str
fn len(&self) -> usize
Source§fn index_type_to_string(&self) -> &'static str
fn index_type_to_string(&self) -> &'static str
Returns the string representation of the index type.
Source§fn value_type_to_size_of(&self) -> usize
fn value_type_to_size_of(&self) -> usize
Returns the size in bytes of the value type.
Source§fn region_names(&self) -> Vec<String>
fn region_names(&self) -> Vec<String>
Returns the list of region names used by this vector.
fn is_empty(&self) -> bool
Source§fn region_name(&self) -> String
fn region_name(&self) -> String
Returns the combined name of the vector.
Source§fn etag(&self, stamp: Stamp, to: Option<i64>) -> String
fn etag(&self, stamp: Stamp, to: Option<i64>) -> String
Generates an ETag for this vector based on stamp and optional end index.
Source§fn i64_to_usize(&self, i: i64) -> usize
fn i64_to_usize(&self, i: i64) -> usize
Converts an i64 index to usize, supporting negative indexing (Python-style).
Source§impl<I, T> GenericStoredVec<I, T> for ZstdVec<I, T>where
I: VecIndex,
T: ZstdVecValue,
impl<I, T> GenericStoredVec<I, T> for ZstdVec<I, T>where
I: VecIndex,
T: ZstdVecValue,
Source§fn read_value_from_bytes(&self, bytes: &[u8]) -> Result<T>
fn read_value_from_bytes(&self, bytes: &[u8]) -> Result<T>
Deserializes a value from bytes. Implementors use their strategy.
Source§fn write_value_to(&self, value: &T, buf: &mut Vec<u8>)
fn write_value_to(&self, value: &T, buf: &mut Vec<u8>)
Writes a value to the provided buffer. Implementors use their strategy.
Source§fn mut_pushed(&mut self) -> &mut Vec<T>
fn mut_pushed(&mut self) -> &mut Vec<T>
Returns a mutable reference to the current pushed (uncommitted) values.
Source§fn truncate_if_needed_at(&mut self, index: usize) -> Result<()>
fn truncate_if_needed_at(&mut self, index: usize) -> Result<()>
Truncates the vector to the given usize index if the current length exceeds it.
Source§fn reset_unsaved(&mut self)
fn reset_unsaved(&mut self)
Resets uncommitted changes.
Source§fn stamped_flush_with_changes(&mut self, stamp: Stamp) -> Result<()>
fn stamped_flush_with_changes(&mut self, stamp: Stamp) -> Result<()>
Flushes with the given stamp, saving changes to enable rollback.
Source§fn rollback_before(&mut self, stamp: Stamp) -> Result<Stamp>
fn rollback_before(&mut self, stamp: Stamp) -> Result<Stamp>
Rolls back changes to before the given stamp.
Source§fn deserialize_then_undo_changes(&mut self, bytes: &[u8]) -> Result<()>
fn deserialize_then_undo_changes(&mut self, bytes: &[u8]) -> Result<()>
Deserializes change data and undoes those changes.
Base implementation handles pushed and truncated data. RawVecInner overrides for holes/updated.
const SIZE_OF_T: usize = _
Source§fn create_reader(&self) -> Reader
fn create_reader(&self) -> Reader
Creates a reader to the underlying region.
Be careful with deadlocks - drop the reader before mutable ops.
Source§fn read(&self, index: I, reader: &Reader) -> Result<T>
fn read(&self, index: I, reader: &Reader) -> Result<T>
Reads value at index using provided reader.
Source§fn read_once(&self, index: I) -> Result<T>
fn read_once(&self, index: I) -> Result<T>
Reads value at index, creating a temporary reader.
For multiple reads, prefer
read() with a reused reader.Source§fn read_at(&self, index: usize, reader: &Reader) -> Result<T>
fn read_at(&self, index: usize, reader: &Reader) -> Result<T>
Reads value at usize index using provided reader.
Source§fn write_values_to(&self, values: &[T], buf: &mut Vec<u8>)
fn write_values_to(&self, values: &[T], buf: &mut Vec<u8>)
Writes multiple values to the provided buffer.
Source§fn read_at_once(&self, index: usize) -> Result<T>
fn read_at_once(&self, index: usize) -> Result<T>
Reads value at usize index, creating a temporary reader.
For multiple reads, prefer
read_at() with a reused reader.Source§fn read_unwrap(&self, index: I, reader: &Reader) -> T
fn read_unwrap(&self, index: I, reader: &Reader) -> T
Reads value at index using provided reader. Panics if read fails.
Source§fn read_unwrap_once(&self, index: I) -> T
fn read_unwrap_once(&self, index: I) -> T
Reads value at index, creating a temporary reader. Panics if read fails.
For multiple reads, prefer
read_unwrap() with a reused reader.Source§fn read_at_unwrap(&self, index: usize, reader: &Reader) -> T
fn read_at_unwrap(&self, index: usize, reader: &Reader) -> T
Reads value at usize index using provided reader. Panics if read fails.
Source§fn read_at_unwrap_once(&self, index: usize) -> T
fn read_at_unwrap_once(&self, index: usize) -> T
Reads value at usize index, creating a temporary reader. Panics if read fails.
For multiple reads, prefer
read_at_unwrap() with a reused reader.Source§fn get_pushed_or_read(&self, index: I, reader: &Reader) -> Result<Option<T>>
fn get_pushed_or_read(&self, index: I, reader: &Reader) -> Result<Option<T>>
Gets value from pushed layer or storage using provided reader.
Source§fn get_pushed_or_read_once(&self, index: I) -> Result<Option<T>>
fn get_pushed_or_read_once(&self, index: I) -> Result<Option<T>>
Gets value from pushed layer or storage, creating a temporary reader.
For multiple reads, prefer
get_pushed_or_read() with a reused reader.Source§fn get_pushed_or_read_unwrap(&self, index: I, reader: &Reader) -> T
fn get_pushed_or_read_unwrap(&self, index: I, reader: &Reader) -> T
Gets value from pushed layer or storage using provided reader, unwrapping the result.
Panics if the read fails or if the value doesn’t exist.
Source§fn get_pushed_or_read_unwrap_once(&self, index: I) -> T
fn get_pushed_or_read_unwrap_once(&self, index: I) -> T
Gets value from pushed layer or storage, unwrapping the result.
Panics if the read fails or if the value doesn’t exist.
For multiple reads, prefer
get_pushed_or_read_unwrap() with a reused reader.Source§fn get_pushed_or_read_at(
&self,
index: usize,
reader: &Reader,
) -> Result<Option<T>>
fn get_pushed_or_read_at( &self, index: usize, reader: &Reader, ) -> Result<Option<T>>
Gets value from pushed layer or storage at usize index using provided reader.
Does not check the updated layer.
Source§fn get_pushed_or_read_at_once(&self, index: usize) -> Result<Option<T>>
fn get_pushed_or_read_at_once(&self, index: usize) -> Result<Option<T>>
Gets value from pushed layer or storage at usize index, creating a temporary reader.
For multiple reads, prefer
get_pushed_or_read_at() with a reused reader.Source§fn get_pushed_or_read_at_unwrap(&self, index: usize, reader: &Reader) -> T
fn get_pushed_or_read_at_unwrap(&self, index: usize, reader: &Reader) -> T
Gets value from pushed layer or storage at usize index using provided reader, unwrapping the result.
Panics if the read fails or if the value doesn’t exist.
Source§fn get_pushed_or_read_at_unwrap_once(&self, index: usize) -> T
fn get_pushed_or_read_at_unwrap_once(&self, index: usize) -> T
Gets value from pushed layer or storage at usize index, unwrapping the result.
Panics if the read fails or if the value doesn’t exist.
For multiple reads, prefer
get_pushed_or_read_at_unwrap() with a reused reader.Source§fn get_pushed_at(&self, index: usize, stored_len: usize) -> Option<&T>
fn get_pushed_at(&self, index: usize, stored_len: usize) -> Option<&T>
Gets value from pushed layer only (no disk reads).
Source§fn len_(&self) -> usize
fn len_(&self) -> usize
Returns the length including both stored and pushed (uncommitted) values. Read more
Source§fn pushed_len(&self) -> usize
fn pushed_len(&self) -> usize
Returns the number of pushed (uncommitted) values in the memory buffer.
Source§fn is_pushed_empty(&self) -> bool
fn is_pushed_empty(&self) -> bool
Returns true if there are no pushed (uncommitted) values.
Source§fn push_if_needed(&mut self, index: I, value: T) -> Result<()>
fn push_if_needed(&mut self, index: I, value: T) -> Result<()>
Pushes a value if the index equals the current length, otherwise does nothing if already exists.
Returns an error if the index is too high.
Source§fn truncate_push(&mut self, index: I, value: T) -> Result<()>
fn truncate_push(&mut self, index: I, value: T) -> Result<()>
Pushes a value at the given index, truncating if necessary.
Source§fn truncate_push_at(&mut self, index: usize, value: T) -> Result<()>
fn truncate_push_at(&mut self, index: usize, value: T) -> Result<()>
Pushes a value at the given usize index, truncating if necessary.
Source§fn batch_limit_reached(&self) -> bool
fn batch_limit_reached(&self) -> bool
Returns true if the pushed cache has reached the batch limit (~1GiB). Read more
Source§fn truncate_if_needed(&mut self, index: I) -> Result<()>
fn truncate_if_needed(&mut self, index: I) -> Result<()>
Truncates the vector to the given index if the current length exceeds it.
Source§fn truncate_if_needed_with_stamp(
&mut self,
index: I,
stamp: Stamp,
) -> Result<()>
fn truncate_if_needed_with_stamp( &mut self, index: I, stamp: Stamp, ) -> Result<()>
Truncates the vector to the given index if needed, updating the stamp.
Source§fn validate_computed_version_or_reset(&mut self, version: Version) -> Result<()>
fn validate_computed_version_or_reset(&mut self, version: Version) -> Result<()>
Validates the computed version against the stored version, resetting if they don’t match.
Source§fn changes_path(&self) -> PathBuf
fn changes_path(&self) -> PathBuf
Returns the path to the changes directory for this vector.
Source§fn stamped_flush_maybe_with_changes(
&mut self,
stamp: Stamp,
with_changes: bool,
) -> Result<()>
fn stamped_flush_maybe_with_changes( &mut self, stamp: Stamp, with_changes: bool, ) -> Result<()>
Flushes with the given stamp, optionally saving changes for rollback.
Source§fn vec_region_name(&self) -> String
fn vec_region_name(&self) -> String
Returns the region name for this vector.
Source§impl<I, T> ImportableVec for ZstdVec<I, T>where
I: VecIndex,
T: ZstdVecValue,
impl<I, T> ImportableVec for ZstdVec<I, T>where
I: VecIndex,
T: ZstdVecValue,
Source§fn import(db: &Database, name: &str, version: Version) -> Result<Self>
fn import(db: &Database, name: &str, version: Version) -> Result<Self>
Import from database, creating if needed.
Source§fn import_with(options: ImportOptions<'_>) -> Result<Self>
fn import_with(options: ImportOptions<'_>) -> Result<Self>
Import with custom options.
Source§fn forced_import(db: &Database, name: &str, version: Version) -> Result<Self>
fn forced_import(db: &Database, name: &str, version: Version) -> Result<Self>
Import from database, resetting on version/format mismatch.
Source§fn forced_import_with(options: ImportOptions<'_>) -> Result<Self>
fn forced_import_with(options: ImportOptions<'_>) -> Result<Self>
Forced import with custom options.
Source§impl<'a, I, T> IntoIterator for &'a ZstdVec<I, T>where
I: VecIndex,
T: ZstdVecValue,
impl<'a, I, T> IntoIterator for &'a ZstdVec<I, T>where
I: VecIndex,
T: ZstdVecValue,
Source§impl<I, T> IterableVec<I, T> for ZstdVec<I, T>where
I: VecIndex,
T: ZstdVecValue,
impl<I, T> IterableVec<I, T> for ZstdVec<I, T>where
I: VecIndex,
T: ZstdVecValue,
fn iter(&self) -> BoxedVecIterator<'_, I, T>
Auto Trait Implementations§
impl<I, T> Freeze for ZstdVec<I, T>
impl<I, T> !RefUnwindSafe for ZstdVec<I, T>
impl<I, T> Send for ZstdVec<I, T>
impl<I, T> Sync for ZstdVec<I, T>
impl<I, T> Unpin for ZstdVec<I, T>
impl<I, T> !UnwindSafe for ZstdVec<I, T>
Blanket Implementations§
Source§impl<V> AnyCollectableVec for V
impl<V> AnyCollectableVec for V
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)Source§impl<I, T, V> CollectableVec<I, T> for V
impl<I, T, V> CollectableVec<I, T> for V
Source§fn iter_range(
&self,
from: Option<usize>,
to: Option<usize>,
) -> impl Iterator<Item = T>
fn iter_range( &self, from: Option<usize>, to: Option<usize>, ) -> impl Iterator<Item = T>
Returns an iterator over the specified range.
Source§fn iter_signed_range(
&self,
from: Option<i64>,
to: Option<i64>,
) -> impl Iterator<Item = T>
fn iter_signed_range( &self, from: Option<i64>, to: Option<i64>, ) -> impl Iterator<Item = T>
Returns an iterator over the specified range using signed indices (supports negative indexing).
Source§fn collect_range(&self, from: Option<usize>, to: Option<usize>) -> Vec<T>
fn collect_range(&self, from: Option<usize>, to: Option<usize>) -> Vec<T>
Collects values in the specified range into a Vec.
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more