deploy: de38ae62916547ad097c066f94a32e9ba7790eeb

This commit is contained in:
NotAShelf 2025-02-05 00:10:33 +00:00
commit 9a86359447
28502 changed files with 1261284 additions and 0 deletions

1
sharded_slab/all.html Normal file
View file

@ -0,0 +1 @@
<!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="List of all items in this crate"><title>List of all items in this crate</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.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-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="sharded_slab" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../static.files/storage-59e33391.js"></script><script defer src="../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-044be391.svg"></head><body class="rustdoc mod sys"><!--[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="../sharded_slab/index.html">sharded_<wbr>slab</a><span class="version">0.1.7</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h3><a href="#structs">Crate Items</a></h3><ul class="block"><li><a href="#structs" title="Structs">Structs</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"><h1>List of all items</h1><h3 id="structs">Structs</h3><ul class="all-items"><li><a href="struct.DefaultConfig.html">DefaultConfig</a></li><li><a href="struct.Entry.html">Entry</a></li><li><a href="struct.OwnedEntry.html">OwnedEntry</a></li><li><a href="struct.Pool.html">Pool</a></li><li><a href="struct.Slab.html">Slab</a></li><li><a href="struct.UniqueIter.html">UniqueIter</a></li><li><a href="struct.VacantEntry.html">VacantEntry</a></li><li><a href="pool/struct.OwnedRef.html">pool::OwnedRef</a></li><li><a href="pool/struct.OwnedRefMut.html">pool::OwnedRefMut</a></li><li><a href="pool/struct.Pool.html">pool::Pool</a></li><li><a href="pool/struct.Ref.html">pool::Ref</a></li><li><a href="pool/struct.RefMut.html">pool::RefMut</a></li></ul><h3 id="traits">Traits</h3><ul class="all-items"><li><a href="trait.Clear.html">Clear</a></li><li><a href="trait.Config.html">Config</a></li></ul></section></div></main></body></html>

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../sharded_slab/struct.DefaultConfig.html">
<title>Redirection</title>
</head>
<body>
<p>Redirecting to <a href="../../sharded_slab/struct.DefaultConfig.html">../../sharded_slab/struct.DefaultConfig.html</a>...</p>
<script>location.replace("../../sharded_slab/struct.DefaultConfig.html" + location.search + location.hash);</script>
</body>
</html>

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../sharded_slab/trait.Config.html">
<title>Redirection</title>
</head>
<body>
<p>Redirecting to <a href="../../sharded_slab/trait.Config.html">../../sharded_slab/trait.Config.html</a>...</p>
<script>location.replace("../../sharded_slab/trait.Config.html" + location.search + location.hash);</script>
</body>
</html>

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../sharded_slab/trait.Clear.html">
<title>Redirection</title>
</head>
<body>
<p>Redirecting to <a href="../../sharded_slab/trait.Clear.html">../../sharded_slab/trait.Clear.html</a>...</p>
<script>location.replace("../../sharded_slab/trait.Clear.html" + location.search + location.hash);</script>
</body>
</html>

View file

