rsonpath/classification/
memmem.rs

1//! Classification ignoring the structure of the JSON and looking for the occurrence
2//! of a specific member name as quickly as possible.
3use crate::{
4    input::{error::InputError, Input},
5    result::InputRecorder,
6    string_pattern::StringPattern,
7    BLOCK_SIZE,
8};
9
10/// Classifier that can quickly find a member name in a byte stream.
11pub trait Memmem<'i, 'b, 'r, I: Input, const N: usize> {
12    /// Find a member key identified by a given [`StringPattern`].
13    ///
14    /// - `first_block` &ndash; optional first block to search; if not provided,
15    ///    the search will start at the next block returned by the underlying [`Input`] iterator.
16    /// - `start_idx` &ndash; index of the start of search, either falling inside `first_block`,
17    ///    or at the start of the next block.
18    ///
19    /// # Errors
20    /// Errors when reading the underlying [`Input`] are propagated.
21    fn find_label(
22        &mut self,
23        first_block: Option<I::Block<'i, N>>,
24        start_idx: usize,
25        label: &StringPattern,
26    ) -> Result<Option<(usize, I::Block<'i, N>)>, InputError>;
27}
28
29pub(crate) mod nosimd;
30pub(crate) mod shared;
31
32#[cfg(target_arch = "x86")]
33pub(crate) mod avx2_32;
34#[cfg(target_arch = "x86_64")]
35pub(crate) mod avx2_64;
36#[cfg(target_arch = "x86")]
37pub(crate) mod sse2_32;
38#[cfg(target_arch = "x86_64")]
39pub(crate) mod sse2_64;
40
41pub(crate) trait MemmemImpl {
42    type Classifier<'i, 'b, 'r, I, R>: Memmem<'i, 'b, 'r, I, BLOCK_SIZE>
43    where
44        I: Input + 'i,
45        <I as Input>::BlockIterator<'i, 'r, R, BLOCK_SIZE>: 'b,
46        R: InputRecorder<<I as Input>::Block<'i, BLOCK_SIZE>> + 'r,
47        'i: 'r;
48
49    fn memmem<'i, 'b, 'r, I, R>(
50        input: &'i I,
51        iter: &'b mut <I as Input>::BlockIterator<'i, 'r, R, BLOCK_SIZE>,
52    ) -> Self::Classifier<'i, 'b, 'r, I, R>
53    where
54        I: Input,
55        R: InputRecorder<<I as Input>::Block<'i, BLOCK_SIZE>>,
56        'i: 'r;
57}