1#[derive(Copy, Clone)]
12pub(crate) enum PhfMode {
13 BinaryOnly,
15 UsePhf,
17}
18
19impl PhfMode {
20 #[cfg(feature = "serde")]
21 const fn to_u8_flag(self) -> u8 {
22 match self {
23 Self::BinaryOnly => 0,
24 Self::UsePhf => 0x1,
25 }
26 }
27}
28
29#[derive(Copy, Clone)]
31pub(crate) enum AsciiMode {
32 AsciiOnly,
34 BinarySpans,
36}
37
38impl AsciiMode {
39 #[cfg(feature = "serde")]
40 const fn to_u8_flag(self) -> u8 {
41 match self {
42 Self::AsciiOnly => 0,
43 Self::BinarySpans => 0x2,
44 }
45 }
46}
47
48#[derive(Copy, Clone)]
50pub(crate) enum CapacityMode {
51 Normal,
53 Extended,
55}
56
57impl CapacityMode {
58 #[cfg(feature = "serde")]
59 const fn to_u8_flag(self) -> u8 {
60 match self {
61 Self::Normal => 0,
62 Self::Extended => 0x4,
63 }
64 }
65}
66
67#[derive(Copy, Clone)]
69pub(crate) enum CaseSensitivity {
70 Sensitive,
72 IgnoreCase,
74}
75
76impl CaseSensitivity {
77 #[cfg(feature = "serde")]
78 const fn to_u8_flag(self) -> u8 {
79 match self {
80 Self::Sensitive => 0,
81 Self::IgnoreCase => 0x8,
82 }
83 }
84}
85
86#[derive(Copy, Clone)]
87pub(crate) struct ZeroTrieBuilderOptions {
88 pub phf_mode: PhfMode,
89 pub ascii_mode: AsciiMode,
90 pub capacity_mode: CapacityMode,
91 pub case_sensitivity: CaseSensitivity,
92}
93
94impl ZeroTrieBuilderOptions {
95 #[cfg(feature = "serde")]
96 pub(crate) const fn to_u8_flags(self) -> u8 {
97 self.phf_mode.to_u8_flag()
98 | self.ascii_mode.to_u8_flag()
99 | self.capacity_mode.to_u8_flag()
100 | self.case_sensitivity.to_u8_flag()
101 }
102}
103
104pub(crate) trait ZeroTrieWithOptions {
105 const OPTIONS: ZeroTrieBuilderOptions;
106}
107
108impl<S: ?Sized> ZeroTrieWithOptions for crate::ZeroTrieSimpleAscii<S> {
111 const OPTIONS: ZeroTrieBuilderOptions = ZeroTrieBuilderOptions {
112 phf_mode: PhfMode::BinaryOnly,
113 ascii_mode: AsciiMode::AsciiOnly,
114 capacity_mode: CapacityMode::Normal,
115 case_sensitivity: CaseSensitivity::Sensitive,
116 };
117}
118
119impl<S: ?Sized> crate::ZeroTrieSimpleAscii<S> {
120 #[cfg(feature = "serde")]
121 pub(crate) const FLAGS: u8 = Self::OPTIONS.to_u8_flags();
122}
123
124impl<S: ?Sized> ZeroTrieWithOptions for crate::ZeroAsciiIgnoreCaseTrie<S> {
127 const OPTIONS: ZeroTrieBuilderOptions = ZeroTrieBuilderOptions {
128 phf_mode: PhfMode::BinaryOnly,
129 ascii_mode: AsciiMode::AsciiOnly,
130 capacity_mode: CapacityMode::Normal,
131 case_sensitivity: CaseSensitivity::IgnoreCase,
132 };
133}
134
135impl<S: ?Sized> ZeroTrieWithOptions for crate::ZeroTriePerfectHash<S> {
137 const OPTIONS: ZeroTrieBuilderOptions = ZeroTrieBuilderOptions {
138 phf_mode: PhfMode::UsePhf,
139 ascii_mode: AsciiMode::BinarySpans,
140 capacity_mode: CapacityMode::Normal,
141 case_sensitivity: CaseSensitivity::Sensitive,
142 };
143}
144
145impl<S: ?Sized> ZeroTrieWithOptions for crate::ZeroTrieExtendedCapacity<S> {
147 const OPTIONS: ZeroTrieBuilderOptions = ZeroTrieBuilderOptions {
148 phf_mode: PhfMode::UsePhf,
149 ascii_mode: AsciiMode::BinarySpans,
150 capacity_mode: CapacityMode::Extended,
151 case_sensitivity: CaseSensitivity::Sensitive,
152 };
153}