Algorithms Reference
A flat catalog of every algorithm shipping in vizcrush, with the package and Rust crate that implements it. Use this page to find the right tool for a job, or as a jumping-off point into the per-package docs.
Downsampling
Reduce a paired (x, y) series to a smaller, visually-equivalent set.
| Algorithm | Function | Package | Best for |
|---|---|---|---|
| LTTB (Largest-Triangle-Three-Buckets) | lttb() | @vizcrush/downsample | Smooth time series, sensor metrics |
| MinMax-LTTB | minMaxLttb() | @vizcrush/downsample | Spiky data — financial, IoT bursts |
| M4 (Min-Max-Min-Max) | m4() | @vizcrush/downsample | Per-pixel rendering, max fidelity |
| LTOB (Largest-Triangle-One-Bucket) | ltob() | @vizcrush/downsample | Faster simpler variant of LTTB |
All four return interleaved [x0, y0, x1, y1, …] Float64Arrays. Reference paper: Steinarsson, "Downsampling Time Series for Visual Representation" (2013).
Aggregation & statistics
| Algorithm | Function / Class | Package | Notes |
|---|---|---|---|
| Welford's online stats | stats(), StreamingStats | @vizcrush/aggregate | One-pass, numerically stable |
| Exact percentiles | percentile() | @vizcrush/aggregate | Sort + linear interpolation |
| t-digest (approximate percentiles) | vizcrush-aggregate::tdigest | (Rust crate) | Approximate, sub-linear memory |
| Append-and-downsample | appendAndDownsample() | @vizcrush/aggregate | Streaming append + LTTB in one pass |
Transforms
| Algorithm | Function | Package | Cost |
|---|---|---|---|
| Radix sort | sortBy() | @vizcrush/transform | O(n) for fixed-width floats |
| Min-max normalize | normalize() | @vizcrush/transform | O(n) two-pass |
| Range filter | filterRange() | @vizcrush/transform | O(n) single pass |
Binning & density
| Algorithm | Function | Package | Output |
|---|---|---|---|
| 1D histogram | bin1d() | @vizcrush/bin | Uint32Array counts + Float64Array edges |
| 2D density grid | bin2d() | @vizcrush/bin | Row-major Uint32Array of size xBins*yBins |
| Hexagonal binning | hexbin() | @vizcrush/bin | Sparse list of {cx, cy, count} cells |
| 3D voxel binning | bin3d() | @vizcrush/bin3d | Flat Uint32Array of size xBins*yBins*zBins |
Spatial indexing
| Index | Build / Query functions | Package | Dimensions |
|---|---|---|---|
| Quadtree | buildQuadtree, queryRange, queryNearest | @vizcrush/spatial | 2D |
| Octree | buildOctree, queryRange3d, queryNearest3d | @vizcrush/spatial3d | 3D |
| k-d tree | (in vizcrush-spatial::kdtree, future export) | (Rust crate) | 2D / N-D |
| Frustum culling | frustumCull() | @vizcrush/spatial3d | 3D, MVP-based |
Both quadtree and octree use the same configuration: MAX_POINTS = 64 per leaf, MAX_DEPTH = 12.
AI & analysis
| Algorithm | Function | Package | Implementation |
|---|---|---|---|
| Anomaly detection (MAD + Z-score) | detectAnomalies() | @vizcrush/ai | Robust to outliers, classifies spike/dip/shift |
| Changepoint detection (CUSUM) | detectChangepoints() | @vizcrush/ai | Sustained mean shifts |
| Auto-optimization | autoOptimize() | @vizcrush/ai | Heuristic algorithm + parameter selection |
| Data summarization | summarize(), summarizeForLLM() | @vizcrush/ai | Trend, distribution, anomalies |
| Shape embeddings | computeShapeVector() | @vizcrush/ai | 16-dim feature vector |
| Shape similarity | shapeSimilarity() | @vizcrush/ai | Cosine similarity in [0, 1] |
| NL query parsing | parseDataQuery() | @vizcrush/ai | Rule-based, no LLM round-trip |
Backend selection
| Function | Package | Purpose |
|---|---|---|
init() | @vizcrush/core | Initialize, auto-select best backend |
detectCapabilities() | @vizcrush/core | Probe runtime features |
selectBackend(caps) | @vizcrush/core | Apply selection rules |
The selection is: WASM → JS — WASM whenever WebAssembly is available, the pure-JS core otherwise. See Backends & Capabilities for details.
Performance reference
Run the suite in benchmarks/ for numbers on your hardware; results land in benchmarks/results/. Reference points from the latest Node run (pure-JS core, V8 — benchmarks/results/latest.json):
| Operation | Input size | Time |
|---|---|---|
lttb | 1M → 1000 | 1.8 ms |
filterRange | 1M | 5.3 ms |
stats | 1M | 3.9 ms |
In Chromium, the WASM backend runs lttb 1M → 1000 in ~1.5 ms — WASM is roughly 4× faster than the JS core in Chromium/V8, but the JS core is comparable or faster in Firefox and WebKit, and the first WASM call pays a one-time module-load cost. See ADR 0003 (docs/adr/0003-wasm-vs-js-is-engine-dependent.md). No WebGPU compute path is wired for any of these algorithms.
See also
- Packages overview — at-a-glance package summary
- Examples gallery — runnable demos for each algorithm