mirror of
https://github.com/fluencelabs/wasmer
synced 2025-05-22 07:01:19 +00:00
90 lines
12 KiB
HTML
90 lines
12 KiB
HTML
<!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="API documentation for the Rust `packed` mod in crate `aho_corasick`."><meta name="keywords" content="rust, rustlang, rust-lang, packed"><title>aho_corasick::packed - Rust</title><link rel="stylesheet" type="text/css" href="../../normalize.css"><link rel="stylesheet" type="text/css" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../dark.css"><link rel="stylesheet" type="text/css" href="../../light.css" id="themeStyle"><script src="../../storage.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="shortcut icon" href="../../favicon.ico"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc mod"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">☰</div><a href='../../aho_corasick/index.html'><div class='logo-container'><img src='../../rust-logo.png' alt='logo'></div></a><p class='location'>Module packed</p><div class="sidebar-elems"><div class="block items"><ul><li><a href="#structs">Structs</a></li><li><a href="#enums">Enums</a></li></ul></div><p class='location'><a href='../index.html'>aho_corasick</a></p><script>window.sidebarCurrent = {name: 'packed', ty: 'mod', relpath: '../'};</script><script defer src="../sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!"><img src="../../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices"></div></div><script src="../../theme.js"></script><nav class="sub"><form class="search-form js-only"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><a id="settings-menu" href="../../settings.html"><img src="../../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class='fqn'><span class='out-of-band'><span id='render-detail'><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class='inner'>−</span>]</a></span><a class='srclink' href='../../src/aho_corasick/packed/mod.rs.html#1-117' title='goto source code'>[src]</a></span><span class='in-band'>Module <a href='../index.html'>aho_corasick</a>::<wbr><a class="mod" href=''>packed</a></span></h1><div class='docblock'><p>A lower level API for 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 directory, 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>
|
||
<h1 id="overview" class="section-header"><a href="#overview">Overview</a></h1>
|
||
<p>The primary types in this sub-module are:</p>
|
||
<ul>
|
||
<li><a href="struct.Searcher.html"><code>Searcher</code></a> executes the actual search algorithm to
|
||
report matches in a haystack.</li>
|
||
<li><a href="struct.Builder.html"><code>Builder</code></a> accumulates patterns incrementally and can
|
||
construct a <code>Searcher</code>.</li>
|
||
<li><a href="struct.Config.html"><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>
|
||
<h1 id="examples" class="section-header"><a href="#examples">Examples</a></h1>
|
||
<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"><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">
|
||
<span class="kw">use</span> <span class="ident">aho_corasick</span>::<span class="ident">packed</span>::{<span class="ident">MatchKind</span>, <span class="ident">Searcher</span>};
|
||
|
||
<span class="kw">let</span> <span class="ident">searcher</span> <span class="op">=</span> <span class="ident">Searcher</span>::<span class="ident">new</span>([<span class="string">"foobar"</span>, <span class="string">"foo"</span>].<span class="ident">iter</span>().<span class="ident">cloned</span>())<span class="question-mark">?</span>;
|
||
<span class="kw">let</span> <span class="ident">matches</span>: <span class="ident">Vec</span><span class="op"><</span><span class="ident">usize</span><span class="op">></span> <span class="op">=</span> <span class="ident">searcher</span>
|
||
.<span class="ident">find_iter</span>(<span class="string">"foobar"</span>)
|
||
.<span class="ident">map</span>(<span class="op">|</span><span class="ident">mat</span><span class="op">|</span> <span class="ident">mat</span>.<span class="ident">pattern</span>())
|
||
.<span class="ident">collect</span>();
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="number">0</span>], <span class="ident">matches</span>);</pre></div>
|
||
<p>This example shows how to use <a href="struct.Config.html"><code>Config</code></a> to change the
|
||
match semantics to leftmost-longest:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">aho_corasick</span>::<span class="ident">packed</span>::{<span class="ident">Config</span>, <span class="ident">MatchKind</span>};
|
||
|
||
<span class="kw">let</span> <span class="ident">searcher</span> <span class="op">=</span> <span class="ident">Config</span>::<span class="ident">new</span>()
|
||
.<span class="ident">match_kind</span>(<span class="ident">MatchKind</span>::<span class="ident">LeftmostLongest</span>)
|
||
.<span class="ident">builder</span>()
|
||
.<span class="ident">add</span>(<span class="string">"foo"</span>)
|
||
.<span class="ident">add</span>(<span class="string">"foobar"</span>)
|
||
.<span class="ident">build</span>()<span class="question-mark">?</span>;
|
||
<span class="kw">let</span> <span class="ident">matches</span>: <span class="ident">Vec</span><span class="op"><</span><span class="ident">usize</span><span class="op">></span> <span class="op">=</span> <span class="ident">searcher</span>
|
||
.<span class="ident">find_iter</span>(<span class="string">"foobar"</span>)
|
||
.<span class="ident">map</span>(<span class="op">|</span><span class="ident">mat</span><span class="op">|</span> <span class="ident">mat</span>.<span class="ident">pattern</span>())
|
||
.<span class="ident">collect</span>();
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>], <span class="ident">matches</span>);</pre></div>
|
||
<h1 id="packed-substring-searching" class="section-header"><a href="#packed-substring-searching">Packed substring searching</a></h1>
|
||
<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. 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. 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><h2 id='structs' class='section-header'><a href="#structs">Structs</a></h2>
|
||
<table><tr class='module-item'><td><a class="struct" href="struct.Builder.html" title='aho_corasick::packed::Builder struct'>Builder</a></td><td class='docblock-short'><p>A builder for constructing a packed searcher from a collection of patterns.</p>
|
||
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Config.html" title='aho_corasick::packed::Config struct'>Config</a></td><td class='docblock-short'><p>The configuration for a packed multiple pattern searcher.</p>
|
||
</td></tr><tr class='module-item'><td><a class="struct" href="struct.FindIter.html" title='aho_corasick::packed::FindIter struct'>FindIter</a></td><td class='docblock-short'><p>An iterator over non-overlapping matches from a packed searcher.</p>
|
||
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Searcher.html" title='aho_corasick::packed::Searcher struct'>Searcher</a></td><td class='docblock-short'><p>A packed searcher for quickly finding occurrences of multiple patterns.</p>
|
||
</td></tr></table><h2 id='enums' class='section-header'><a href="#enums">Enums</a></h2>
|
||
<table><tr class='module-item'><td><a class="enum" href="enum.MatchKind.html" title='aho_corasick::packed::MatchKind enum'>MatchKind</a></td><td class='docblock-short'><p>A knob for controlling the match semantics of a packed multiple string
|
||
searcher.</p>
|
||
</td></tr></table></section><section id="search" class="content hidden"></section><section class="footer"></section><aside id="help" class="hidden"><div><h1 class="hidden">Help</h1><div class="shortcuts"><h2>Keyboard Shortcuts</h2><dl><dt><kbd>?</kbd></dt><dd>Show this help dialog</dd><dt><kbd>S</kbd></dt><dd>Focus the search field</dd><dt><kbd>↑</kbd></dt><dd>Move up in search results</dd><dt><kbd>↓</kbd></dt><dd>Move down in search results</dd><dt><kbd>↹</kbd></dt><dd>Switch tab</dd><dt><kbd>⏎</kbd></dt><dd>Go to active search result</dd><dt><kbd>+</kbd></dt><dd>Expand all sections</dd><dt><kbd>-</kbd></dt><dd>Collapse all sections</dd></dl></div><div class="infos"><h2>Search Tricks</h2><p>Prefix searches with a type followed by a colon (e.g., <code>fn:</code>) to restrict the search to a given type.</p><p>Accepted types are: <code>fn</code>, <code>mod</code>, <code>struct</code>, <code>enum</code>, <code>trait</code>, <code>type</code>, <code>macro</code>, and <code>const</code>.</p><p>Search functions by type signature (e.g., <code>vec -> usize</code> or <code>* -> vec</code>)</p><p>Search multiple things at once by splitting your query with comma (e.g., <code>str,u8</code> or <code>String,struct:Vec,test</code>)</p></div></div></aside><script>window.rootPath = "../../";window.currentCrate = "aho_corasick";</script><script src="../../aliases.js"></script><script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html> |