Related Work

Comparison of spatial indexing libraries and techniques for 2D range management.


JavaScript/TypeScript Libraries

RBush

URL: https://github.com/mourner/rbush

Algorithm: R-tree with OMT (Overlap Minimizing Top-down) split

Trade-offs:

Use Case: General-purpose 2D spatial queries (GIS, maps, collision detection)

vs This Project: RBush is for finding overlapping objects. We're for managing overlapping ranges with last-writer-wins conflict resolution and automatic fragmentation. Different problem domain.


FlatBush

URL: https://github.com/mourner/flatbush

Algorithm: Static packed Hilbert R-tree

Trade-offs:

Use Case: Immutable spatial datasets (tile indices, static maps)

vs This Project: FlatBush is read-only. Spreadsheet ranges are dynamic (user edits constantly). Not applicable.


kd-Bush

URL: https://github.com/mourner/kdbush

Algorithm: k-d tree for 2D points

Trade-offs:

Use Case: Point clouds, marker clustering

vs This Project: k-d trees are for points. We need rectangles. Wrong data structure.


Other Spatial Indexing Techniques

Quadtree

Algorithm: Recursive 2D grid subdivision

Trade-offs:

vs This Project: Tested in early research (not in archive). R-tree was faster and more space-efficient for realistic spreadsheet patterns.


Grid/Hashmap

Algorithm: Divide space into fixed-size cells, hash ranges to cells

Trade-offs:

vs This Project: Grid approach works if you know the query pattern (e.g., always 10×10 viewport). Spreadsheets have arbitrary range sizes (1 cell to entire sheet). R-tree adapts dynamically.


S2 Geometry

URL: https://s2geometry.io/

Algorithm: Hilbert curve mapping on sphere surface

Trade-offs:

vs This Project: S2's Hilbert curve insight inspired our HilbertLinearScan implementation. But S2's spherical math is unnecessary for flat 2D grids.


Academic Algorithms (Not Implemented)

R+ tree

Innovation: Non-overlapping nodes (objects clipped at boundaries)

Trade-offs:

Why not: R* tree already achieves good query performance. R+ tree's complexity not worth marginal gains.


Priority R-tree

Innovation: Prioritize important objects for faster access

Trade-offs:

Why not: Spreadsheet ranges don't have predictable "importance" - all ranges equal priority.


Key Differentiators of This Project

1. Last-Writer-Wins Semantics

Most spatial libraries assume independent objects (e.g., buildings on a map don't overwrite each other).

Spreadsheet ranges conflict - applying background color to A1:B2 then A2:C3 means A2:B2 gets the second color. This requires:

No existing library handles this - they'd need LWW logic built on top.


2. Context-Dependent Optimization

Research finding: Best algorithm depends on n (data size).

Libraries like RBush optimize for one use case. We provide both, with guidance on when to switch.


3. Google Sheets Integration

All implementations use Google Sheets GridRange type via custom adapter (src/adapters/gridrange.ts). Minimal conversion overhead (half-open ⟷ closed interval transformation).

Other libraries would need adapter layer to translate to/from their coordinate systems.


When to Use Existing Libraries

Use RBush if:

Use FlatBush if:

Use this project if:


References


See Also: