#[derive(Copy, Clone)]
pub(crate) enum PhfMode {
BinaryOnly,
UsePhf,
}
impl PhfMode {
#[cfg(feature = "serde")]
const fn to_u8_flag(self) -> u8 {
match self {
Self::BinaryOnly => 0,
Self::UsePhf => 0x1,
}
}
}
#[derive(Copy, Clone)]
pub(crate) enum AsciiMode {
AsciiOnly,
BinarySpans,
}
impl AsciiMode {
#[cfg(feature = "serde")]
const fn to_u8_flag(self) -> u8 {
match self {
Self::AsciiOnly => 0,
Self::BinarySpans => 0x2,
}
}
}
#[derive(Copy, Clone)]
pub(crate) enum CapacityMode {
Normal,
Extended,
}
impl CapacityMode {
#[cfg(feature = "serde")]
const fn to_u8_flag(self) -> u8 {
match self {
Self::Normal => 0,
Self::Extended => 0x4,
}
}
}
#[derive(Copy, Clone)]
pub(crate) enum CaseSensitivity {
Sensitive,
IgnoreCase,
}
impl CaseSensitivity {
#[cfg(feature = "serde")]
const fn to_u8_flag(self) -> u8 {
match self {
Self::Sensitive => 0,
Self::IgnoreCase => 0x8,
}
}
}
#[derive(Copy, Clone)]
pub(crate) struct ZeroTrieBuilderOptions {
pub phf_mode: PhfMode,
pub ascii_mode: AsciiMode,
pub capacity_mode: CapacityMode,
pub case_sensitivity: CaseSensitivity,
}
impl ZeroTrieBuilderOptions {
#[cfg(feature = "serde")]
const fn to_u8_flags(self) -> u8 {
self.phf_mode.to_u8_flag()
| self.ascii_mode.to_u8_flag()
| self.capacity_mode.to_u8_flag()
| self.case_sensitivity.to_u8_flag()
}
}
pub(crate) trait ZeroTrieWithOptions {
const OPTIONS: ZeroTrieBuilderOptions;
}
impl<S: ?Sized> ZeroTrieWithOptions for crate::ZeroTrieSimpleAscii<S> {
const OPTIONS: ZeroTrieBuilderOptions = ZeroTrieBuilderOptions {
phf_mode: PhfMode::BinaryOnly,
ascii_mode: AsciiMode::AsciiOnly,
capacity_mode: CapacityMode::Normal,
case_sensitivity: CaseSensitivity::Sensitive,
};
}
impl<S: ?Sized> crate::ZeroTrieSimpleAscii<S> {
#[cfg(feature = "serde")]
pub(crate) const FLAGS: u8 = Self::OPTIONS.to_u8_flags();
}
impl<S: ?Sized> ZeroTrieWithOptions for crate::ZeroAsciiIgnoreCaseTrie<S> {
const OPTIONS: ZeroTrieBuilderOptions = ZeroTrieBuilderOptions {
phf_mode: PhfMode::BinaryOnly,
ascii_mode: AsciiMode::AsciiOnly,
capacity_mode: CapacityMode::Normal,
case_sensitivity: CaseSensitivity::IgnoreCase,
};
}
impl<S: ?Sized> crate::ZeroAsciiIgnoreCaseTrie<S> {
#[cfg(feature = "serde")]
pub(crate) const FLAGS: u8 = Self::OPTIONS.to_u8_flags();
}
impl<S: ?Sized> ZeroTrieWithOptions for crate::ZeroTriePerfectHash<S> {
const OPTIONS: ZeroTrieBuilderOptions = ZeroTrieBuilderOptions {
phf_mode: PhfMode::UsePhf,
ascii_mode: AsciiMode::BinarySpans,
capacity_mode: CapacityMode::Normal,
case_sensitivity: CaseSensitivity::Sensitive,
};
}
impl<S: ?Sized> crate::ZeroTriePerfectHash<S> {
#[cfg(feature = "serde")]
pub(crate) const FLAGS: u8 = Self::OPTIONS.to_u8_flags();
}
impl<S: ?Sized> ZeroTrieWithOptions for crate::ZeroTrieExtendedCapacity<S> {
const OPTIONS: ZeroTrieBuilderOptions = ZeroTrieBuilderOptions {
phf_mode: PhfMode::UsePhf,
ascii_mode: AsciiMode::BinarySpans,
capacity_mode: CapacityMode::Extended,
case_sensitivity: CaseSensitivity::Sensitive,
};
}
impl<S: ?Sized> crate::ZeroTrieExtendedCapacity<S> {
#[cfg(feature = "serde")]
pub(crate) const FLAGS: u8 = Self::OPTIONS.to_u8_flags();
}