Module aho_corasick::util::primitives

source ·
Expand description

Lower level primitive types that are useful in a variety of circumstances.

§Overview

This list represents the principle types in this module and briefly describes when you might want to use them.

  • PatternID - A type that represents the identifier of a regex pattern. This is probably the most widely used type in this module (which is why it’s also re-exported in the crate root).
  • StateID - A type the represents the identifier of a finite automaton state. This is used for both NFAs and DFAs, with the notable exception of the hybrid NFA/DFA. (The hybrid NFA/DFA uses a special purpose “lazy” state identifier.)
  • SmallIndex - The internal representation of both a PatternID and a StateID. Its purpose is to serve as a type that can index memory without being as big as a usize on 64-bit targets. The main idea behind this type is that there are many things in regex engines that will, in practice, never overflow a 32-bit integer. (For example, like the number of patterns in a regex or the number of states in an NFA.) Thus, a SmallIndex can be used to index memory without peppering as casts everywhere. Moreover, it forces callers to handle errors in the case where, somehow, the value would otherwise overflow either a 32-bit integer or a usize (e.g., on 16-bit targets).

Macros§

Structs§

  • The identifier of a pattern in an Aho-Corasick automaton.
  • This error occurs when an ID could not be constructed.
  • SmallIndex 🔒
    A type that represents a “small” index.
  • This error occurs when a small index could not be constructed.
  • The identifier of a finite automaton state.
  • This error occurs when an ID could not be constructed.
  • An iterator adapter that is like std::iter::Enumerate, but attaches small index values instead. It requires ExactSizeIterator. At construction, it ensures that the index of each element in the iterator is representable in the corresponding small index type.
  • An iterator adapter that is like std::iter::Enumerate, but attaches small index values instead. It requires ExactSizeIterator. At construction, it ensures that the index of each element in the iterator is representable in the corresponding small index type.

Traits§

  • A utility trait that defines a couple of adapters for making it convenient to access indices as “small index” types. We require ExactSizeIterator so that iterator construction can do a single check to make sure the index of each element is representable by its small index type.