| <!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Provides packed multiple substring search, principally for a small number of patterns."><meta name="keywords" content="rust, rustlang, rust-lang, packed"><title>aho_corasick::packed - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../../normalize.css"><link rel="stylesheet" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../../ayu.css" disabled><link rel="stylesheet" href="../../dark.css" disabled><link rel="stylesheet" href="../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../storage.js"></script><script defer src="../../main.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../favicon.svg"></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">☰</button><a class="sidebar-logo" href="../../aho_corasick/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></div></a><h2></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../../aho_corasick/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">Module packed</a></h2><div class="sidebar-elems"><section><ul class="block"><li><a href="#structs">Structs</a></li><li><a href="#enums">Enums</a></li></ul></section></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../wheel.svg"></a></div></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Module <a href="../index.html">aho_corasick</a>::<wbr><a class="mod" href="#">packed</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../../clipboard.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../../src/aho_corasick/packed/mod.rs.html#1-116">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Provides packed multiple substring search, principally for a small number of |
| patterns.</p> |
| <p>This sub-module provides vectorized routines for quickly finding |
| matches of a small number of patterns. In general, users of this crate |
| shouldn’t need to interface with this module directly, as the primary |
| <a href="../struct.AhoCorasick.html"><code>AhoCorasick</code></a> searcher will use these routines |
| automatically as a prefilter when applicable. However, in some cases, callers |
| may want to bypass the Aho-Corasick machinery entirely and use this vectorized |
| searcher directly.</p> |
| <h2 id="overview"><a href="#overview">Overview</a></h2> |
| <p>The primary types in this sub-module are:</p> |
| <ul> |
| <li><a href="struct.Searcher.html" title="Searcher"><code>Searcher</code></a> executes the actual search algorithm to report matches in a |
| haystack.</li> |
| <li><a href="struct.Builder.html" title="Builder"><code>Builder</code></a> accumulates patterns incrementally and can construct a |
| <code>Searcher</code>.</li> |
| <li><a href="struct.Config.html" title="Config"><code>Config</code></a> permits tuning the searcher, and itself will produce a <code>Builder</code> |
| (which can then be used to build a <code>Searcher</code>). Currently, the only tuneable |
| knob are the match semantics, but this may be expanded in the future.</li> |
| </ul> |
| <h2 id="examples"><a href="#examples">Examples</a></h2> |
| <p>This example shows how to create a searcher from an iterator of patterns. |
| By default, leftmost-first match semantics are used. (See the top-level |
| <a href="enum.MatchKind.html" title="MatchKind"><code>MatchKind</code></a> type for more details about match semantics, which apply |
| similarly to packed substring search.)</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>aho_corasick::{packed::{MatchKind, Searcher}, PatternID}; |
| |
| <span class="kw">let </span>searcher = Searcher::new([<span class="string">"foobar"</span>, <span class="string">"foo"</span>].iter().cloned())<span class="question-mark">?</span>; |
| <span class="kw">let </span>matches: Vec<PatternID> = searcher |
| .find_iter(<span class="string">"foobar"</span>) |
| .map(|mat| mat.pattern()) |
| .collect(); |
| <span class="macro">assert_eq!</span>(<span class="macro">vec!</span>[PatternID::ZERO], matches);</code></pre></div> |
| <p>This example shows how to use <a href="struct.Config.html" title="Config"><code>Config</code></a> to change the match semantics to |
| leftmost-longest:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>aho_corasick::{packed::{Config, MatchKind}, PatternID}; |
| |
| <span class="kw">let </span>searcher = Config::new() |
| .match_kind(MatchKind::LeftmostLongest) |
| .builder() |
| .add(<span class="string">"foo"</span>) |
| .add(<span class="string">"foobar"</span>) |
| .build()<span class="question-mark">?</span>; |
| <span class="kw">let </span>matches: Vec<PatternID> = searcher |
| .find_iter(<span class="string">"foobar"</span>) |
| .map(|mat| mat.pattern()) |
| .collect(); |
| <span class="macro">assert_eq!</span>(<span class="macro">vec!</span>[PatternID::must(<span class="number">1</span>)], matches);</code></pre></div> |
| <h2 id="packed-substring-searching"><a href="#packed-substring-searching">Packed substring searching</a></h2> |
| <p>Packed substring searching refers to the use of SIMD (Single Instruction, |
| Multiple Data) to accelerate the detection of matches in a haystack. Unlike |
| conventional algorithms, such as Aho-Corasick, SIMD algorithms for substring |
| search tend to do better with a small number of patterns, where as Aho-Corasick |
| generally maintains reasonably consistent performance regardless of the number |
| of patterns you give it. Because of this, the vectorized searcher in this |
| sub-module cannot be used as a general purpose searcher, since building the |
| searcher may fail even when given a small number of patterns. However, in |
| exchange, when searching for a small number of patterns, searching can be quite |
| a bit faster than Aho-Corasick (sometimes by an order of magnitude).</p> |
| <p>The key take away here is that constructing a searcher from a list of patterns |
| is a fallible operation with no clear rules for when it will fail. While the |
| precise conditions under which building a searcher can fail is specifically an |
| implementation detail, here are some common reasons:</p> |
| <ul> |
| <li>Too many patterns were given. Typically, the limit is on the order of 100 or |
| so, but this limit may fluctuate based on available CPU features.</li> |
| <li>The available packed algorithms require CPU features that aren’t available. |
| For example, currently, this crate only provides packed algorithms for |
| <code>x86_64</code>. Therefore, constructing a packed searcher on any other target |
| (e.g., ARM) will always fail.</li> |
| <li>Zero patterns were given, or one of the patterns given was empty. Packed |
| searchers require at least one pattern and that all patterns are non-empty.</li> |
| <li>Something else about the nature of the patterns (typically based on |
| heuristics) suggests that a packed searcher would perform very poorly, so |
| no searcher is built.</li> |
| </ul> |
| </div></details><h2 id="structs" class="small-section-header"><a href="#structs">Structs</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Builder.html" title="aho_corasick::packed::Builder struct">Builder</a></div><div class="item-right docblock-short">A builder for constructing a packed searcher from a collection of patterns.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Config.html" title="aho_corasick::packed::Config struct">Config</a></div><div class="item-right docblock-short">The configuration for a packed multiple pattern searcher.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.FindIter.html" title="aho_corasick::packed::FindIter struct">FindIter</a></div><div class="item-right docblock-short">An iterator over non-overlapping matches from a packed searcher.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Searcher.html" title="aho_corasick::packed::Searcher struct">Searcher</a></div><div class="item-right docblock-short">A packed searcher for quickly finding occurrences of multiple patterns.</div></div></div><h2 id="enums" class="small-section-header"><a href="#enums">Enums</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.MatchKind.html" title="aho_corasick::packed::MatchKind enum">MatchKind</a></div><div class="item-right docblock-short">A knob for controlling the match semantics of a packed multiple string |
| searcher.</div></div></div></section></div></main><div id="rustdoc-vars" data-root-path="../../" data-current-crate="aho_corasick" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html> |