@ -0,0 +1,106 @@
<!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="Notes on `sharded-slab`s implementation and design."><title>sharded_slab::implementation - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.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-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="sharded_slab" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../sharded_slab/index.html">sharded_<wbr>slab</a><span class="version">0.1.7</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module implementation</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#design" title="Design">Design</a></li><li><a href="#implementation" title="Implementation">Implementation</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="../index.html">In crate sharded_<wbr>slab</a></h2></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"><span class="rustdoc-breadcrumbs"><a href="../index.html">sharded_slab</a></span><h1>Module <span>implementation</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/sharded_slab/implementation.rs.html#4-138">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Notes on <code>sharded-slab</code>s implementation and design.</p>
<h2 id="design"><a class="doc-anchor" href="#design">§</a>Design</h2>
<p>The sharded slabs design is strongly inspired by the ideas presented by
Leijen, Zorn, and de Moura in <a href="https://www.microsoft.com/en-us/research/uploads/prod/2019/06/mimalloc-tr-v1.pdf">Mimalloc: Free List Sharding in
Action</a>. In this report, the authors present a novel design for a
memory allocator based on a concept of <em>free list sharding</em>.</p>
<p>Memory allocators must keep track of what memory regions are not currently
allocated (“free”) in order to provide them to future allocation requests.
The term <a href="https://en.wikipedia.org/wiki/Free_list"><em>free list</em></a> refers to a technique for performing this
bookkeeping, where each free block stores a pointer to the next free block,
forming a linked list. The memory allocator keeps a pointer to the most
recently freed block, the <em>head</em> of the free list. To allocate more memory,
the allocator pops from the free list by setting the head pointer to the
next free block of the current head block, and returning the previous head.
To deallocate a block, the block is pushed to the free list by setting its
first word to the current head pointer, and the head pointer is set to point
to the deallocated block. Most implementations of slab allocators backed by
arrays or vectors use a similar technique, where pointers are replaced by
indices into the backing array.</p>
<p>When allocations and deallocations can occur concurrently across threads,
they must synchronize accesses to the free list; either by putting the
entire allocator state inside of a lock, or by using atomic operations to
treat the free list as a lock-free structure (such as a <a href="https://en.wikipedia.org/wiki/Treiber_stack">Treiber stack</a>). In
both cases, there is a significant performance cost — even when the free
list is lock-free, it is likely that a noticeable amount of time will be
spent in compare-and-swap loops. Ideally, the global synchronzation point
created by the single global free list could be avoided as much as possible.</p>
<p>The approach presented by Leijen, Zorn, and de Moura is to introduce
sharding and thus increase the granularity of synchronization significantly.
In mimalloc, the heap is <em>sharded</em> so that each thread has its own
thread-local heap. Objects are always allocated from the local heap of the
thread where the allocation is performed. Because allocations are always
done from a threads local heap, they need not be synchronized.</p>
<p>However, since objects can move between threads before being deallocated,
<em>deallocations</em> may still occur concurrently. Therefore, Leijen et al.
introduce a concept of <em>local</em> and <em>global</em> free lists. When an object is
deallocated on the same thread it was originally allocated on, it is placed
on the local free list; if it is deallocated on another thread, it goes on
the global free list for the heap of the thread from which it originated. To
allocate, the local free list is used first; if it is empty, the entire
global free list is popped onto the local free list. Since the local free
list is only ever accessed by the thread it belongs to, it does not require
synchronization at all, and because the global free list is popped from
infrequently, the cost of synchronization has a reduced impact. A majority
of allocations can occur without any synchronization at all; and
deallocations only require synchronization when an object has left its
parent thread (a relatively uncommon case).</p>
<h2 id="implementation"><a class="doc-anchor" href="#implementation">§</a>Implementation</h2>
<p>A slab is represented as an array of <a href="https://docs.rs/sharded-slab/latest/sharded_slab/trait.Config.html#associatedconstant.MAX_THREADS"><code>MAX_THREADS</code></a> <em>shards</em>. A shard
consists of a vector of one or more <em>pages</em> plus associated metadata.
Finally, a page consists of an array of <em>slots</em>, head indices for the local
and remote free lists.</p>
<div class="example-wrap"><pre class="language-text"><code>┌─────────────┐
│ shard 1 │
│ │ ┌─────────────┐ ┌────────┐
│ pages───────┼───▶│ page 1 │ │ │
├─────────────┤ ├─────────────┤ ┌────▶│ next──┼─┐
│ shard 2 │ │ page 2 │ │ ├────────┤ │
├─────────────┤ │ │ │ │XXXXXXXX│ │
│ shard 3 │ │ local_head──┼──┘ ├────────┤ │
└─────────────┘ │ remote_head─┼──┐ │ │◀┘
... ├─────────────┤ │ │ next──┼─┐
┌─────────────┐ │ page 3 │ │ ├────────┤ │
│ shard n │ └─────────────┘ │ │XXXXXXXX│ │
└─────────────┘ ... │ ├────────┤ │
┌─────────────┐ │ │XXXXXXXX│ │
│ page n │ │ ├────────┤ │
└─────────────┘ │ │ │◀┘
└────▶│ next──┼───▶ ...
├────────┤
│XXXXXXXX│
└────────┘</code></pre></div>
<p>The size of the first page in a shard is always a power of two, and every
subsequent page added after the first is twice as large as the page that
preceeds it.</p>
<div class="example-wrap"><pre class="language-text"><code>
pg.
┌───┐ ┌─┬─┐
│ 0 │───▶ │ │
├───┤ ├─┼─┼─┬─┐
│ 1 │───▶ │ │ │ │
├───┤ ├─┼─┼─┼─┼─┬─┬─┬─┐
│ 2 │───▶ │ │ │ │ │ │ │ │
├───┤ ├─┼─┼─┼─┼─┼─┼─┼─┼─┬─┬─┬─┬─┬─┬─┬─┐
│ 3 │───▶ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
└───┘ └─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┘</code></pre></div>
<p>When searching for a free slot, the smallest page is searched first, and if
it is full, the search proceeds to the next page until either a free slot is
found or all available pages have been searched. If all available pages have
been searched and the maximum number of pages has not yet been reached, a
new page is then allocated.</p>
<p>Since every page is twice as large as the previous page, and all page sizes
are powers of two, we can determine the page index that contains a given
address by shifting the address down by the smallest page size and
looking at how many twos places necessary to represent that number,
telling us what power of two page size it fits inside of. We can
determine the number of twos places by counting the number of leading
zeros (unused twos places) in the numbers binary representation, and
subtracting that count from the total number of bits in a word.</p>
<p>The formula for determining the page number that contains an offset is thus:</p>
<div class="example-wrap ignore"><a href="#" class="tooltip" title="This example is not tested"></a><pre class="rust rust-example-rendered"><code>WIDTH - ((offset + INITIAL_PAGE_SIZE) &gt;&gt; INDEX_SHIFT).leading_zeros()</code></pre></div>
<p>where <code>WIDTH</code> is the number of bits in a <code>usize</code>, and <code>INDEX_SHIFT</code> is</p>
<div class="example-wrap ignore"><a href="#" class="tooltip" title="This example is not tested"></a><pre class="rust rust-example-rendered"><code>INITIAL_PAGE_SIZE.trailing_zeros() + <span class="number">1</span>;</code></pre></div>
</div></details></section></div></main></body></html>

View file

@ -0,0 +1 @@
window.SIDEBAR_ITEMS = {};

146
sharded_slab/index.html Normal file
View file

