Files
tantivy/fst/raw/struct.Builder.html
2018-02-12 02:52:50 +00:00

201 lines
19 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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 `Builder` struct in crate `fst`.">
<meta name="keywords" content="rust, rustlang, rust-lang, Builder">
<title>fst::raw::Builder - 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="../../main.css" id="themeStyle">
<script src="../../storage.js"></script>
</head>
<body class="rustdoc struct">
<!--[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">&#9776;</div>
<p class='location'>Struct Builder</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#methods">Methods</a><div class="sidebar-links"><a href="#method.memory">memory</a><a href="#method.new">new</a><a href="#method.new_type">new_type</a><a href="#method.add">add</a><a href="#method.insert">insert</a><a href="#method.extend_iter">extend_iter</a><a href="#method.extend_stream">extend_stream</a><a href="#method.finish">finish</a><a href="#method.into_inner">into_inner</a><a href="#method.get_ref">get_ref</a><a href="#method.bytes_written">bytes_written</a></div></div><p class='location'><a href='../index.html'>fst</a>::<wbr><a href='index.html'>raw</a></p><script>window.sidebarCurrent = {name: 'Builder', ty: 'struct', 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">
<input class="search-input" name="search"
autocomplete="off"
placeholder="Click or press S to search, ? for more options…"
type="search">
</div>
</form>
</nav>
<section id='main' class="content">
<h1 class='fqn'><span class='in-band'>Struct <a href='../index.html'>fst</a>::<wbr><a href='index.html'>raw</a>::<wbr><a class="struct" href=''>Builder</a></span><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'>&#x2212;</span>]
</a>
</span><a class='srclink' href='../../src/fst/raw/build.rs.html#44-74' title='goto source code'>[src]</a></span></h1>
<pre class='rust struct'>pub struct Builder&lt;W&gt; { /* fields omitted */ }</pre><div class='docblock'><p>A builder for creating a finite state transducer.</p>
<p>This is not your average everyday builder. It has two important qualities
that make it a bit unique from what you might expect:</p>
<ol>
<li>All keys must be added in lexicographic order. Adding a key out of order
will result in an error. Additionally, adding a duplicate key with an
output value will also result in an error. That is, once a key is
associated with a value, that association can never be modified or
deleted.</li>
<li>The representation of an fst is streamed to <em>any</em> <code>io::Write</code> as it is
built. For an in memory representation, this can be a <code>Vec&lt;u8&gt;</code>.</li>
</ol>
<p>Point (2) is especially important because it means that an fst can be
constructed <em>without storing the entire fst in memory</em>. Namely, since it
works with any <code>io::Write</code>, it can be streamed directly to a file.</p>
<p>With that said, the builder does use memory, but <strong>memory usage is bounded
to a constant size</strong>. The amount of memory used trades off with the
compression ratio. Currently, the implementation hard codes this trade off
which can result in about 5-20MB of heap usage during construction. (N.B.
Guaranteeing a maximal compression ratio requires memory proportional to
the size of the fst, which defeats some of the benefit of streaming
it to disk. In practice, a small bounded amount of memory achieves
close-to-minimal compression ratios.)</p>
<p>The algorithmic complexity of fst construction is <code>O(n)</code> where <code>n</code> is the
number of elements added to the fst.</p>
</div>
<h2 id='methods' class='small-section-header'>
Methods<a href='#methods' class='anchor'></a>
</h2>
<h3 id='impl' class='impl'><span class='in-band'><code>impl <a class="struct" href="../../fst/raw/struct.Builder.html" title="struct fst::raw::Builder">Builder</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>&gt;&gt;</code><a href='#impl' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/fst/raw/build.rs.html#100-105' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.memory' class="method"><span id='memory.v' class='invisible'><code>pub fn <a href='#method.memory' class='fnname'>memory</a>() -&gt; Self</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/fst/raw/build.rs.html#102-104' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Create a builder that builds an fst in memory.</p>
</div></div><h3 id='impl-1' class='impl'><span class='in-band'><code>impl&lt;W:&nbsp;<a class="trait" href="https://doc.rust-lang.org/nightly/std/io/trait.Write.html" title="trait std::io::Write">Write</a>&gt; <a class="struct" href="../../fst/raw/struct.Builder.html" title="struct fst::raw::Builder">Builder</a>&lt;W&gt;</code><a href='#impl-1' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/fst/raw/build.rs.html#107-304' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.new' class="method"><span id='new.v' class='invisible'><code>pub fn <a href='#method.new' class='fnname'>new</a>(wtr: W) -&gt; <a class="type" href="../../fst/type.Result.html" title="type fst::Result">Result</a>&lt;<a class="struct" href="../../fst/raw/struct.Builder.html" title="struct fst::raw::Builder">Builder</a>&lt;W&gt;&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/fst/raw/build.rs.html#110-112' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Create a builder that builds an fst by writing it to <code>wtr</code> in a
streaming fashion.</p>
</div><h4 id='method.new_type' class="method"><span id='new_type.v' class='invisible'><code>pub fn <a href='#method.new_type' class='fnname'>new_type</a>(wtr: W, ty: <a class="type" href="../../fst/raw/type.FstType.html" title="type fst::raw::FstType">FstType</a>) -&gt; <a class="type" href="../../fst/type.Result.html" title="type fst::Result">Result</a>&lt;<a class="struct" href="../../fst/raw/struct.Builder.html" title="struct fst::raw::Builder">Builder</a>&lt;W&gt;&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/fst/raw/build.rs.html#116-132' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>The same as <code>new</code>, except it sets the type of the fst to the type
given.</p>
</div><h4 id='method.add' class="method"><span id='add.v' class='invisible'><code>pub fn <a href='#method.add' class='fnname'>add</a>&lt;B&gt;(&amp;mut self, bs: B) -&gt; <a class="type" href="../../fst/type.Result.html" title="type fst::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;B: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>&gt;,&nbsp;</span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/fst/raw/build.rs.html#135-139' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Adds a byte string to this FST with a zero output value.</p>
</div><h4 id='method.insert' class="method"><span id='insert.v' class='invisible'><code>pub fn <a href='#method.insert' class='fnname'>insert</a>&lt;B&gt;(&amp;mut self, bs: B, val: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u64.html">u64</a>) -&gt; <a class="type" href="../../fst/type.Result.html" title="type fst::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;B: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>&gt;,&nbsp;</span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/fst/raw/build.rs.html#150-154' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Insert a new key-value pair into the fst.</p>
<p>Keys must be convertible to byte strings. Values must be a <code>u64</code>, which
is a restriction of the current implementation of finite state
transducers. (Values may one day be expanded to other types.)</p>
<p>If a key is inserted that is less than or equal to any previous key
added, then an error is returned. Similarly, if there was a problem
writing to the underlying writer, an error is returned.</p>
</div><h4 id='method.extend_iter' class="method"><span id='extend_iter.v' class='invisible'><code>pub fn <a href='#method.extend_iter' class='fnname'>extend_iter</a>&lt;T, I&gt;(&amp;mut self, iter: I) -&gt; <a class="type" href="../../fst/type.Result.html" title="type fst::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">[</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;I: <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/trait.IntoIterator.html" title="trait core::iter::traits::IntoIterator">IntoIterator</a>&lt;Item = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a>T, <a class="struct" href="../../fst/raw/struct.Output.html" title="struct fst::raw::Output">Output</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a>&gt;,&nbsp;</span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/fst/raw/build.rs.html#164-170' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Calls insert on each item in the iterator.</p>
<p>If an error occurred while adding an element, processing is stopped
and the error is returned.</p>
<p>If a key is inserted that is less than or equal to any previous key
added, then an error is returned. Similarly, if there was a problem
writing to the underlying writer, an error is returned.</p>
</div><h4 id='method.extend_stream' class="method"><span id='extend_stream.v' class='invisible'><code>pub fn <a href='#method.extend_stream' class='fnname'>extend_stream</a>&lt;'f, I, S&gt;(&amp;mut self, stream: I) -&gt; <a class="type" href="../../fst/type.Result.html" title="type fst::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;I: for&lt;'a&gt; <a class="trait" href="../../fst/trait.IntoStreamer.html" title="trait fst::IntoStreamer">IntoStreamer</a>&lt;'a, Into = S, Item = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&amp;'a [</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>, <a class="struct" href="../../fst/raw/struct.Output.html" title="struct fst::raw::Output">Output</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a>&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;S: 'f + for&lt;'a&gt; <a class="trait" href="../../fst/trait.Streamer.html" title="trait fst::Streamer">Streamer</a>&lt;'a, Item = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&amp;'a [</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>, <a class="struct" href="../../fst/raw/struct.Output.html" title="struct fst::raw::Output">Output</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a>&gt;,&nbsp;</span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/fst/raw/build.rs.html#180-188' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Calls insert on each item in the stream.</p>
<p>Note that unlike <code>extend_iter</code>, this is not generic on the items in
the stream.</p>
<p>If a key is inserted that is less than or equal to any previous key
added, then an error is returned. Similarly, if there was a problem
writing to the underlying writer, an error is returned.</p>
</div><h4 id='method.finish' class="method"><span id='finish.v' class='invisible'><code>pub fn <a href='#method.finish' class='fnname'>finish</a>(self) -&gt; <a class="type" href="../../fst/type.Result.html" title="type fst::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/fst/raw/build.rs.html#193-196' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Finishes the construction of the fst and flushes the underlying
writer. After completion, the data written to <code>W</code> may be read using
one of <code>Fst</code>'s constructor methods.</p>
</div><h4 id='method.into_inner' class="method"><span id='into_inner.v' class='invisible'><code>pub fn <a href='#method.into_inner' class='fnname'>into_inner</a>(self) -&gt; <a class="type" href="../../fst/type.Result.html" title="type fst::Result">Result</a>&lt;W&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/fst/raw/build.rs.html#200-208' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Just like <code>finish</code>, except it returns the underlying writer after
flushing it.</p>
</div><h4 id='method.get_ref' class="method"><span id='get_ref.v' class='invisible'><code>pub fn <a href='#method.get_ref' class='fnname'>get_ref</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>W</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/fst/raw/build.rs.html#296-298' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Gets a reference to the underlying writer.</p>
</div><h4 id='method.bytes_written' class="method"><span id='bytes_written.v' class='invisible'><code>pub fn <a href='#method.bytes_written' class='fnname'>bytes_written</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u64.html">u64</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/fst/raw/build.rs.html#301-303' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Returns the number of bytes written to the underlying writer</p>
</div></div></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>&#9166;</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>
</div>
</div>
</aside>
<script>
window.rootPath = "../../";
window.currentCrate = "fst";
</script>
<script src="../../main.js"></script>
<script defer src="../../search-index.js"></script>
</body>
</html>