rtic/1/api/indexmap/index.html
2024-12-06 13:35:18 +00:00

58 lines
No EOL
10 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="`IndexMap` is a hash table where the iteration order of the key-value pairs is independent of the hash values of the keys."><title>indexmap - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-b0742ba02757f159.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="indexmap" data-themes="" data-resource-suffix="" data-rustdoc-version="1.83.0 (90b35a623 2024-11-26)" data-channel="1.83.0" data-search-js="search-f0d225181b97f9a4.js" data-settings-js="settings-805db61a62df4bd2.js" ><script src="../static.files/storage-1d39b6787ed640ff.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-f070b9041d14864c.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-0111fcff984fae8f.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc mod crate"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../indexmap/index.html">indexmap</a><span class="version">1.9.3</span></h2></div><div class="sidebar-elems"><ul class="block"><li><a id="all-types" href="all.html">All Items</a></li></ul><section id="rustdoc-toc"><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#feature-highlights" title="Feature Highlights">Feature Highlights</a></li><li><a href="#alternate-hashers" title="Alternate Hashers">Alternate Hashers</a></li><li><a href="#rust-version" title="Rust Version">Rust Version</a></li><li><a href="#no-standard-library-targets" title="No Standard Library Targets">No Standard Library Targets</a></li></ul><h3><a href="#reexports">Crate Items</a></h3><ul class="block"><li><a href="#reexports" title="Re-exports">Re-exports</a></li><li><a href="#modules" title="Modules">Modules</a></li><li><a href="#macros" title="Macros">Macros</a></li><li><a href="#traits" title="Traits">Traits</a></li></ul></section><div id="rustdoc-modnav"></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><h1>Crate <span>indexmap</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/indexmap/lib.rs.html#2-194">source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p><a href="map/struct.IndexMap.html"><code>IndexMap</code></a> is a hash table where the iteration order of the key-value
pairs is independent of the hash values of the keys.</p>
<p><a href="set/struct.IndexSet.html"><code>IndexSet</code></a> is a corresponding hash set using the same implementation and
with similar properties.</p>
<h4 id="feature-highlights"><a class="doc-anchor" href="#feature-highlights">§</a>Feature Highlights</h4>
<p><a href="map/struct.IndexMap.html"><code>IndexMap</code></a> and <a href="set/struct.IndexSet.html"><code>IndexSet</code></a> are drop-in compatible with the std <code>HashMap</code>
and <code>HashSet</code>, but they also have some features of note:</p>
<ul>
<li>The ordering semantics (see their documentation for details)</li>
<li>Sorting methods and the <a href="map/struct.IndexMap.html#method.pop" title="method indexmap::map::IndexMap::pop"><code>.pop()</code></a> methods.</li>
<li>The <a href="trait.Equivalent.html" title="trait indexmap::Equivalent"><code>Equivalent</code></a> trait, which offers more flexible equality definitions
between borrowed and owned versions of keys.</li>
<li>The <a href="map/trait.MutableKeys.html" title="trait indexmap::map::MutableKeys"><code>MutableKeys</code></a> trait, which gives opt-in mutable
access to hash map keys.</li>
</ul>
<h4 id="alternate-hashers"><a class="doc-anchor" href="#alternate-hashers">§</a>Alternate Hashers</h4>
<p><a href="map/struct.IndexMap.html"><code>IndexMap</code></a> and <a href="set/struct.IndexSet.html"><code>IndexSet</code></a> have a default hasher type <code>S = RandomState</code>,
just like the standard <code>HashMap</code> and <code>HashSet</code>, which is resistant to
HashDoS attacks but not the most performant. Type aliases can make it easier
to use alternate hashers:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>fnv::FnvBuildHasher;
<span class="kw">use </span>fxhash::FxBuildHasher;
<span class="kw">use </span>indexmap::{IndexMap, IndexSet};
<span class="kw">type </span>FnvIndexMap&lt;K, V&gt; = IndexMap&lt;K, V, FnvBuildHasher&gt;;
<span class="kw">type </span>FnvIndexSet&lt;T&gt; = IndexSet&lt;T, FnvBuildHasher&gt;;
<span class="kw">type </span>FxIndexMap&lt;K, V&gt; = IndexMap&lt;K, V, FxBuildHasher&gt;;
<span class="kw">type </span>FxIndexSet&lt;T&gt; = IndexSet&lt;T, FxBuildHasher&gt;;
<span class="kw">let </span>std: IndexSet&lt;i32&gt; = (<span class="number">0</span>..<span class="number">100</span>).collect();
<span class="kw">let </span>fnv: FnvIndexSet&lt;i32&gt; = (<span class="number">0</span>..<span class="number">100</span>).collect();
<span class="kw">let </span>fx: FxIndexSet&lt;i32&gt; = (<span class="number">0</span>..<span class="number">100</span>).collect();
<span class="macro">assert_eq!</span>(std, fnv);
<span class="macro">assert_eq!</span>(std, fx);</code></pre></div>
<h4 id="rust-version"><a class="doc-anchor" href="#rust-version">§</a>Rust Version</h4>
<p>This version of indexmap requires Rust 1.56 or later.</p>
<p>The indexmap 1.x release series will use a carefully considered version
upgrade policy, where in a later 1.x version, we will raise the minimum
required Rust version.</p>
<h3 id="no-standard-library-targets"><a class="doc-anchor" href="#no-standard-library-targets">§</a>No Standard Library Targets</h3>
<p>This crate supports being built without <code>std</code>, requiring
<code>alloc</code> instead. This is enabled automatically when it is detected that
<code>std</code> is not available. There is no crate feature to enable/disable to
trigger this. It can be tested by building for a std-less target.</p>
<ul>
<li>Creating maps and sets using <a href="map/struct.IndexMap.html#method.new" title="associated function indexmap::map::IndexMap::new"><code>new</code></a> and
<a href="map/struct.IndexMap.html#method.with_capacity" title="associated function indexmap::map::IndexMap::with_capacity"><code>with_capacity</code></a> is unavailable without <code>std</code>.<br />
Use methods <a href="map/struct.IndexMap.html#impl-Default"><code>IndexMap::default</code></a>,
<a href="map/struct.IndexMap.html#method.with_hasher" title="associated function indexmap::map::IndexMap::with_hasher"><code>with_hasher</code></a>,
<a href="map/struct.IndexMap.html#method.with_capacity_and_hasher" title="associated function indexmap::map::IndexMap::with_capacity_and_hasher"><code>with_capacity_and_hasher</code></a> instead.
A no-std compatible hasher will be needed as well, for example
from the crate <code>twox-hash</code>.</li>
<li>Macros <a href="macro.indexmap.html" title="macro indexmap::indexmap"><code>indexmap!</code></a> and <a href="macro.indexset.html" title="macro indexmap::indexset"><code>indexset!</code></a> are unavailable without <code>std</code>.</li>
</ul>
</div></details><h2 id="reexports" class="section-header">Re-exports<a href="#reexports" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name" id="reexport.IndexMap"><code>pub use crate::map::<a class="struct" href="map/struct.IndexMap.html" title="struct indexmap::map::IndexMap">IndexMap</a>;</code></div></li><li><div class="item-name" id="reexport.IndexSet"><code>pub use crate::set::<a class="struct" href="set/struct.IndexSet.html" title="struct indexmap::set::IndexSet">IndexSet</a>;</code></div></li></ul><h2 id="modules" class="section-header">Modules<a href="#modules" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="mod" href="map/index.html" title="mod indexmap::map">map</a></div><div class="desc docblock-short"><code>IndexMap</code> is a hash table where the iteration order of the key-value
pairs is independent of the hash values of the keys.</div></li><li><div class="item-name"><a class="mod" href="set/index.html" title="mod indexmap::set">set</a></div><div class="desc docblock-short">A hash set implemented using <code>IndexMap</code></div></li></ul><h2 id="macros" class="section-header">Macros<a href="#macros" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="macro" href="macro.indexmap.html" title="macro indexmap::indexmap">indexmap</a></div><div class="desc docblock-short">Create an <code>IndexMap</code> from a list of key-value pairs</div></li><li><div class="item-name"><a class="macro" href="macro.indexset.html" title="macro indexmap::indexset">indexset</a></div><div class="desc docblock-short">Create an <code>IndexSet</code> from a list of values</div></li></ul><h2 id="traits" class="section-header">Traits<a href="#traits" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="trait" href="trait.Equivalent.html" title="trait indexmap::Equivalent">Equivalent</a></div><div class="desc docblock-short">Key equivalence trait.</div></li></ul></section></div></main></body></html>