Crates.io | chtholly_tree |
lib.rs | chtholly_tree |
version | 1.0.0 |
source | src |
created_at | 2022-05-28 08:18:52.053545 |
updated_at | 2022-05-28 08:28:27.395976 |
description | Rust bindings for Chtholly Tree |
homepage | |
repository | https://github.com/shanmo/chtholly_tree.git |
max_upload_size | |
id | 595640 |
size | 7,947 |
Chtholly Tree
in RustChtholly Tree
is a data structure originated from C. Willem, Chtholly and Seniorious, which could be used to update the values of intervalsO(nloglogn)
[dependencies]
chtholly_tree = "1.0.0"
To demonstrate its usage, leetcode 699. Falling Squares is used as an example
#[cfg(test)]
mod tests {
use super::*;
/// Test Chtholly Tree using [leetcode 699. Falling Squares](https://leetcode.com/problems/falling-squares/).
#[test]
fn test_tree() {
let positions = vec![vec![1, 2], vec![2, 3], vec![6, 1]];
let mut results = Vec::<i32>::new();
let mut max_height = 0;
let mut ct_tree = ChthollyTree::new();
ct_tree.assign(1_i32, 10i32.pow(8), 0_i32);
for pos in positions {
let itr = ct_tree.split(pos[0] + pos[1]);
let itl = ct_tree.split(pos[0]);
let mut height = 0;
for i in itl..itr + 1 {
height = height.max(ct_tree.nodes[i].value + pos[1]);
max_height = max_height.max(height);
}
ct_tree.assign(pos[0], pos[0] + pos[1] - 1, height);
results.push(max_height);
}
assert_eq!(results, vec![2, 5, 5]);
}
}
This repo is inspired by