Skip to main content

paged_collections/
lib.rs

1//! Paged collections: containers whose memory is split into fixed-size pages.
2//!
3//! Paging serves two separate purposes, and each collection states which it uses:
4//!
5//! - **Paged index.** A lookup table indexed by key is split into pages that are
6//!   allocated on first use, so memory follows the occupied key ranges rather than
7//!   the largest key ever inserted.
8//! - **Paged storage.** Elements live in fixed-size pages that never move, so
9//!   references and pointers to elements stay valid while the collection grows.
10//!
11//! # Collections
12//!
13//! | Module | Type | Paging |
14//! |---|---|---|
15//! | [`sparse_set`] | `PagedSparseSet<K>` | index; storage optional |
16//! | [`sparse_map`] | `PagedSparseMap<K, V>` | index; storage optional |
17//! | [`priority_queue`] | `PagedPriorityQueue<K, P>` | index (indexed max-heap) |
18//! | [`direct_map`] | `PagedDirectMap<K, V>` | index (values in place, slot order) |
19//! | [`bit_set`] | `PagedBitSet<K>` | index (1 bit per slot) |
20//! | [`paged_vec`] | `PagedVec<T>` | storage (stable addresses) |
21//! | [`paged_deque`] | `PagedDeque<T>` | storage (stable addresses, double-ended) |
22//! | [`hive`] | `Hive<T>` | storage (stable addresses, reusable slots, generational ids) |
23//! | [`id_alloc`] | `IdAllocator`, `Id` | none (free list of generational ids) |
24//!
25//! Shared building blocks live in [`key`] (how a key maps to an index) and
26//! [`page`] (the page directory).
27//!
28//! # Features
29//!
30//! - `std` (default): `std`-only conveniences. Without it the crate is `no_std`
31//!   and needs only `alloc`.
32//! - `serde`: serialization support.
33//! - `rayon`: parallel iteration through `rayon::prelude`. Enables `std`.
34//! - `concurrent`: thread-safe variants in [`concurrent`], which use `unsafe`
35//!   code and atomics. Includes an MPMC FIFO `ConcurrentQueue` that waits at
36//!   page boundaries and a sharded `ConcurrentPriorityQueue` with relaxed
37//!   `pop` and exact `pop_exact`. Off by default.
38
39#![no_std]
40#![cfg_attr(docsrs, feature(doc_cfg))]
41
42extern crate alloc;
43#[cfg(feature = "std")]
44extern crate std;
45
46pub mod bit_set;
47// Needs pointer-sized and 64-bit atomics, and `u32` indices that fit `usize`.
48#[cfg(all(
49    feature = "concurrent",
50    target_has_atomic = "ptr",
51    target_has_atomic = "64",
52    any(target_pointer_width = "32", target_pointer_width = "64")
53))]
54#[cfg_attr(docsrs, doc(cfg(feature = "concurrent")))]
55pub mod concurrent;
56pub mod direct_map;
57mod hash;
58// Slot indices are `u32` and must convert to `usize` without loss.
59#[cfg(any(target_pointer_width = "32", target_pointer_width = "64"))]
60pub mod hive;
61// Indices are `u32` and must convert to `usize` without loss.
62#[cfg(any(target_pointer_width = "32", target_pointer_width = "64"))]
63pub mod id_alloc;
64pub mod key;
65pub mod page;
66pub mod paged_deque;
67pub mod paged_vec;
68pub mod priority_queue;
69pub mod sparse_map;
70pub mod sparse_set;
71
72// Runs the README's Rust examples as doctests.
73#[cfg(all(doctest, any(target_pointer_width = "32", target_pointer_width = "64")))]
74#[doc = include_str!("../README.md")]
75struct ReadmeDoctests;