pub struct VersionChain<T> { /* private fields */ }Expand description
A chain of versions for a single entity.
Versions are stored newest-first for efficient access to recent versions. Old versions can be garbage collected when no active transactions can see them.
Implementations§
Source§impl<T> VersionChain<T>
impl<T> VersionChain<T>
Sourcepub fn new() -> VersionChain<T>
pub fn new() -> VersionChain<T>
Creates a new empty version chain.
Sourcepub fn with_initial(
data: T,
created_epoch: EpochId,
created_by: TxId,
) -> VersionChain<T>
pub fn with_initial( data: T, created_epoch: EpochId, created_by: TxId, ) -> VersionChain<T>
Creates a version chain with an initial version.
Sourcepub fn add_version(&mut self, data: T, created_epoch: EpochId, created_by: TxId)
pub fn add_version(&mut self, data: T, created_epoch: EpochId, created_by: TxId)
Adds a new version to the chain.
The new version becomes the head of the chain.
Sourcepub fn visible_at(&self, epoch: EpochId) -> Option<&T>
pub fn visible_at(&self, epoch: EpochId) -> Option<&T>
Finds the version visible at the given epoch.
Returns a reference to the visible version’s data, or None if no version
is visible at that epoch.
Sourcepub fn visible_to(&self, epoch: EpochId, tx: TxId) -> Option<&T>
pub fn visible_to(&self, epoch: EpochId, tx: TxId) -> Option<&T>
Finds the version visible to a specific transaction.
This considers both the transaction’s epoch and its own uncommitted changes.
Sourcepub fn mark_deleted(&mut self, delete_epoch: EpochId) -> bool
pub fn mark_deleted(&mut self, delete_epoch: EpochId) -> bool
Marks the current visible version as deleted.
Returns true if a version was marked, false if no visible version exists.
Sourcepub fn modified_by(&self, tx: TxId) -> bool
pub fn modified_by(&self, tx: TxId) -> bool
Checks if any version was modified by the given transaction.
Sourcepub fn remove_versions_by(&mut self, tx: TxId)
pub fn remove_versions_by(&mut self, tx: TxId)
Removes all versions created by the given transaction.
Used for rollback to discard uncommitted changes.
Sourcepub fn has_conflict(&self, start_epoch: EpochId, our_tx: TxId) -> bool
pub fn has_conflict(&self, start_epoch: EpochId, our_tx: TxId) -> bool
Checks if there’s a concurrent modification conflict.
A conflict exists if another transaction modified this entity after our start epoch.
Sourcepub fn version_count(&self) -> usize
pub fn version_count(&self) -> usize
Returns the number of versions in the chain.
Sourcepub fn gc(&mut self, min_epoch: EpochId)
pub fn gc(&mut self, min_epoch: EpochId)
Garbage collects old versions that are no longer visible to any transaction.
Keeps versions that might still be visible to transactions at or after min_epoch.
Sourcepub fn latest(&self) -> Option<&T>
pub fn latest(&self) -> Option<&T>
Returns a reference to the latest version’s data regardless of visibility.
Sourcepub fn latest_mut(&mut self) -> Option<&mut T>
pub fn latest_mut(&mut self) -> Option<&mut T>
Returns a mutable reference to the latest version’s data.
Source§impl<T> VersionChain<T>where
T: Clone,
impl<T> VersionChain<T>where
T: Clone,
Trait Implementations§
Source§impl<T> Clone for VersionChain<T>where
T: Clone,
impl<T> Clone for VersionChain<T>where
T: Clone,
Source§fn clone(&self) -> VersionChain<T>
fn clone(&self) -> VersionChain<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more