wedb_embed 0.1.1

Embedded database engine providing Redis-like APIs, built on fjall / 嵌入式数据库引擎,提供类似 Redis 的接口,底层基于 fjall 开发
Documentation
/// 默认压缩因子
pub const DEFAULT_COMPRESSION: u32 = 100;
/// 最小压缩因子
pub const MIN_COMPRESSION: u32 = 1;
/// 最大压缩因子
pub const MAX_COMPRESSION: u32 = 1000;
/// 最大缓冲区容量
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, bitcode::Encode, bitcode::Decode)]
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, bitcode::Encode, bitcode::Decode)]
pub struct TDigestMerge {
    pub compression: Option<u32>,
    pub override_dest: bool,
}

/// TDIGEST.INFO 命令响应信息(对标 Apache Kvrocks TDigestMetadata & TDIGEST.INFO)
#[derive(Debug, Clone, PartialEq, bitcode::Encode, bitcode::Decode)]
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>,
}