wedb_embed 0.1.0

Embedded Kvrocks-compatible storage engine for WeDb
Documentation
/// 键值对引用结构(对标 Apache Kvrocks StringPair)
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct StringPair<'a> {
    pub key: &'a [u8],
    pub value: &'a [u8],
}

impl<'a> StringPair<'a> {
    #[inline]
    pub fn new(key: &'a [u8], value: &'a [u8]) -> Self {
        Self { key, value }
    }
}

/// String SET 条件类型(对标 Apache Kvrocks StringSetType)
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum StringSetType {
    #[default]
    None,
    Nx,
    Xx,
    IfEq,
    IfNe,
    IfDeq,
    IfDne,
}

/// String SET 参数结构体(对标 Apache Kvrocks StringSetArgs)
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct StringSetArgs<'a> {
    pub expire: u64,
    pub set_type: StringSetType,
    pub get: bool,
    pub keep_ttl: bool,
    pub cmp_value: Option<&'a [u8]>,
}

impl<'a> Default for StringSetArgs<'a> {
    fn default() -> Self {
        Self {
            expire: 0,
            set_type: StringSetType::None,
            get: false,
            keep_ttl: false,
            cmp_value: None,
        }
    }
}

/// String SET 选项
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Set<'a> {
    Ex(u64),
    Px(u64),
    ExAt(u64),
    PxAt(u64),
    KeepTtl,
    Nx,
    Xx,
    IfEq(&'a [u8]),
    IfNe(&'a [u8]),
    IfDeq(&'a [u8]),
    IfDne(&'a [u8]),
    Get,
}

/// GETEX 选项
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GetEx {
    Ex(u64),
    Px(u64),
    ExAt(u64),
    PxAt(u64),
    Persist,
}

/// DELEX 选项(对标 Apache Kvrocks DelExOption)
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub enum DelEx<'a> {
    #[default]
    None,
    IfEq(&'a [u8]),
    IfNe(&'a [u8]),
    IfDeq(&'a [u8]),
    IfDne(&'a [u8]),
}

/// String MSET 参数结构体(对标 Apache Kvrocks StringMSetArgs)
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct StringMSetArgs {
    pub expire: u64,
    pub set_type: StringSetType,
    pub keep_ttl: bool,
}

/// LCS 选项类型(对标 Apache Kvrocks StringLCSType)
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum StringLCSType {
    #[default]
    None,
    Len,
    Idx,
}

/// LCS 参数结构体(对标 Apache Kvrocks StringLCSArgs)
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct StringLCSArgs {
    pub lcs_type: StringLCSType,
    pub min_match_len: i64,
}

impl Default for StringLCSArgs {
    fn default() -> Self {
        Self {
            lcs_type: StringLCSType::None,
            min_match_len: 0,
        }
    }
}

/// LCS 选项
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Lcs {
    Len,
    Idx,
    WithMatchLen,
    MinMatchLen(i64),
}

impl From<&[Lcs]> for StringLCSArgs {
    fn from(options: &[Lcs]) -> Self {
        let mut lcs_type = StringLCSType::None;
        let mut min_match_len = 0;
        for opt in options {
            match opt {
                Lcs::Len => lcs_type = StringLCSType::Len,
                Lcs::Idx | Lcs::WithMatchLen => lcs_type = StringLCSType::Idx,
                Lcs::MinMatchLen(len) => {
                    lcs_type = StringLCSType::Idx;
                    min_match_len = *len;
                }
            }
        }
        Self {
            lcs_type,
            min_match_len,
        }
    }
}

/// LCS 字符串子区间(对标 Apache Kvrocks StringLCSRange)
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct StringLCSRange {
    pub start: u32,
    pub end: u32,
}

/// LCS 匹配区间(对标 Apache Kvrocks StringLCSMatchedRange)
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct StringLCSMatchedRange {
    pub a: StringLCSRange,
    pub b: StringLCSRange,
    pub match_len: u32,
}

impl StringLCSMatchedRange {
    #[inline]
    pub const fn new(a_start: u32, a_end: u32, b_start: u32, b_end: u32, match_len: u32) -> Self {
        Self {
            a: StringLCSRange {
                start: a_start,
                end: a_end,
            },
            b: StringLCSRange {
                start: b_start,
                end: b_end,
            },
            match_len,
        }
    }

    #[inline]
    pub const fn a_start(&self) -> u32 {
        self.a.start
    }

    #[inline]
    pub const fn a_end(&self) -> u32 {
        self.a.end
    }

    #[inline]
    pub const fn b_start(&self) -> u32 {
        self.b.start
    }

    #[inline]
    pub const fn b_end(&self) -> u32 {
        self.b.end
    }
}

/// LCS 索引结果(对标 Apache Kvrocks StringLCSIdxResult)
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct StringLCSIdxResult {
    pub matches: Vec<StringLCSMatchedRange>,
    pub len: u32,
}

/// LCS 综合结果(对标 Apache Kvrocks StringLCSResult)
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum StringLCSResult {
    Str(String),
    Len(u32),
    Idx(StringLCSIdxResult),
}