sparse_table 0.1.2

SparseTable Struct / ST表数据结构
Documentation
  • Coverage
  • 0%
    0 out of 5 items documented0 out of 3 items with examples
  • Size
  • Source code size: 4.59 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 280.84 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 8s Average build duration of successful builds.
  • all releases: 8s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • DawnMagnet/SparseTable
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • DawnMagnet

使用Rust实现的ST表(Sparse Table)

English Version
ST表是一类高效的数组结构,在利用O(n*log2(n))的时间建完索引后,就可以使用O(1)的时间查询区间最大值/最小值/最大公约数等。是一个非常高效的数据结构。

用法:

  • Cargo.toml里添加依赖
sparse_table = "*"

例子:

use sparse_table::SparseTable;
use std::cmp::max;

fn main() {
    let spt = SparseTable::init(&vec![5, 3, 8, 10, 1], max);
    println!("{:?}", spt.dp);
    dbg!(spt.query(0, 4));
}

输出结果:

[[5, 5, 10, 0], [3, 8, 10, 0], [8, 10, 0, 0], [10, 10, 0, 0], [1, 0, 0, 0]]
[src\main.rs:7] spt.query(0, 4) = 10

如果给入的函数是max,则query返回的就是区间最大值,如果给入的是gcd,返回的就是区间gcd