@ -0,0 +1,146 @@
<!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="A lock-free concurrent slab."><title>sharded_slab - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.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-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="sharded_slab" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../static.files/storage-59e33391.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-044be391.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="../sharded_slab/index.html">sharded_<wbr>slab</a><span class="version">0.1.7</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="#usage" title="Usage">Usage</a></li><li><a href="#examples" title="Examples">Examples</a></li><li><a href="#configuration" title="Configuration">Configuration</a></li><li><a href="#comparison-with-similar-crates" title="Comparison with Similar Crates">Comparison with Similar Crates</a></li><li><a href="#safety-and-correctness" title="Safety and Correctness">Safety and Correctness</a></li><li><a href="#performance" title="Performance">Performance</a></li><li><a href="#implementation-notes" title="Implementation Notes">Implementation Notes</a></li></ul><h3><a href="#modules">Crate Items</a></h3><ul class="block"><li><a href="#modules" title="Modules">Modules</a></li><li><a href="#structs" title="Structs">Structs</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>sharded_slab</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/sharded_slab/lib.rs.html#1-1106">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A lock-free concurrent slab.</p>
<p>Slabs provide pre-allocated storage for many instances of a single data
type. When a large number of values of a single type are required,
this can be more efficient than allocating each item individually. Since the
allocated items are the same size, memory fragmentation is reduced, and
creating and removing new items can be very cheap.</p>
<p>This crate implements a lock-free concurrent slab, indexed by <code>usize</code>s.</p>
<h3 id="usage"><a class="doc-anchor" href="#usage">§</a>Usage</h3>
<p>First, add this to your <code>Cargo.toml</code>:</p>
<div class="example-wrap"><pre class="language-toml"><code>sharded-slab = &quot;0.1.1&quot;</code></pre></div>
<p>This crate provides two types, <a href="https://crates.io/crates/loom"><code>Slab</code></a> and <a href="struct.Pool.html" title="struct sharded_slab::Pool"><code>Pool</code></a>, which provide
slightly different APIs for using a sharded slab.</p>
<p><a href="https://crates.io/crates/loom"><code>Slab</code></a> implements a slab for <em>storing</em> small types, sharing them between
threads, and accessing them by index. New entries are allocated by
<a href="struct.Slab.html#method.insert" title="method sharded_slab::Slab::insert">inserting</a> data, moving it in by value. Similarly, entries may be
deallocated by <a href="struct.Slab.html#method.take" title="method sharded_slab::Slab::take">taking</a> from the slab, moving the value out. This API is
similar to a <code>Vec&lt;Option&lt;T&gt;&gt;</code>, but allowing lock-free concurrent insertion
and removal.</p>
<p>In contrast, the <a href="struct.Pool.html" title="struct sharded_slab::Pool"><code>Pool</code></a> type provides an <a href="https://en.wikipedia.org/wiki/Object_pool_pattern">object pool</a> style API for
<em>reusing storage</em>. Rather than constructing values and moving them into the
pool, as with <a href="https://crates.io/crates/loom"><code>Slab</code></a>, <a href="struct.Pool.html#method.create" title="method sharded_slab::Pool::create">allocating an entry</a> from the pool takes a
closure thats provided with a mutable reference to initialize the entry in
place. When entries are deallocated, they are <a href="trait.Clear.html" title="trait sharded_slab::Clear">cleared</a> in place. Types
which own a heap allocation can be cleared by dropping any <em>data</em> they
store, but retaining any previously-allocated capacity. This means that a
<a href="struct.Pool.html" title="struct sharded_slab::Pool"><code>Pool</code></a> may be used to reuse a set of existing heap allocations, reducing
allocator load.</p>
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
<p>Inserting an item into the slab, returning an index:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>slab = Slab::new();
<span class="kw">let </span>key = slab.insert(<span class="string">"hello world"</span>).unwrap();
<span class="macro">assert_eq!</span>(slab.get(key).unwrap(), <span class="string">"hello world"</span>);</code></pre></div>
<p>To share a slab across threads, it may be wrapped in an <code>Arc</code>:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::sync::Arc;
<span class="kw">let </span>slab = Arc::new(Slab::new());
<span class="kw">let </span>slab2 = slab.clone();
<span class="kw">let </span>thread2 = std::thread::spawn(<span class="kw">move </span>|| {
<span class="kw">let </span>key = slab2.insert(<span class="string">"hello from thread two"</span>).unwrap();
<span class="macro">assert_eq!</span>(slab2.get(key).unwrap(), <span class="string">"hello from thread two"</span>);
key
});
<span class="kw">let </span>key1 = slab.insert(<span class="string">"hello from thread one"</span>).unwrap();
<span class="macro">assert_eq!</span>(slab.get(key1).unwrap(), <span class="string">"hello from thread one"</span>);
<span class="comment">// Wait for thread 2 to complete.
</span><span class="kw">let </span>key2 = thread2.join().unwrap();
<span class="comment">// The item inserted by thread 2 remains in the slab.
</span><span class="macro">assert_eq!</span>(slab.get(key2).unwrap(), <span class="string">"hello from thread two"</span>);</code></pre></div>
<p>If items in the slab must be mutated, a <code>Mutex</code> or <code>RwLock</code> may be used for
each item, providing granular locking of items rather than of the slab:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::sync::{Arc, Mutex};
<span class="kw">let </span>slab = Arc::new(Slab::new());
<span class="kw">let </span>key = slab.insert(Mutex::new(String::from(<span class="string">"hello world"</span>))).unwrap();
<span class="kw">let </span>slab2 = slab.clone();
<span class="kw">let </span>thread2 = std::thread::spawn(<span class="kw">move </span>|| {
<span class="kw">let </span>hello = slab2.get(key).expect(<span class="string">"item missing"</span>);
<span class="kw">let </span><span class="kw-2">mut </span>hello = hello.lock().expect(<span class="string">"mutex poisoned"</span>);
<span class="kw-2">*</span>hello = String::from(<span class="string">"hello everyone!"</span>);
});
thread2.join().unwrap();
<span class="kw">let </span>hello = slab.get(key).expect(<span class="string">"item missing"</span>);
<span class="kw">let </span><span class="kw-2">mut </span>hello = hello.lock().expect(<span class="string">"mutex poisoned"</span>);
<span class="macro">assert_eq!</span>(hello.as_str(), <span class="string">"hello everyone!"</span>);</code></pre></div>
<h2 id="configuration"><a class="doc-anchor" href="#configuration">§</a>Configuration</h2>
<p>For performance reasons, several values used by the slab are calculated as
constants. In order to allow users to tune the slabs parameters, we provide
a <a href="trait.Config.html"><code>Config</code></a> trait which defines these parameters as associated <code>consts</code>.
The <code>Slab</code> type is generic over a <code>C: Config</code> parameter.</p>
<h2 id="comparison-with-similar-crates"><a class="doc-anchor" href="#comparison-with-similar-crates">§</a>Comparison with Similar Crates</h2>
<ul>
<li>
<p><a href="https://crates.io/crates/loom"><code>slab</code></a>: Carl Lerches <code>slab</code> crate provides a slab implementation with a
similar API, implemented by storing all data in a single vector.</p>
<p>Unlike <code>sharded_slab</code>, inserting and removing elements from the slab
requires mutable access. This means that if the slab is accessed
concurrently by multiple threads, it is necessary for it to be protected
by a <code>Mutex</code> or <code>RwLock</code>. Items may not be inserted or removed (or
accessed, if a <code>Mutex</code> is used) concurrently, even when they are
unrelated. In many cases, the lock can become a significant bottleneck. On
the other hand, this crate allows separate indices in the slab to be
accessed, inserted, and removed concurrently without requiring a global
lock. Therefore, when the slab is shared across multiple threads, this
crate offers significantly better performance than <code>slab</code>.</p>
<p>However, the lock free slab introduces some additional constant-factor
overhead. This means that in use-cases where a slab is <em>not</em> shared by
multiple threads and locking is not required, this crate will likely offer
slightly worse performance.</p>
<p>In summary: <code>sharded-slab</code> offers significantly improved performance in
concurrent use-cases, while <code>slab</code> should be preferred in single-threaded
use-cases.</p>
</li>
</ul>
<h2 id="safety-and-correctness"><a class="doc-anchor" href="#safety-and-correctness">§</a>Safety and Correctness</h2>
<p>Most implementations of lock-free data structures in Rust require some
amount of unsafe code, and this crate is not an exception. In order to catch
potential bugs in this unsafe code, we make use of <a href="https://crates.io/crates/loom"><code>loom</code></a>, a
permutation-testing tool for concurrent Rust programs. All <code>unsafe</code> blocks
this crate occur in accesses to <code>loom</code> <code>UnsafeCell</code>s. This means that when
those accesses occur in this crates tests, <code>loom</code> will assert that they are
valid under the C11 memory model across multiple permutations of concurrent
executions of those tests.</p>
<p>In order to guard against the <a href="https://en.wikipedia.org/wiki/ABA_problem">ABA problem</a>, this crate makes use of
<em>generational indices</em>. Each slot in the slab tracks a generation counter
which is incremented every time a value is inserted into that slot, and the
indices returned by <a href="struct.Slab.html#method.insert"><code>Slab::insert</code></a> include the generation of the slot when
the value was inserted, packed into the high-order bits of the index. This
ensures that if a value is inserted, removed, and a new value is inserted
into the same slot in the slab, the key returned by the first call to
<code>insert</code> will not map to the new value.</p>
<p>Since a fixed number of bits are set aside to use for storing the generation
counter, the counter will wrap around after being incremented a number of
times. To avoid situations where a returned index lives long enough to see the
generation counter wrap around to the same value, it is good to be fairly
generous when configuring the allocation of index bits.</p>
<h2 id="performance"><a class="doc-anchor" href="#performance">§</a>Performance</h2>
<p>These graphs were produced by <a href="https://github.com/hawkw/sharded-slab/blob/master/benches/bench.rs">benchmarks</a> of the sharded slab implementation,
using the <a href="https://crates.io/crates/criterion"><code>criterion</code></a> crate.</p>
<p>The first shows the results of a benchmark where an increasing number of
items are inserted and then removed into a slab concurrently by five
threads. It compares the performance of the sharded slab implementation
with a <code>RwLock&lt;slab::Slab&gt;</code>:</p>
<img width="1124" alt="Screen Shot 2019-10-01 at 5 09 49 PM" src="https://user-images.githubusercontent.com/2796466/66078398-cd6c9f80-e516-11e9-9923-0ed6292e8498.png">
<p>The second graph shows the results of a benchmark where an increasing
number of items are inserted and then removed by a <em>single</em> thread. It
compares the performance of the sharded slab implementation with an
<code>RwLock&lt;slab::Slab&gt;</code> and a <code>mut slab::Slab</code>.</p>
<img width="925" alt="Screen Shot 2019-10-01 at 5 13 45 PM" src="https://user-images.githubusercontent.com/2796466/66078469-f0974f00-e516-11e9-95b5-f65f0aa7e494.png">
<p>These benchmarks demonstrate that, while the sharded approach introduces
a small constant-factor overhead, it offers significantly better
performance across concurrent accesses.</p>
<h2 id="implementation-notes"><a class="doc-anchor" href="#implementation-notes">§</a>Implementation Notes</h2>
<p>See <a href="implementation/index.html" title="mod sharded_slab::implementation">this page</a> for details on this crates design
and implementation.</p>
</div></details><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="implementation/index.html" title="mod sharded_slab::implementation">implementation</a></div><div class="desc docblock-short">Notes on <code>sharded-slab</code>s implementation and design.</div></li><li><div class="item-name"><a class="mod" href="pool/index.html" title="mod sharded_slab::pool">pool</a></div><div class="desc docblock-short">A lock-free concurrent object pool.</div></li></ul><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.DefaultConfig.html" title="struct sharded_slab::DefaultConfig">Default<wbr>Config</a></div><div class="desc docblock-short">Default slab configuration values.</div></li><li><div class="item-name"><a class="struct" href="struct.Entry.html" title="struct sharded_slab::Entry">Entry</a></div><div class="desc docblock-short">A handle that allows access to an occupied entry in a <a href="struct.Slab.html" title="struct sharded_slab::Slab"><code>Slab</code></a>.</div></li><li><div class="item-name"><a class="struct" href="struct.OwnedEntry.html" title="struct sharded_slab::OwnedEntry">Owned<wbr>Entry</a></div><div class="desc docblock-short">An owned reference to an occupied entry in a <a href="struct.Slab.html" title="struct sharded_slab::Slab"><code>Slab</code></a>.</div></li><li><div class="item-name"><a class="struct" href="struct.Pool.html" title="struct sharded_slab::Pool">Pool</a></div><div class="desc docblock-short">A lock-free concurrent object pool.</div></li><li><div class="item-name"><a class="struct" href="struct.Slab.html" title="struct sharded_slab::Slab">Slab</a></div><div class="desc docblock-short">A sharded slab.</div></li><li><div class="item-name"><a class="struct" href="struct.UniqueIter.html" title="struct sharded_slab::UniqueIter">Unique<wbr>Iter</a></div><div class="desc docblock-short">An exclusive fused iterator over the items in a <a href="struct.Slab.html" title="struct sharded_slab::Slab"><code>Slab</code></a>.</div></li><li><div class="item-name"><a class="struct" href="struct.VacantEntry.html" title="struct sharded_slab::VacantEntry">Vacant<wbr>Entry</a></div><div class="desc docblock-short">A handle to a vacant entry in a <a href="struct.Slab.html" title="struct sharded_slab::Slab"><code>Slab</code></a>.</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.Clear.html" title="trait sharded_slab::Clear">Clear</a></div><div class="desc docblock-short">Trait implemented by types which can be cleared in place, retaining any
allocated memory.</div></li><li><div class="item-name"><a class="trait" href="trait.Config.html" title="trait sharded_slab::Config">Config</a></div><div class="desc docblock-short">Configuration parameters which can be overridden to tune the behavior of a slab.</div></li></ul></section></div></main></body></html>

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../sharded_slab/struct.UniqueIter.html">
<title>Redirection</title>
</head>
<body>
<p>Redirecting to <a href="../../sharded_slab/struct.UniqueIter.html">../../sharded_slab/struct.UniqueIter.html</a>...</p>
<script>location.replace("../../sharded_slab/struct.UniqueIter.html" + location.search + location.hash);</script>
</body>
</html>

View file

@ -0,0 +1,4 @@
<!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="A lock-free concurrent object pool."><title>sharded_slab::pool - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.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-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="sharded_slab" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../sharded_slab/index.html">sharded_<wbr>slab</a><span class="version">0.1.7</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module pool</a></h2><h3><a href="#structs">Module Items</a></h3><ul class="block"><li><a href="#structs" title="Structs">Structs</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="../index.html">In crate sharded_<wbr>slab</a></h2></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"><span class="rustdoc-breadcrumbs"><a href="../index.html">sharded_slab</a></span><h1>Module <span>pool</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/sharded_slab/pool.rs.html#1-1342">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A lock-free concurrent object pool.</p>
<p>See the <a href="../struct.Pool.html"><code>Pool</code> types documentation</a> for details on the object pool API and how
it differs from the <a href="../struct.Slab.html"><code>Slab</code></a> API.</p>
</div></details><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.OwnedRef.html" title="struct sharded_slab::pool::OwnedRef">Owned<wbr>Ref</a></div><div class="desc docblock-short">An owned guard that allows shared immutable access to an object in a pool.</div></li><li><div class="item-name"><a class="struct" href="struct.OwnedRefMut.html" title="struct sharded_slab::pool::OwnedRefMut">Owned<wbr>RefMut</a></div><div class="desc docblock-short">An owned guard that allows exclusive, mutable access to an object in a pool.</div></li><li><div class="item-name"><a class="struct" href="struct.Pool.html" title="struct sharded_slab::pool::Pool">Pool</a></div><div class="desc docblock-short">A lock-free concurrent object pool.</div></li><li><div class="item-name"><a class="struct" href="struct.Ref.html" title="struct sharded_slab::pool::Ref">Ref</a></div><div class="desc docblock-short">A guard that allows access to an object in a pool.</div></li><li><div class="item-name"><a class="struct" href="struct.RefMut.html" title="struct sharded_slab::pool::RefMut">RefMut</a></div><div class="desc docblock-short">A guard that allows exclusive mutable access to an object in a pool.</div></li></ul></section></div></main></body></html>

