pipecircuit 0.0.24

Correct. Robust. Fast. Portable. Pick four.
Documentation
use super::PreparedSecondaryIndexRemove;
use crate::storage::{IndexKey, warp_table::secondary_index::StableSlot};
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum SecondaryIndexInsertError<SecondaryKey> {
    AlreadyPresent {
        secondary_key: SecondaryKey,
        slot: StableSlot,
    },
    Full {
        secondary_key: SecondaryKey,
        slot: StableSlot,
        maximum_distinct_keys: usize,
    },
    Inconsistent {
        secondary_key: SecondaryKey,
        slot: StableSlot,
        reason: SecondaryIndexInconsistency,
    },
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[must_use]
pub enum SecondaryIndexInsertOutcome<SecondaryKey> {
    CreatedBucket {
        secondary_key: SecondaryKey,
        slot: StableSlot,
    },
    AddedToBucket {
        secondary_key: SecondaryKey,
        slot: StableSlot,
    },
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum SecondaryIndexRemoveError<SecondaryKey> {
    Inconsistent {
        secondary_key: SecondaryKey,
        slot: StableSlot,
        reason: SecondaryIndexInconsistency,
    },
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[must_use]
pub enum SecondaryIndexRemoveOutcome<SecondaryKey> {
    RemovedFromBucket {
        secondary_key: SecondaryKey,
        slot: StableSlot,
        remaining_slots: u64,
    },
    RemovedBucket {
        secondary_key: SecondaryKey,
        slot: StableSlot,
    },
    BucketAbsent {
        secondary_key: SecondaryKey,
        slot: StableSlot,
    },
    SlotAbsent {
        secondary_key: SecondaryKey,
        slot: StableSlot,
    },
}

pub type SecondaryIndexRemoveResult<SecondaryKey> =
    Result<SecondaryIndexRemoveOutcome<SecondaryKey>, SecondaryIndexRemoveError<SecondaryKey>>;

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[must_use]
pub enum SecondaryIndexCommitRemoveOutcome<SecondaryKey> {
    RemovedFromBucket {
        secondary_key: SecondaryKey,
        slot: StableSlot,
        remaining_slots: u64,
    },
    RemovedBucket {
        secondary_key: SecondaryKey,
        slot: StableSlot,
    },
}

#[must_use]
#[allow(
    clippy::large_enum_variant,
    reason = "bounded traversal and preparation stay inline without allocating"
)]
pub enum SecondaryIndexPrepareRemoveOutcome<'index, SecondaryKey: IndexKey> {
    Prepared(PreparedSecondaryIndexRemove<'index, SecondaryKey>),
    BucketAbsent {
        secondary_key: SecondaryKey,
        slot: StableSlot,
    },
    SlotAbsent {
        secondary_key: SecondaryKey,
        slot: StableSlot,
    },
}

#[derive(Debug)]
pub enum SecondaryIndexMoveError<SecondaryKey> {
    SourceBucketAbsent {
        source: SecondaryKey,
        target: SecondaryKey,
        slot: StableSlot,
    },
    SourceSlotAbsent {
        source: SecondaryKey,
        target: SecondaryKey,
        slot: StableSlot,
    },
    TargetSlotAlreadyPresent {
        source: SecondaryKey,
        target: SecondaryKey,
        slot: StableSlot,
    },
    Full {
        source: SecondaryKey,
        target: SecondaryKey,
        slot: StableSlot,
        maximum_distinct_keys: usize,
    },
    Inconsistent {
        source: SecondaryKey,
        target: SecondaryKey,
        slot: StableSlot,
        reason: SecondaryIndexInconsistency,
    },
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[must_use]
pub enum SecondaryIndexMoveOutcome<SecondaryKey> {
    Unchanged {
        secondary_key: SecondaryKey,
        slot: StableSlot,
    },
    MovedBetweenExistingBuckets {
        source: SecondaryKey,
        target: SecondaryKey,
        slot: StableSlot,
    },
    MovedAndRemovedSourceBucket {
        source: SecondaryKey,
        target: SecondaryKey,
        slot: StableSlot,
    },
    MovedAndCreatedTargetBucket {
        source: SecondaryKey,
        target: SecondaryKey,
        slot: StableSlot,
    },
    RenamedBucket {
        source: SecondaryKey,
        target: SecondaryKey,
        slot: StableSlot,
    },
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum SecondaryIndexInconsistency {
    Membership(crate::storage::membership::MembershipIndexError),
    KeySlotSetLengthMismatch {
        secondary_keys: usize,
        slot_sets: usize,
    },
    SlotSetUnavailable {
        row: usize,
    },
    BucketUnavailable {
        bucket: usize,
    },
    StoredRowUnrepresentable {
        stored_row: u32,
    },
    KeyUnavailable {
        row: usize,
    },
    StoredRowMismatch {
        expected: usize,
        actual: usize,
    },
    ProbeLimitReached,
    InsertRowUnrepresentable {
        bucket: usize,
        row: usize,
    },
    InsertRowReserved {
        bucket: usize,
        row: usize,
    },
    InsertVacancyUnavailable {
        bucket: usize,
        row: usize,
    },
    InsertVacancyOccupied {
        bucket: usize,
        row: usize,
        occupying_row: u32,
    },
    EmptySlotSet {
        row: usize,
    },
    PreparedRemovalAbsent {
        row: usize,
    },
    PreparedRemovalRowMismatch {
        found_row: usize,
        prepared_row: usize,
    },
    PreparedReplacementUnexpected {
        row: usize,
    },
}