#[cfg(feature = "secondary-indexes")]
use super::query::WorkspaceSelectionError;
use crate::storage::query_workspace::{QueryChunk, QueryWorkspace, WorkspaceMembership};
mod assignment;
pub struct BulkUpdateWorkspace<Chunks, Scratch, Pending, Group, Slots> {
pub(in crate::storage::warp_table) query: QueryWorkspace<Chunks, Scratch>,
pub(in crate::storage::warp_table) pending: Pending,
pub(in crate::storage::warp_table) group: Group,
pub(in crate::storage::warp_table) slots: Slots,
}
impl<Chunks, Scratch, Pending, Group, Slots>
BulkUpdateWorkspace<Chunks, Scratch, Pending, Group, Slots>
{
pub const fn new(
query: QueryWorkspace<Chunks, Scratch>,
pending: Pending,
group: Group,
slots: Slots,
) -> Self {
Self {
query,
pending,
group,
slots,
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum BulkUpdateError {
#[cfg(feature = "secondary-indexes")]
Selection(WorkspaceSelectionError),
InsufficientStorage {
required: usize,
available: usize,
},
}
#[cfg(feature = "secondary-indexes")]
impl From<WorkspaceSelectionError> for BulkUpdateError {
fn from(reason: WorkspaceSelectionError) -> Self {
Self::Selection(reason)
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[must_use]
pub enum BulkSetOutcome {
Unchanged { selected: u64 },
Updated { selected: u64, changed: u64 },
}
#[doc(hidden)]
pub struct BulkSelection<'update> {
pub(in crate::storage::warp_table) selected: &'update WorkspaceMembership<'update>,
pub(in crate::storage::warp_table) pending: &'update mut QueryChunk,
pub(in crate::storage::warp_table) group: &'update mut QueryChunk,
pub(in crate::storage::warp_table) slots: &'update mut [u16],
}
impl BulkSelection<'_> {
pub fn set_membership<Key, Keys, Backing, Slots>(
&mut self,
index: &mut crate::storage::membership::KeyedMemberships<Key, Keys, Backing>,
column: &mut [Key],
stable_slots: &crate::storage::warp_table::stable_slots::StableSlots<Slots>,
target: Key,
) -> Result<BulkSetOutcome, BulkUpdateError>
where
Key: crate::storage::IndexKey,
Keys: crate::storage::membership::MembershipKeys<Key>,
Backing: crate::storage::membership::MembershipBacking,
Slots: crate::storage::warp_table::stable_slots::StableSlotsBacking,
{
assignment::set_column_selection(index, column, stable_slots, target, self)
}
}