use std::sync::Arc;
use uqa_core::memory::BudgetedVec;
use crate::mvcc::overlay::run::SpilledRun;
use super::cursor::PreparedWriteCursor;
use super::PreparedRecordWrite;
pub(in crate::mvcc) enum PreparedWrites {
Resident(BudgetedVec<PreparedRecordWrite>),
Spilled(Arc<SpilledRun>),
}
impl PreparedWrites {
pub(in crate::mvcc) fn len(&self) -> usize {
match self {
Self::Resident(writes) => writes.len(),
Self::Spilled(run) => usize::try_from(run.len()).unwrap_or(usize::MAX),
}
}
pub(in crate::mvcc) fn cursor(&self) -> PreparedWriteCursor<'_> {
match self {
Self::Resident(writes) => PreparedWriteCursor::resident(writes),
Self::Spilled(run) => PreparedWriteCursor::spilled(run),
}
}
pub(in crate::mvcc) fn typed(&self) -> bool {
match self {
Self::Resident(writes) => writes
.iter()
.any(|write| write.kind() != super::RecordWriteKind::Canonical),
Self::Spilled(run) => run.typed(),
}
}
}