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