vers_vecs/
lib.rs

1#![warn(missing_docs)]
2#![allow(clippy::module_name_repetitions)]
3#![allow(clippy::assertions_on_constants)] // for asserts warning about incompatible constant values
4#![allow(clippy::inline_always)] // we actually measure performance increases with most of these
5#![cfg_attr(docsrs, feature(doc_cfg))] // for conditional compilation in docs
6
7//! This crate provides a collection of data structures supported by fast implementations of
8//! rank and select queries. The data structures are static, meaning that they cannot be modified
9//! after they have been created.
10//!
11//! # Data structures
12//!  - [Bit-Vector][bit_vec::BitVec] with no overhead. The only data structure that can be modified after creation.
13//!  - [Succinct Bit-Vector][bit_vec::fast_rs_vec::RsVec] supporting fast rank and select queries.
14//!  - [Elias-Fano][elias_fano::EliasFanoVec] encoding of monotone sequences supporting constant-time predecessor queries.
15//!  - Two [Range Minimum Query][rmq] structures for constant-time range minimum queries.
16//!  - [Wavelet Matrix][wavelet::WaveletMatrix] encoding `k`-bit symbols, supporting rank, select, statistical, and predecessor/successor queries in `O(k)`.
17//!  - [Succinct Tree][trees::bp::BpTree] supporting tree navigation in `O(log n)` time,
18//!    as well as subtree size, level-order, and ancestor queries, and fast depth-first iteration.
19//!
20//! # Performance
21//! Performance was benchmarked against publicly available implementations of the same (or similar)
22//! data structures on crates.io.
23//! Vers is among the fastest for all benchmarked operations.
24//! The benchmark results can be found
25//! in the [Benchmark repository](https://github.com/Cydhra/vers_benchmarks).
26//! Some tradeoffs between average time, worst-case time, and available API features should be taken
27//! into consideration when selecting among the fastest libraries
28//! (see the GitHub repository for a discussion).
29//!
30//! # Intrinsics
31//! This crate uses compiler intrinsics for bit-manipulation. The intrinsics are supported by
32//! all modern ``x86_64`` CPUs, but not by other architectures. The crate will compile on other
33//! architectures using fallback implementations,
34//! but the performance will be significantly worse. It is strongly recommended to
35//! enable the ``BMI2`` and ``popcnt`` target features when using this crate.
36//!
37//! The intrinsics in question are `popcnt` (supported since ``SSE4.2`` resp. ``SSE4a`` on AMD, 2007-2008),
38//! `pdep` (supported with ``BMI2`` since Intel Haswell resp. AMD Excavator, in hardware since AMD Zen 3, 2011-2013),
39//! and `tzcnt` (supported with ``BMI1`` since Intel Haswell resp. AMD Jaguar, ca. 2013).
40//!
41//! # Safety
42//! When the `simd` crate feature is not enabled (default),
43//! this crate uses no unsafe code, with the only exception being compiler intrinsics for
44//! bit-manipulation, if available.
45//! The intrinsics do not operate on addresses, so even if they were to be implemented incorrectly,
46//! no memory safety issues would arise.
47//!
48//! The `simd` crate feature adds SIMD implementations to some of the operations (notably `select`)
49//! which do operate on pointers.
50//!
51//! # Crate Features
52//! - `simd` (disabled by default): Enables the use of SIMD instructions in the `RsVec`
53//!   implementation, and an additional iterator for the `RsVec` data structure.
54//! - `serde` (disabled by default): Enables serialization and deserialization support for all
55//!   data structures in this crate using the `serde` crate.
56//! - `bp_u16_lookup` (disabled by default): Uses a 16-bit lookup table for the balanced parenthesis
57//!   tree data structure. This is faster, but requires 128 KiB instead of 4 KiB.
58
59pub use bit_vec::fast_rs_vec::RsVec;
60pub use bit_vec::sparse::SparseRSVec;
61pub use bit_vec::BitVec;
62pub use elias_fano::EliasFanoVec;
63pub use rmq::binary_rmq::BinaryRmq;
64pub use rmq::fast_rmq::FastRmq;
65pub use trees::bp::{BpBuilder, BpTree};
66pub use trees::{IsAncestor, LevelTree, SubtreeSize, Tree, TreeBuilder};
67pub use wavelet::WaveletMatrix;
68
69pub mod bit_vec;
70
71#[forbid(unsafe_code)]
72pub mod elias_fano;
73
74#[forbid(unsafe_code)]
75pub mod rmq;
76
77#[forbid(unsafe_code)]
78pub mod trees;
79
80#[forbid(unsafe_code)]
81pub mod wavelet;
82
83pub(crate) mod util;