The Wavelet Matrix is a space-efficient variant of Wavelet Tree data structure. - https://en.wikipedia.org/wiki/Wavelet_Tree
Add to Cargo.toml:
[dependencies]
wavelet-matrix = "0.2.0"
Add to lib.rs or main.rs
extern crate wavelet_matrix; // Note: underscore is used here
Add to main.rs: ``` use wavelet_matrix::*;
fn main() { let vec = vec![1, 2, 4, 5, 1, 0, 4, 6, 2, 9, 2, 0];
let wm = WaveletMatrix::new(vec);
assert_eq!(wm.len(), 12);
assert_eq!(wm.lookup(7), 6);
assert_eq!(wm.rank(5, 1), 2);
assert_eq!(wm.select(2, 2), Some(10));
println!("Worked as expected!");
} ```
Given unsigned integer sequence A, it provides the following queries:
- .len()
: returns the length of A.
- .lookup(pos)
: returns the value at the position pos of A, A[pos].
- .rank(pos, value)
: counts value included in A[0..pos].
- Note: pos is exclusive. When pos is 0, .rank() always returns 0.
- .select(rank, value)
: return the position of the (rank+1)-th value
- Note: When found nothing, it returns .len() instead of None.
.prefix_rank()
and .prefix_select()
. They will be much faster and useful for IPv4 prefix search (eg. searching for 192.168.12.0/24)..rank_less_than()
and the variations with the other operators such as equal
, greater_than
.ranged_rank()
and .ranged_select()
. Add u128 support or arbitrary-length integer support
The fastest implementation on the planet
A Go package for myriad array operations using wavelet trees
excellent slides in Japanese
The original inventor's pdf: