1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
use crate::quotes::{QuoteClassifiedIterator, ResumeClassifierState};
use cfg_if::cfg_if;
#[allow(clippy::len_without_is_empty)]
pub trait DepthBlock<'a>: Sized {
fn add_depth(&mut self, depth: isize);
fn get_depth(&self) -> isize;
fn estimate_lowest_possible_depth(&self) -> isize;
fn depth_at_end(&self) -> isize;
fn advance_to_next_depth_decrease(&mut self) -> bool;
}
pub trait DepthIterator<'a, I: QuoteClassifiedIterator<'a>>:
Iterator<Item = Self::Block> + 'a
{
type Block: DepthBlock<'a>;
fn resume(state: ResumeClassifierState<'a, I>, opening: u8) -> (Option<Self::Block>, Self);
fn stop(self, block: Option<Self::Block>) -> ResumeClassifierState<'a, I>;
}
pub struct DepthIteratorResumeOutcome<'a, I: QuoteClassifiedIterator<'a>, D: DepthIterator<'a, I>>(
pub Option<D::Block>,
pub D,
);
cfg_if! {
if #[cfg(any(doc, not(feature = "simd")))] {
mod nosimd;
#[inline(always)]
pub fn classify_depth<'a, I: QuoteClassifiedIterator<'a>>(iter: I, opening: u8) -> impl DepthIterator<'a, I> {
nosimd::VectorIterator::new(iter, opening)
}
#[inline(always)]
pub fn resume_depth_classification<'a, I: QuoteClassifiedIterator<'a>>(
state: ResumeClassifierState<'a, I>, opening: u8
) -> DepthIteratorResumeOutcome<'a, I, impl DepthIterator<'a, I>> {
let (first_block, iter) = nosimd::VectorIterator::resume(state, opening);
DepthIteratorResumeOutcome(first_block, iter)
}
}
else if #[cfg(simd = "avx2")] {
mod avx2;
#[inline(always)]
pub fn classify_depth<'a, I: QuoteClassifiedIterator<'a>>(iter: I, opening: u8) -> impl DepthIterator<'a, I> {
avx2::VectorIterator::new(iter, opening)
}
#[inline(always)]
pub fn resume_depth_classification<'a, I: QuoteClassifiedIterator<'a>>(
state: ResumeClassifierState<'a, I>, opening: u8
) -> DepthIteratorResumeOutcome<'a, I, impl DepthIterator<'a, I>> {
let (first_block, iter) = avx2::VectorIterator::resume(state, opening);
DepthIteratorResumeOutcome(first_block, iter)
}
}
else {
compile_error!("Target architecture is not supported by SIMD features of this crate. Disable the default `simd` feature.");
}
}