View file

@ -0,0 +1 @@
window.SIDEBAR_ITEMS = {"struct":["OwnedRef","OwnedRefMut","Pool","Ref","RefMut"]};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1 @@
window.SIDEBAR_ITEMS = {"mod":["implementation","pool"],"struct":["DefaultConfig","Entry","OwnedEntry","Pool","Slab","UniqueIter","VacantEntry"],"trait":["Clear","Config"]};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,25 @@
<!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="Trait implemented by types which can be cleared in place, retaining any allocated memory."><title>Clear in sharded_slab - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.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-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="sharded_slab" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-044be391.svg"></head><body class="rustdoc trait"><!--[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="../sharded_slab/index.html">sharded_<wbr>slab</a><span class="version">0.1.7</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Clear</a></h2><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.clear" title="clear">clear</a></li></ul><h3><a href="#foreign-impls">Implementations on Foreign Types</a></h3><ul class="block"><li><a href="#impl-Clear-for-Box%3CT%3E" title="Box&#60;T&#62;">Box&#60;T&#62;</a></li><li><a href="#impl-Clear-for-HashMap%3CK,+V,+S%3E" title="HashMap&#60;K, V, S&#62;">HashMap&#60;K, V, S&#62;</a></li><li><a href="#impl-Clear-for-HashSet%3CT,+S%3E" title="HashSet&#60;T, S&#62;">HashSet&#60;T, S&#62;</a></li><li><a href="#impl-Clear-for-Mutex%3CT%3E" title="Mutex&#60;T&#62;">Mutex&#60;T&#62;</a></li><li><a href="#impl-Clear-for-Option%3CT%3E" title="Option&#60;T&#62;">Option&#60;T&#62;</a></li><li><a href="#impl-Clear-for-RwLock%3CT%3E" title="RwLock&#60;T&#62;">RwLock&#60;T&#62;</a></li><li><a href="#impl-Clear-for-String" title="String">String</a></li><li><a href="#impl-Clear-for-Vec%3CT%3E" title="Vec&#60;T&#62;">Vec&#60;T&#62;</a></li></ul><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="index.html">In crate sharded_<wbr>slab</a></h2></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"><span class="rustdoc-breadcrumbs"><a href="index.html">sharded_slab</a></span><h1>Trait <span class="trait">Clear</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/sharded_slab/clear.rs.html#24-27">Source</a> </span></div><pre class="rust item-decl"><code>pub trait Clear {
// Required method
fn <a href="#tymethod.clear" class="fn">clear</a>(&amp;mut self);
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Trait implemented by types which can be cleared in place, retaining any
allocated memory.</p>
<p>This is essentially a generalization of methods on standard library
collection types, including as <a href="https://doc.rust-lang.org/stable/std/vec/struct.Vec.html#method.clear"><code>Vec::clear</code></a>, <a href="https://doc.rust-lang.org/stable/std/string/struct.String.html#method.clear"><code>String::clear</code></a>, and
<a href="https://doc.rust-lang.org/stable/std/collections/struct.HashMap.html#method.clear"><code>HashMap::clear</code></a>. These methods drop all data stored in the collection,
but retain the collections heap allocation for future use. Types such as
<code>BTreeMap</code>, whose <code>clear</code> methods drops allocations, should not
implement this trait.</p>
<p>When implemented for types which do not own a heap allocation, <code>Clear</code>
should reset the type in place if possible. If the type has an empty state
or stores <code>Option</code>s, those values should be reset to the empty state. For
“plain old data” types, which hold no pointers to other data and do not have
an empty or initial state, its okay for a <code>Clear</code> implementation to be a
no-op. In that case, it essentially serves as a marker indicating that the
type may be reused to store new data.</p>
</div></details><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="tymethod.clear" class="method"><a class="src rightside" href="../src/sharded_slab/clear.rs.html#26">Source</a><h4 class="code-header">fn <a href="#tymethod.clear" class="fn">clear</a>(&amp;mut self)</h4></section></summary><div class="docblock"><p>Clear all data in <code>self</code>, retaining the allocated capacithy.</p>
</div></details></div><h2 id="foreign-impls" class="section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor">§</a></h2><details class="toggle implementors-toggle"><summary><section id="impl-Clear-for-String" class="impl"><a class="src rightside" href="../src/sharded_slab/clear.rs.html#74-79">Source</a><a href="#impl-Clear-for-String" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.Clear.html" title="trait sharded_slab::Clear">Clear</a> for <a class="struct" href="https://doc.rust-lang.org/1.84.1/alloc/string/struct.String.html" title="struct alloc::string::String">String</a></h3></section></summary><div class="impl-items"><section id="method.clear" class="method trait-impl"><a class="src rightside" href="../src/sharded_slab/clear.rs.html#76-78">Source</a><a href="#method.clear" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.clear" class="fn">clear</a>(&amp;mut self)</h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Clear-for-HashMap%3CK,+V,+S%3E" class="impl"><a class="src rightside" href="../src/sharded_slab/clear.rs.html#52-61">Source</a><a href="#impl-Clear-for-HashMap%3CK,+V,+S%3E" class="anchor">§</a><h3 class="code-header">impl&lt;K, V, S&gt; <a class="trait" href="trait.Clear.html" title="trait sharded_slab::Clear">Clear</a> for <a class="struct" href="https://doc.rust-lang.org/1.84.1/std/collections/hash/map/struct.HashMap.html" title="struct std::collections::hash::map::HashMap">HashMap</a>&lt;K, V, S&gt;<div class="where">where
K: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a> + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a>,
S: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/hash/trait.BuildHasher.html" title="trait core::hash::BuildHasher">BuildHasher</a>,</div></h3></section></summary><div class="impl-items"><section id="method.clear-1" class="method trait-impl"><a class="src rightside" href="../src/sharded_slab/clear.rs.html#58-60">Source</a><a href="#method.clear-1" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.clear" class="fn">clear</a>(&amp;mut self)</h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Clear-for-Option%3CT%3E" class="impl"><a class="src rightside" href="../src/sharded_slab/clear.rs.html#29-33">Source</a><a href="#impl-Clear-for-Option%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="trait.Clear.html" title="trait sharded_slab::Clear">Clear</a> for <a class="enum" href="https://doc.rust-lang.org/1.84.1/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;T&gt;</h3></section></summary><div class="impl-items"><section id="method.clear-2" class="method trait-impl"><a class="src rightside" href="../src/sharded_slab/clear.rs.html#30-32">Source</a><a href="#method.clear-2" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.clear" class="fn">clear</a>(&amp;mut self)</h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Clear-for-Box%3CT%3E" class="impl"><a class="src rightside" href="../src/sharded_slab/clear.rs.html#35-43">Source</a><a href="#impl-Clear-for-Box%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="trait.Clear.html" title="trait sharded_slab::Clear">Clear</a> for <a class="struct" href="https://doc.rust-lang.org/1.84.1/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a>&lt;T&gt;<div class="where">where
T: <a class="trait" href="trait.Clear.html" title="trait sharded_slab::Clear">Clear</a>,</div></h3></section></summary><div class="impl-items"><section id="method.clear-3" class="method trait-impl"><a class="src rightside" href="../src/sharded_slab/clear.rs.html#40-42">Source</a><a href="#method.clear-3" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.clear" class="fn">clear</a>(&amp;mut self)</h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Clear-for-Vec%3CT%3E" class="impl"><a class="src rightside" href="../src/sharded_slab/clear.rs.html#45-50">Source</a><a href="#impl-Clear-for-Vec%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="trait.Clear.html" title="trait sharded_slab::Clear">Clear</a> for <a class="struct" href="https://doc.rust-lang.org/1.84.1/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;T&gt;</h3></section></summary><div class="impl-items"><section id="method.clear-4" class="method trait-impl"><a class="src rightside" href="../src/sharded_slab/clear.rs.html#47-49">Source</a><a href="#method.clear-4" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.clear" class="fn">clear</a>(&amp;mut self)</h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Clear-for-HashSet%3CT,+S%3E" class="impl"><a class="src rightside" href="../src/sharded_slab/clear.rs.html#63-72">Source</a><a href="#impl-Clear-for-HashSet%3CT,+S%3E" class="anchor">§</a><h3 class="code-header">impl&lt;T, S&gt; <a class="trait" href="trait.Clear.html" title="trait sharded_slab::Clear">Clear</a> for <a class="struct" href="https://doc.rust-lang.org/1.84.1/std/collections/hash/set/struct.HashSet.html" title="struct std::collections::hash::set::HashSet">HashSet</a>&lt;T, S&gt;<div class="where">where
T: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a> + <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a>,
S: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/hash/trait.BuildHasher.html" title="trait core::hash::BuildHasher">BuildHasher</a>,</div></h3></section></summary><div class="impl-items"><section id="method.clear-5" class="method trait-impl"><a class="src rightside" href="../src/sharded_slab/clear.rs.html#69-71">Source</a><a href="#method.clear-5" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.clear" class="fn">clear</a>(&amp;mut self)</h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Clear-for-Mutex%3CT%3E" class="impl"><a class="src rightside" href="../src/sharded_slab/clear.rs.html#81-86">Source</a><a href="#impl-Clear-for-Mutex%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;T: <a class="trait" href="trait.Clear.html" title="trait sharded_slab::Clear">Clear</a>&gt; <a class="trait" href="trait.Clear.html" title="trait sharded_slab::Clear">Clear</a> for <a class="struct" href="https://doc.rust-lang.org/1.84.1/std/sync/mutex/struct.Mutex.html" title="struct std::sync::mutex::Mutex">Mutex</a>&lt;T&gt;</h3></section></summary><div class="impl-items"><section id="method.clear-6" class="method trait-impl"><a class="src rightside" href="../src/sharded_slab/clear.rs.html#83-85">Source</a><a href="#method.clear-6" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.clear" class="fn">clear</a>(&amp;mut self)</h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Clear-for-RwLock%3CT%3E" class="impl"><a class="src rightside" href="../src/sharded_slab/clear.rs.html#88-93">Source</a><a href="#impl-Clear-for-RwLock%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;T: <a class="trait" href="trait.Clear.html" title="trait sharded_slab::Clear">Clear</a>&gt; <a class="trait" href="trait.Clear.html" title="trait sharded_slab::Clear">Clear</a> for <a class="struct" href="https://doc.rust-lang.org/1.84.1/std/sync/rwlock/struct.RwLock.html" title="struct std::sync::rwlock::RwLock">RwLock</a>&lt;T&gt;</h3></section></summary><div class="impl-items"><section id="method.clear-7" class="method trait-impl"><a class="src rightside" href="../src/sharded_slab/clear.rs.html#90-92">Source</a><a href="#method.clear-7" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.clear" class="fn">clear</a>(&amp;mut self)</h4></section></div></details><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"></div><script src="../trait.impl/sharded_slab/clear/trait.Clear.js" data-ignore-extern-crates="core,alloc,std" async></script></section></div></main></body></html>

