wedb_embed 0.1.0

Embedded Kvrocks-compatible storage engine for WeDb
Documentation
use serde::{Deserialize, Serialize};

/// 默认压缩因子
pub const DEFAULT_COMPRESSION: u32 = 100;
/// 最小压缩因子
pub const MIN_COMPRESSION: u32 = 1;
/// 最大压缩因子
pub const MAX_COMPRESSION: u32 = 1000;
/// 最小缓冲区容量
pub const MIN_CAPACITY: usize = 64;
/// 最大缓冲区容量
pub const MAX_CAPACITY: usize = 1024;

/// 计算缓冲区容量 (对标 Apache Kvrocks std::min(compression * 6 + 10, 1024))
#[inline]
pub const fn calculate_capacity(compression: u32) -> usize {
    let cap = compression as usize * 6 + 10;
    if cap > MAX_CAPACITY {
        MAX_CAPACITY
    } else {
        cap
    }
}

/// TDIGEST.CREATE 命令选项
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub struct TDigestCreate {
    pub compression: u32,
}

impl Default for TDigestCreate {
    #[inline]
    fn default() -> Self {
        Self {
            compression: DEFAULT_COMPRESSION,
        }
    }
}

/// TDIGEST.MERGE 命令选项
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
pub struct TDigestMerge {
    pub compression: Option<u32>,
    pub override_dest: bool,
}

/// TDIGEST.INFO 命令响应信息(对标 Apache Kvrocks TDigestMetadata & TDIGEST.INFO)
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct TDigestInfo {
    pub compression: u32,
    pub capacity: usize,
    pub merged_nodes: usize,
    pub unmerged_nodes: usize,
    pub merged_weight: f64,
    pub unmerged_weight: f64,
    pub total_weight: f64,
    pub observations: u64,
    pub total_compressions: u64,
    pub minimum: Option<f64>,
    pub maximum: Option<f64>,
}