#[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 }
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum StringSetType {
#[default]
None,
Nx,
Xx,
IfEq,
IfNe,
IfDeq,
IfDne,
}
#[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,
}
}
}
#[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,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GetEx {
Ex(u64),
Px(u64),
ExAt(u64),
PxAt(u64),
Persist,
}
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub enum DelEx<'a> {
#[default]
None,
IfEq(&'a [u8]),
IfNe(&'a [u8]),
IfDeq(&'a [u8]),
IfDne(&'a [u8]),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct StringMSetArgs {
pub expire: u64,
pub set_type: StringSetType,
pub keep_ttl: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum StringLCSType {
#[default]
None,
Len,
Idx,
}
#[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,
}
}
}
#[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,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct StringLCSRange {
pub start: u32,
pub end: u32,
}
#[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
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct StringLCSIdxResult {
pub matches: Vec<StringLCSMatchedRange>,
pub len: u32,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum StringLCSResult {
Str(String),
Len(u32),
Idx(StringLCSIdxResult),
}