1 | use crate::util::primitives::StateID; |
2 | |
3 | /// A collection of sentinel state IDs for Aho-Corasick automata. |
4 | /// |
5 | /// This specifically enables the technique by which we determine which states |
6 | /// are dead, matches or start states. Namely, by arranging states in a |
7 | /// particular order, we can determine the type of a state simply by looking at |
8 | /// its ID. |
9 | #[derive (Clone, Debug)] |
10 | pub(crate) struct Special { |
11 | /// The maximum ID of all the "special" states. This corresponds either to |
12 | /// start_anchored_id when a prefilter is active and max_match_id when a |
13 | /// prefilter is not active. The idea here is that if there is no prefilter, |
14 | /// then there is no point in treating start states as special. |
15 | pub(crate) max_special_id: StateID, |
16 | /// The maximum ID of all the match states. Any state ID bigger than this |
17 | /// is guaranteed to be a non-match ID. |
18 | /// |
19 | /// It is possible and legal for max_match_id to be equal to |
20 | /// start_anchored_id, which occurs precisely in the case where the empty |
21 | /// string is a pattern that was added to the underlying automaton. |
22 | pub(crate) max_match_id: StateID, |
23 | /// The state ID of the start state used for unanchored searches. |
24 | pub(crate) start_unanchored_id: StateID, |
25 | /// The state ID of the start state used for anchored searches. This is |
26 | /// always start_unanchored_id+1. |
27 | pub(crate) start_anchored_id: StateID, |
28 | } |
29 | |
30 | impl Special { |
31 | /// Create a new set of "special" state IDs with all IDs initialized to |
32 | /// zero. The general idea here is that they will be updated and set to |
33 | /// correct values later. |
34 | pub(crate) fn zero() -> Special { |
35 | Special { |
36 | max_special_id: StateID::ZERO, |
37 | max_match_id: StateID::ZERO, |
38 | start_unanchored_id: StateID::ZERO, |
39 | start_anchored_id: StateID::ZERO, |
40 | } |
41 | } |
42 | } |
43 | |