mindb 0.1.2

Lightweight embedded key–value store with write-ahead log and zstd compression.
Documentation
//! In-memory and on-disk index structures used by MindB.
//!
//! The index subsystem is split into three layers:
//!   * [`hot`] for the lock-free hash index that tracks the latest versions.
//!   * [`sparse`] and [`bloom`] for segment-local accelerators.
//!   * [`secondary`] for auxiliary lookups such as slugs or full-text search.
#![allow(dead_code)]

pub mod bloom;
pub mod hot;
pub mod secondary;
pub mod sparse;

/// Identifier of a record inside MindB.
pub type RecordId = u64;

/// Sequence number attached to a version written by the MVCC machinery.
pub type SequenceNumber = u64;

/// Pointer describing where a value for a key can be retrieved.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct VersionPointer {
    /// Unique identifier assigned by the write path.
    pub record_id: RecordId,
    /// Monotonically increasing MVCC sequence number.
    pub sequence: SequenceNumber,
    /// Location of the payload.
    pub location: VersionLocation,
    /// Whether this version marks the key as deleted.
    pub tombstone: bool,
    /// Optional timestamp that can be used by range queries.
    pub timestamp: Option<i64>,
}

impl VersionPointer {
    /// Checks whether the version is visible under the provided snapshot.
    pub fn is_visible_at(&self, snapshot: SequenceNumber) -> bool {
        self.sequence <= snapshot && !self.tombstone
    }
}

/// Location variants for an indexed version.
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum VersionLocation {
    /// The value still lives in the in-memory memtable.
    MemTable,
    /// The value resides in an immutable on-disk segment at the given offset.
    Segment {
        /// Identifier of the segment file.
        segment_id: String,
        /// Byte offset where the record begins inside the segment.
        offset: u64,
        /// Length in bytes of the serialized record.
        length: u32,
    },
}