<main><divclass="width-limiter"><navclass="sub"><formclass="search-form"><span></span><divid="sidebar-button"tabindex="-1"><ahref="../../../regex_automata/all.html"title="show sidebar"></a></div><inputclass="search-input"name="search"aria-label="Run search in the documentation"autocomplete="off"spellcheck="false"placeholder="Click or press ‘S’ to search, ‘?’ for more options…"type="search"><divid="help-button"tabindex="-1"><ahref="../../../help.html"title="help">?</a></div><divid="settings-menu"tabindex="-1"><ahref="../../../settings.html"title="settings"><imgwidth="22"height="22"alt="Change settings"src="../../../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><sectionid="main-content"class="content"><divclass="main-heading"><h1>Struct <ahref="../../index.html">regex_automata</a>::<wbr><ahref="../index.html">util</a>::<wbr><ahref="index.html">alphabet</a>::<wbr><aclass="struct"href="#">ByteClasses</a><buttonid="copy-path"title="Copy item path to clipboard"><imgsrc="../../../static.files/clipboard-7571035ce49a181d.svg"width="19"height="18"alt="Copy item path"></button></h1><spanclass="out-of-band"><aclass="src"href="../../../src/regex_automata/util/alphabet.rs.html#215">source</a> · <buttonid="toggle-all-docs"title="collapse all docs">[<span>−</span>]</button></span></div><preclass="rust item-decl"><code>pub struct ByteClasses(<spanclass="comment">/* private fields */</span>);</code></pre><detailsclass="toggle top-doc"open><summaryclass="hideme"><span>Expand description</span></summary><divclass="docblock"><p>A representation of byte oriented equivalence classes.</p>
<p>This is used in a DFA to reduce the size of the transition table. This can
have a particularly large impact not only on the total size of a dense DFA,
but also on compile times.</p>
<p>The essential idea here is that the alphabet of a DFA is shrunk from the
usual 256 distinct byte values down to a set of equivalence classes. The
guarantee you get is that any byte belonging to the same equivalence class
can be treated as if it were any other byte in the same class, and the
<p>This example shows how to get byte classes from an
<ahref="../../nfa/thompson/struct.NFA.html"title="struct regex_automata::nfa::thompson::NFA"><code>NFA</code></a> and ask for the class of various bytes.</p>
</div></details><h2id="implementations"class="section-header">Implementations<ahref="#implementations"class="anchor">§</a></h2><divid="implementations-list"><detailsclass="toggle implementors-toggle"open><summary><sectionid="impl-ByteClasses"class="impl"><aclass="src rightside"href="../../../src/regex_automata/util/alphabet.rs.html#217-483">source</a><ahref="#impl-ByteClasses"class="anchor">§</a><h3class="code-header">impl <aclass="struct"href="struct.ByteClasses.html"title="struct regex_automata::util::alphabet::ByteClasses">ByteClasses</a></h3></section></summary><divclass="impl-items"><detailsclass="toggle method-toggle"open><summary><sectionid="method.empty"class="method"><aclass="src rightside"href="../../../src/regex_automata/util/alphabet.rs.html#221-223">source</a><h4class="code-header">pub fn <ahref="#method.empty"class="fn">empty</a>() -><aclass="struct"href="struct.ByteClasses.html"title="struct regex_automata::util::alphabet::ByteClasses">ByteClasses</a></h4></section></summary><divclass="docblock"><p>Creates a new set of equivalence classes where all bytes are mapped to
the same class.</p>
</div></details><detailsclass="toggle method-toggle"open><summary><sectionid="method.singletons"class="method"><aclass="src rightside"href="../../../src/regex_automata/util/alphabet.rs.html#228-234">source</a><h4class="code-header">pub fn <ahref="#method.singletons"class="fn">singletons</a>() -><aclass="struct"href="struct.ByteClasses.html"title="struct regex_automata::util::alphabet::ByteClasses">ByteClasses</a></h4></section></summary><divclass="docblock"><p>Creates a new set of equivalence classes where each byte belongs to
its own equivalence class.</p>
</div></details><detailsclass="toggle method-toggle"open><summary><sectionid="method.set"class="method"><aclass="src rightside"href="../../../src/regex_automata/util/alphabet.rs.html#288-290">source</a><h4class="code-header">pub fn <ahref="#method.set"class="fn">set</a>(&mut self, byte: <aclass="primitive"href="https://doc.rust-lang.org/1.76.0/std/primitive.u8.html">u8</a>, class: <aclass="primitive"href="https://doc.rust-lang.org/1.76.0/std/primitive.u8.html">u8</a>)</h4></section></summary><divclass="docblock"><p>Set the equivalence class for the given byte.</p>
</div></details><detailsclass="toggle method-toggle"open><summary><sectionid="method.get"class="method"><aclass="src rightside"href="../../../src/regex_automata/util/alphabet.rs.html#294-296">source</a><h4class="code-header">pub fn <ahref="#method.get"class="fn">get</a>(&self, byte: <aclass="primitive"href="https://doc.rust-lang.org/1.76.0/std/primitive.u8.html">u8</a>) -><aclass="primitive"href="https://doc.rust-lang.org/1.76.0/std/primitive.u8.html">u8</a></h4></section></summary><divclass="docblock"><p>Get the equivalence class for the given byte.</p>
</div></details><detailsclass="toggle method-toggle"open><summary><sectionid="method.get_by_unit"class="method"><aclass="src rightside"href="../../../src/regex_automata/util/alphabet.rs.html#301-306">source</a><h4class="code-header">pub fn <ahref="#method.get_by_unit"class="fn">get_by_unit</a>(&self, unit: <aclass="struct"href="struct.Unit.html"title="struct regex_automata::util::alphabet::Unit">Unit</a>) -><aclass="primitive"href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a></h4></section></summary><divclass="docblock"><p>Get the equivalence class for the given haystack unit and return the
class as a <code>usize</code>.</p>
</div></details><detailsclass="toggle method-toggle"open><summary><sectionid="method.eoi"class="method"><aclass="src rightside"href="../../../src/regex_automata/util/alphabet.rs.html#311-315">source</a><h4class="code-header">pub fn <ahref="#method.eoi"class="fn">eoi</a>(&self) -><aclass="struct"href="struct.Unit.html"title="struct regex_automata::util::alphabet::Unit">Unit</a></h4></section></summary><divclass="docblock"><p>Create a unit that represents the “end of input” sentinel based on the
number of equivalence classes.</p>
</div></details><detailsclass="toggle method-toggle"open><summary><sectionid="method.alphabet_len"class="method"><aclass="src rightside"href="../../../src/regex_automata/util/alphabet.rs.html#321-326">source</a><h4class="code-header">pub fn <ahref="#method.alphabet_len"class="fn">alphabet_len</a>(&self) -><aclass="primitive"href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a></h4></section></summary><divclass="docblock"><p>Return the total number of elements in the alphabet represented by
these equivalence classes. Equivalently, this returns the total number
of equivalence classes.</p>
</div></details><detailsclass="toggle method-toggle"open><summary><sectionid="method.stride2"class="method"><aclass="src rightside"href="../../../src/regex_automata/util/alphabet.rs.html#337-340">source</a><h4class="code-header">pub fn <ahref="#method.stride2"class="fn">stride2</a>(&self) -><aclass="primitive"href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a></h4></section></summary><divclass="docblock"><p>Returns the stride, as a base-2 exponent, required for these
equivalence classes.</p>
<p>The stride is always the smallest power of 2 that is greater than or
equal to the alphabet length, and the <code>stride2</code> returned here is the
exponent applied to <code>2</code> to get the smallest power. This is done so that
converting between premultiplied state IDs and indices can be done with
shifts alone, which is much faster than integer division.</p>
</div></details><detailsclass="toggle method-toggle"open><summary><sectionid="method.is_singleton"class="method"><aclass="src rightside"href="../../../src/regex_automata/util/alphabet.rs.html#347-349">source</a><h4class="code-header">pub fn <ahref="#method.is_singleton"class="fn">is_singleton</a>(&self) -><aclass="primitive"href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a></h4></section></summary><divclass="docblock"><p>Returns true if and only if every byte in this class maps to its own
equivalence class. Equivalently, there are 257 equivalence classes
and each class contains either exactly one byte or corresponds to the
singleton class containing the “end of input” sentinel.</p>
</div></details><detailsclass="toggle method-toggle"open><summary><sectionid="method.iter"class="method"><aclass="src rightside"href="../../../src/regex_automata/util/alphabet.rs.html#353-355">source</a><h4class="code-header">pub fn <ahref="#method.iter"class="fn">iter</a>(&self) -><aclass="struct"href="struct.ByteClassIter.html"title="struct regex_automata::util::alphabet::ByteClassIter">ByteClassIter</a><'_><ahref="#"class="tooltip"data-notable-ty="ByteClassIter<'_>">ⓘ</a></h4></section></summary><divclass="docblock"><p>Returns an iterator over all equivalence classes in this set.</p>
) -><aclass="struct"href="struct.ByteClassRepresentatives.html"title="struct regex_automata::util::alphabet::ByteClassRepresentatives">ByteClassRepresentatives</a><'_><ahref="#"class="tooltip"data-notable-ty="ByteClassRepresentatives<'_>">ⓘ</a></h4></section></summary><divclass="docblock"><p>Returns an iterator over a sequence of representative bytes from each
equivalence class within the range of bytes given.</p>
<p>When the given range is unbounded on both sides, the iterator yields
exactly N items, where N is equivalent to the number of equivalence
classes. Each item is an arbitrary byte drawn from each equivalence
class.</p>
<p>This is useful when one is determinizing an NFA and the NFA’s alphabet
hasn’t been converted to equivalence classes. Picking an arbitrary byte
from each equivalence class then permits a full exploration of the NFA
instead of using every possible byte value and thus potentially saves
</div></details><detailsclass="toggle method-toggle"open><summary><sectionid="method.elements"class="method"><aclass="src rightside"href="../../../src/regex_automata/util/alphabet.rs.html#472-474">source</a><h4class="code-header">pub fn <ahref="#method.elements"class="fn">elements</a>(&self, class: <aclass="struct"href="struct.Unit.html"title="struct regex_automata::util::alphabet::Unit">Unit</a>) -><aclass="struct"href="struct.ByteClassElements.html"title="struct regex_automata::util::alphabet::ByteClassElements">ByteClassElements</a><'_><ahref="#"class="tooltip"data-notable-ty="ByteClassElements<'_>">ⓘ</a></h4></section></summary><divclass="docblock"><p>Returns an iterator of the bytes in the given equivalence class.</p>
<p>This is useful when one needs to know the actual bytes that belong to
an equivalence class. For example, conceptually speaking, accelerating
a DFA state occurs when a state only has a few outgoing transitions.
But in reality, what is required is that there are only a small
number of distinct bytes that can lead to an outgoing transition. The
difference is that any one transition can correspond to an equivalence
class which may contains many bytes. Therefore, DFA state acceleration
considers the actual elements in each equivalence class of each
<p>That is, this conversion is whatever the implementation of
<code><ahref="https://doc.rust-lang.org/1.76.0/core/convert/trait.From.html"title="trait core::convert::From">From</a><T> for U</code> chooses to do.</p>
</div></details></div></details><detailsclass="toggle implementors-toggle"><summary><sectionid="impl-ToOwned-for-T"class="impl"><aclass="src rightside"href="https://doc.rust-lang.org/1.76.0/src/alloc/borrow.rs.html#83-85">source</a><ahref="#impl-ToOwned-for-T"class="anchor">§</a><h3class="code-header">impl<T><aclass="trait"href="https://doc.rust-lang.org/1.76.0/alloc/borrow/trait.ToOwned.html"title="trait alloc::borrow::ToOwned">ToOwned</a> for T<divclass="where">where
T: <aclass="trait"href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html"title="trait core::clone::Clone">Clone</a>,</div></h3></section></summary><divclass="impl-items"><detailsclass="toggle"open><summary><sectionid="associatedtype.Owned"class="associatedtype trait-impl"><ahref="#associatedtype.Owned"class="anchor">§</a><h4class="code-header">type <ahref="https://doc.rust-lang.org/1.76.0/alloc/borrow/trait.ToOwned.html#associatedtype.Owned"class="associatedtype">Owned</a> = T</h4></section></summary><divclass='docblock'>The resulting type after obtaining ownership.</div></details><detailsclass="toggle method-toggle"open><summary><sectionid="method.to_owned"class="method trait-impl"><aclass="src rightside"href="https://doc.rust-lang.org/1.76.0/src/alloc/borrow.rs.html#88">source</a><ahref="#method.to_owned"class="anchor">§</a><h4class="code-header">fn <ahref="https://doc.rust-lang.org/1.76.0/alloc/borrow/trait.ToOwned.html#tymethod.to_owned"class="fn">to_owned</a>(&self) -> T</h4></section></summary><divclass='docblock'>Creates owned data from borrowed data, usually by cloning. <ahref="https://doc.rust-lang.org/1.76.0/alloc/borrow/trait.ToOwned.html#tymethod.to_owned">Read more</a></div></details><detailsclass="toggle method-toggle"open><summary><sectionid="method.clone_into"class="method trait-impl"><aclass="src rightside"href="https://doc.rust-lang.org/1.76.0/src/alloc/borrow.rs.html#92">source</a><ahref="#method.clone_into"class="anchor">§</a><h4class="code-header">fn <ahref="https://doc.rust-lang.org/1.76.0/alloc/borrow/trait.ToOwned.html#method.clone_into"class="fn">clone_into</a>(&self, target: <aclass="primitive"href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&mut T</a>)</h4></section></summary><divclass='docblock'>Uses borrowed data to replace owned data, usually by cloning. <ahref="https://doc.rust-lang.org/1.76.0/alloc/borrow/trait.ToOwned.html#method.clone_into">Read more</a></div></details></div></details><detailsclass="toggle implementors-toggle"><summary><sectionid="impl-TryFrom%3CU%3E-for-T"class="impl"><aclass="src rightside"href="https://doc.rust-lang.org/1.76.0/src/core/convert/mod.rs.html#803-805">source</a><ahref="#impl-TryFrom%3CU%3E-for-T"class="anchor">§</a><h3class="code-header">impl<T, U><aclass="trait"href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryFrom.html"title="trait core::convert::TryFrom">TryFrom</a><U> for T<divclass="where">where
U: <aclass="trait"href="https://doc.rust-lang.org/1.76.0/core/convert/trait.Into.html"title="trait core::convert::Into">Into</a><T>,</div></h3></section></summary><divclass="impl-items"><detailsclass="toggle"open><summary><sectionid="associatedtype.Error"class="associatedtype trait-impl"><ahref="#associatedtype.Error"class="anchor">§</a><h4class="code-header">type <ahref="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryFrom.html#associatedtype.Error"class="associatedtype">Error</a> = <aclass="enum"href="https://doc.rust-lang.org/1.76.0/core/convert/enum.Infallible.html"title="enum core::convert::Infallible">Infallible</a></h4></section></summary><divclass='docblock'>The type returned in the event of a conversion error.</div></details><detailsclass="toggle method-toggle"open><summary><sectionid="method.try_from"class="method trait-impl"><aclass="src rightside"href="https://doc.rust-lang.org/1.76.0/src/core/convert/mod.rs.html#810">source</a><ahref="#method.try_from"class="anchor">§</a><h4class="code-header">fn <ahref="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryFrom.html#tymethod.try_from"class="fn">try_from</a>(value: U) -><aclass="enum"href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html"title="enum core::result::Result">Result</a><T, <T as <aclass="trait"href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryFrom.html"title="trait core::convert::TryFrom">TryFrom</a><U>>::<aclass="associatedtype"href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryFrom.html#associatedtype.Error"title="type core::convert::TryFrom::Error">Error</a>></h4></section></summary><divclass='docblock'>Performs the conversion.</div></details></div></details><detailsclass="toggle implementors-toggle"><summary><sectionid="impl-TryInto%3CU%3E-for-T"class="impl"><aclass="src rightside"href="https://doc.rust-lang.org/1.76.0/src/core/convert/mod.rs.html#788-790">source</a><ahref="#impl-TryInto%3CU%3E-for-T"class="anchor">§</a><h3class="code-header">impl<T, U><aclass="trait"href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryInto.html"title="trait core::convert::TryInto">TryInto</a><U> for T<divclass="where">where
U: <aclass="trait"href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryFrom.html"title="trait core::convert::TryFrom">TryFrom</a><T>,</div></h3></section></summary><divclass="impl-items"><detailsclass="toggle"open><summary><sectionid="associatedtype.Error-1"class="associatedtype trait-impl"><ahref="#associatedtype.Error-1"class="anchor">§</a><h4class="code-header">type <ahref="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryInto.html#associatedtype.Error"class="associatedtype">Error</a> = <U as <aclass="trait"href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryFrom.html"title="trait core::convert::TryFrom">TryFrom</a><T>>::<aclass="associatedtype"href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryFrom.html#associatedtype.Error"title="type core::convert::TryFrom::Error">Error</a></h4></section></summary><divclass='docblock'>The type returned in the event of a conversion error.</div></details><detailsclass="toggle method-toggle"open><summary><sectionid="method.try_into"class="method trait-impl"><aclass="src rightside"href="https://doc.rust-lang.org/1.76.0/src/core/convert/mod.rs.html#795">source</a><ahref="#method.try_into"class="anchor">§</a><h4class="code-header">fn <ahref="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryInto.html#tymethod.try_into"class="fn">try_into</a>(self) -><aclass="enum"href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html"title="enum core::result::Result">Result</a><U, <U as <aclass="trait"href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryFrom.html"title="trait core::convert::TryFrom">TryFrom</a><T>>::<aclass="associatedtype"href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryFrom.html#associatedtype.Error"title="type core::convert::TryFrom::Error">Error</a>></h4></section></summary><divclass='docblock'>Performs the conversion.</div></details></div></details></div><scripttype="text/json"id="notable-traits-data">{"ByteClassElements<'_>":"<h3>Notabletraitsfor<code><aclass=\"struct\"href=\"struct.ByteClassElements.html\"title=\"structregex_automata::util::alphabet::ByteClassElements\">ByteClassElements</a><'a></code></h3><pre><code><divclass=\"where\">impl<'a><aclass=\"trait\"href=\"https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html\"title=\"traitcore::iter::traits::iterator::Iterator\">Iterator</a>for<aclass=\"struct\"href=\"struct.ByteClassElements.html\"title=\"structregex_automata::util::alphabet::ByteClassElements\">ByteClassElements</a><'a></div><divclass=\"where\">type<ahref=\"https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item\"class=\"associatedtype\">Item</a>=<aclass=\"struct\"href=\"struct.Unit.html\"title=\"structregex_automata::util::alphabet::Unit\">Unit</a>;</div>","ByteClassIter<'_>":"<h3>Notabletraitsfor<code><aclass=\"struct\"href=\"struct.ByteClassIter.html\"title=\"structregex_automata::util::alphabet::ByteClassIter\">ByteClassIter</a><'a></code></h3><pre><code><divclass=\"where\">impl<'a><aclass=\"trait\"href=\"https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html\"title=\"traitcore::iter::traits::iterator::Iterator\">Iterator</a>for<aclass=\"struct\"href=\"struct.ByteClassIter.html\"title=\"structregex_automata::util::alphabet::ByteClassIter\">ByteClassIter</a><'a></div><divclass=\"where\">type<ahref=\"https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item\"class=\"associatedtype\">Item</a>=<aclass=\"struct\"href=\"struct.Unit.html\"title=\"structregex_automata::util::alphabet::Unit\">Unit</a>;</div>","ByteClassRepresentatives<'_>":"<h3>Notabletraitsfor<code><aclass=\"struct\"href=\"struct.ByteClassRepresentatives.html\"title=\"structregex_automata::util::alphabet::ByteClassRepresentatives\">ByteClassRepresentatives</a><'a></code></h3><pre><code><divclass=\"whe