English | 简体中文
NBSlim
Rust implementation of SIA, SIATEC, COSIATEC, and RecurSIA – algorithms for compressing 2D point sets by discovering translational equivalence classes (TECs). Designed for compressing Note Block Studio (.nbs) music files, but works on any set of points in the plane.
This crate is the core algorithm implementation extracted from the NBSlim Python package, released independently for Rust projects.
Algorithms
- SIA – finds all maximal translatable patterns from a point set.
- SIATEC – builds translational equivalence classes from SIA results.
- COSIATEC – greedy lossless compression: repeatedly extract the best TEC (highest compression ratio) and remove its covered points.
- RecurSIA – recursive version of COSIATEC that compresses patterns of each TEC, capturing nested repetitions.
All algorithms are implemented with O(n²) time complexity and use online HashMap aggregation to avoid storing all point pairs, making them memory efficient for large inputs.
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Usage
Basic compression with COSIATEC
use ;
let points = vec!;
let tecs = cosiatec_compress; // restrict_dpitch_zero = true
for tec in &tecs
Recursive compression (RecurSIA)
use recursive_cosiatec_compress;
let tecs = recursive_cosiatec_compress;
Working with TECs
use HashSet;
// Coverage set (all points that belong to any occurrence of this TEC)
let coverage: = tec.coverage;
// Compression ratio (coverage size / encoding units)
let ratio = tec.compression_ratio;
// Compactness relative to the full dataset
let dataset_points: = points.iter.copied.collect;
let compactness = tec.compactness;
Reconstructing original points from a list of TECs
use rebuild;
let original_points = rebuild;
assert_eq!;
Merge small TECs
use merge_tecs;
// Merge all TECs with coverage size <= 10 into a single TEC
let merged = merge_tecs;
Compression statistics
use compression_stats;
let = compression_stats;
println!;
References
- Meredith, D., Lemström, K., & Wiggins, G. A. (2002). Algorithms for discovering repeated patterns in multidimensional representations of polyphonic music.
- Meredith, D. (2013). COSIATEC and SIATECCompress: Pattern discovery by geometric compression.
- Meredith, D. (2019). RecurSIA-RRT: Recursive translatable point-set pattern discovery with removal of redundant translators. arXiv:1906.12286.