Crate vers_vecs

source ·
Expand description

This crate provides a collection of data structures supported by fast implementations of rank and select queries. The data structures are static, meaning that they cannot be modified after they have been created.

§Data structures

  • Bit-Vector with no overhead. The only data structure that can be modified after creation.
  • Succinct Bit-Vector supporting fast rank and select queries.
  • Elias-Fano encoding of monotone sequences supporting constant-time predecessor queries.
  • Two Range Minimum Query structures for constant-time range minimum queries.
  • Wavelet Matrix encoding k-bit symbols, supporting rank, select, statistical, and predecessor/successor queries in O(k).

§Performance

Performance was benchmarked against publicly available implementations of the same (or similar) data structures on crates.io. Vers is among the fastest for all benchmarked operations. The benchmark results can be found in the Benchmark repository. Some tradeoffs between average time, worst-case time, and available API features should be taken into consideration when selecting among the fastest libraries (see the GitHub repository for a discussion).

§Intrinsics

This crate uses compiler intrinsics for bit-manipulation. The intrinsics are supported by all modern x86_64 CPUs, but not by other architectures. The crate will compile on other architectures using fallback implementations, but the performance will be significantly worse. It is strongly recommended to enable the BMI2 and popcnt target features when using this crate.

The intrinsics in question are popcnt (supported since SSE4.2 resp. SSE4a on AMD, 2007-2008), pdep (supported with BMI2 since Intel Haswell resp. AMD Excavator, in hardware since AMD Zen 3, 2011-2013), and tzcnt (supported with BMI1 since Intel Haswell resp. AMD Jaguar, ca. 2013).

§Safety

When the simd crate feature is not enabled (default), this crate uses no unsafe code, with the only exception being compiler intrinsics for bit-manipulation. The intrinsics cannot fail with their inputs (provided they are supported by the target machine), so even if they were to be implemented incorrectly, no memory safety issues would arise.

§Crate Features

  • simd (disabled by default): Enables the use of SIMD instructions in the RsVec implementation, and an additional iterator for the RsVec data structure.
  • serde (disabled by default): Enables serialization and deserialization support for all data structures in this crate using the serde crate.

Re-exports§

Modules§

  • This module contains a simple bit vector implementation with no overhead and a fast succinct bit vector implementation with rank and select queries.
  • Elias-Fano encoding for sorted vectors of u64 values. It reduces the space required to represent all numbers (compression ratio dependent on data) and allows for constant-time predecessor queries.
  • Range minimum query data structures. These data structures allow for the calculation of the index of the minimum element in a range of a static array in constant-time. The implementations are located in the binary_rmq and fast_rmq modules.

Structs§

  • A wavelet matrix implementation implemented as described in Navarro and Claude, 2021. The implementation is designed to allow for extremely large alphabet sizes, without sacrificing performance for small alphabets.