rsonpath/classification/depth/
shared.rs1#[cfg(target_arch = "x86")]
2pub(super) mod mask_32;
3#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
4pub(super) mod mask_64;
5#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
6pub(super) mod vector_128;
7#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
8pub(super) mod vector_256;
9#[cfg(target_arch = "x86_64")]
10pub(super) mod vector_512;
11#[cfg(target_arch = "aarch64")]
12pub(super) mod vector_neon;
13
14#[cfg(any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64"))]
15macro_rules! depth_classifier {
16 ($name:ident, $core:ident, $vector:ident, $size:literal, $mask_ty:ty) => {
17 pub(crate) struct Constructor;
18
19 impl DepthImpl for Constructor {
20 type Classifier<'i, I, Q>
21 = $name<'i, I, Q>
22 where
23 I: InputBlockIterator<'i, BLOCK_SIZE>,
24 Q: QuoteClassifiedIterator<'i, I, MaskType, BLOCK_SIZE>;
25 }
26
27 pub(crate) struct $name<'i, I, Q> {
28 iter: Q,
29 classifier: $core,
30 were_commas_on: bool,
31 were_colons_on: bool,
32 phantom: PhantomData<(&'i (), I)>,
33 }
34
35 impl<'a, I, Q> FallibleIterator for $name<'a, I, Q>
36 where
37 I: InputBlockIterator<'a, $size>,
38 Q: QuoteClassifiedIterator<'a, I, $mask_ty, $size>,
39 {
40 type Item = $vector<'a, I::Block>;
41 type Error = InputError;
42
43 #[inline(always)]
44 fn next(&mut self) -> Result<Option<Self::Item>, Self::Error> {
45 let quote_classified = self.iter.next()?;
46 Ok(quote_classified.map(|q| new_vector(q, &self.classifier)))
47 }
48 }
49
50 impl<'a, I, Q> DepthIterator<'a, I, Q, $mask_ty, $size> for $name<'a, I, Q>
51 where
52 I: InputBlockIterator<'a, $size>,
53 Q: QuoteClassifiedIterator<'a, I, $mask_ty, $size>,
54 {
55 type Block = $vector<'a, I::Block>;
56
57 #[inline(always)]
58 fn stop(self, block: Option<Self::Block>) -> ResumeClassifierState<'a, I, Q, $mask_ty, $size> {
59 let block_state = block.map(|b| {
60 let idx = b.idx;
61 debug!("Depth iterator stopping at index {idx}");
62 ResumeClassifierBlockState {
63 block: b.quote_classified,
64 idx,
65 }
66 });
67
68 ResumeClassifierState {
69 iter: self.iter,
70 block: block_state,
71 are_commas_on: self.were_commas_on,
72 are_colons_on: self.were_colons_on,
73 }
74 }
75
76 #[inline(always)]
77 fn resume(
78 state: ResumeClassifierState<'a, I, Q, $mask_ty, $size>,
79 opening: BracketType,
80 ) -> (Option<Self::Block>, Self) {
81 let classifier = $core::new(opening);
82 let first_block = state.block.and_then(|b| {
83 if b.idx == $size {
84 None
85 } else {
86 Some(new_vector_from(b.block, &classifier, b.idx))
87 }
88 });
89
90 (
91 first_block,
92 $name {
93 iter: state.iter,
94 classifier,
95 phantom: PhantomData,
96 were_commas_on: state.are_commas_on,
97 were_colons_on: state.are_colons_on,
98 },
99 )
100 }
101 }
102 };
103}
104
105#[cfg(any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64"))]
106pub(crate) use depth_classifier;