View file

@ -0,0 +1,29 @@
<!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="Configuration parameters which can be overridden to tune the behavior of a slab."><title>Config in sharded_slab - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.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-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="sharded_slab" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-044be391.svg"></head><body class="rustdoc trait"><!--[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="../sharded_slab/index.html">sharded_<wbr>slab</a><span class="version">0.1.7</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Config</a></h2><h3><a href="#provided-associated-consts">Provided Associated Constants</a></h3><ul class="block"><li><a href="#associatedconstant.INITIAL_PAGE_SIZE" title="INITIAL_PAGE_SIZE">INITIAL_PAGE_SIZE</a></li><li><a href="#associatedconstant.MAX_PAGES" title="MAX_PAGES">MAX_PAGES</a></li><li><a href="#associatedconstant.MAX_THREADS" title="MAX_THREADS">MAX_THREADS</a></li><li><a href="#associatedconstant.RESERVED_BITS" title="RESERVED_BITS">RESERVED_BITS</a></li></ul><h3><a href="#dyn-compatibility">Dyn Compatibility</a></h3><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="index.html">In crate sharded_<wbr>slab</a></h2></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"><span class="rustdoc-breadcrumbs"><a href="index.html">sharded_slab</a></span><h1>Trait <span class="trait">Config</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/sharded_slab/cfg.rs.html#8-40">Source</a> </span></div><pre class="rust item-decl"><code>pub trait Config: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> {
const <a href="#associatedconstant.MAX_THREADS" class="constant">MAX_THREADS</a>: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a> = 4_096usize;
const <a href="#associatedconstant.MAX_PAGES" class="constant">MAX_PAGES</a>: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a> = 32usize;
const <a href="#associatedconstant.INITIAL_PAGE_SIZE" class="constant">INITIAL_PAGE_SIZE</a>: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a> = 32usize;
const <a href="#associatedconstant.RESERVED_BITS" class="constant">RESERVED_BITS</a>: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a> = 0usize;
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Configuration parameters which can be overridden to tune the behavior of a slab.</p>
</div></details><h2 id="provided-associated-consts" class="section-header">Provided Associated Constants<a href="#provided-associated-consts" class="anchor">§</a></h2><div class="methods"><details class="toggle" open><summary><section id="associatedconstant.MAX_THREADS" class="method"><a class="src rightside" href="../src/sharded_slab/cfg.rs.html#15">Source</a><h4 class="code-header">const <a href="#associatedconstant.MAX_THREADS" class="constant">MAX_THREADS</a>: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a> = 4_096usize</h4></section></summary><div class="docblock"><p>The maximum number of threads which can access the slab.</p>
<p>This value (rounded to a power of two) determines the number of shards
in the slab. If a thread is created, accesses the slab, and then terminates,
its shard may be reused and thus does not count against the maximum
number of threads once the thread has terminated.</p>
</div></details><details class="toggle" open><summary><section id="associatedconstant.MAX_PAGES" class="method"><a class="src rightside" href="../src/sharded_slab/cfg.rs.html#20">Source</a><h4 class="code-header">const <a href="#associatedconstant.MAX_PAGES" class="constant">MAX_PAGES</a>: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a> = 32usize</h4></section></summary><div class="docblock"><p>The maximum number of pages in each shard in the slab.</p>
<p>This value, in combination with <code>INITIAL_PAGE_SIZE</code>, determines how many
bits of each index are used to represent page addresses.</p>
</div></details><details class="toggle" open><summary><section id="associatedconstant.INITIAL_PAGE_SIZE" class="method"><a class="src rightside" href="../src/sharded_slab/cfg.rs.html#30">Source</a><h4 class="code-header">const <a href="#associatedconstant.INITIAL_PAGE_SIZE" class="constant">INITIAL_PAGE_SIZE</a>: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a> = 32usize</h4></section></summary><div class="docblock"><p>The size of the first page in each shard.</p>
<p>When a page in a shard has been filled with values, a new page
will be allocated that is twice as large as the previous page. Thus, the
second page will be twice this size, and the third will be four times
this size, and so on.</p>
<p>Note that page sizes must be powers of two. If this value is not a power
of two, it will be rounded to the next power of two.</p>
</div></details><details class="toggle" open><summary><section id="associatedconstant.RESERVED_BITS" class="method"><a class="src rightside" href="../src/sharded_slab/cfg.rs.html#39">Source</a><h4 class="code-header">const <a href="#associatedconstant.RESERVED_BITS" class="constant">RESERVED_BITS</a>: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a> = 0usize</h4></section></summary><div class="docblock"><p>Sets a number of high-order bits in each index which are reserved from
user code.</p>
<p>Note that these bits are taken from the generation counter; if the page
address and thread IDs are configured to use a large number of bits,
reserving additional bits will decrease the period of the generation
counter. These should thus be used relatively sparingly, to ensure that
generation counters are able to effectively prevent the ABA problem.</p>
</div></details></div><h2 id="dyn-compatibility" class="section-header">Dyn Compatibility<a href="#dyn-compatibility" class="anchor">§</a></h2><div class="dyn-compatibility-info"><p>This trait is <b>not</b> <a href="https://doc.rust-lang.org/1.84.1/reference/items/traits.html#object-safety">dyn compatible</a>.</p><p><i>In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.</i></p></div><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><details class="toggle implementors-toggle"><summary><section id="impl-Config-for-DefaultConfig" class="impl"><a class="src rightside" href="../src/sharded_slab/cfg.rs.html#136-146">Source</a><a href="#impl-Config-for-DefaultConfig" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.Config.html" title="trait sharded_slab::Config">Config</a> for <a class="struct" href="struct.DefaultConfig.html" title="struct sharded_slab::DefaultConfig">DefaultConfig</a></h3></section></summary><div class="impl-items"><section id="associatedconstant.INITIAL_PAGE_SIZE-1" class="associatedconstant trait-impl"><a class="src rightside" href="../src/sharded_slab/cfg.rs.html#137">Source</a><a href="#associatedconstant.INITIAL_PAGE_SIZE-1" class="anchor">§</a><h4 class="code-header">const <a href="#associatedconstant.INITIAL_PAGE_SIZE" class="constant">INITIAL_PAGE_SIZE</a>: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a> = 32usize</h4></section><section id="associatedconstant.MAX_THREADS-1" class="associatedconstant trait-impl"><a class="src rightside" href="../src/sharded_slab/cfg.rs.html#140">Source</a><a href="#associatedconstant.MAX_THREADS-1" class="anchor">§</a><h4 class="code-header">const <a href="#associatedconstant.MAX_THREADS" class="constant">MAX_THREADS</a>: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a> = 4_096usize</h4></section><section id="associatedconstant.MAX_PAGES-1" class="associatedconstant trait-impl"><a class="src rightside" href="../src/sharded_slab/cfg.rs.html#145">Source</a><a href="#associatedconstant.MAX_PAGES-1" class="anchor">§</a><h4 class="code-header">const <a href="#associatedconstant.MAX_PAGES" class="constant">MAX_PAGES</a>: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a> = 32usize</h4></section></div></details></div><script src="../trait.impl/sharded_slab/cfg/trait.Config.js" async></script></section></div></main></body></html>