Overview
A Spatial Hash divides space into uniform cells and hashes cell coordinates, making nearby-object queries simple and fast for evenly sized objects.
Maps spatial positions into grid cells stored in a hash table.
Compact metadata for implementation and discovery.
A Spatial Hash divides space into uniform cells and hashes cell coordinates, making nearby-object queries simple and fast for evenly sized objects.
Quick facts
Runtime and memory behavior at a glance.
Best
O(1)
Average
O(1) average insert and local query
Worst
O(n)
Space
O(n)
cell = floor(position / cell_size)Maps a continuous position to integer grid coordinates.
Show points assigned to grid cells with each occupied cell stored in a hash table.
Cell size should match the typical interaction radius.
What each reference supports for this entry.
Data-structures reference for hash-based spatial indexing, grid-cell lookup, and neighborhood-query tradeoffs.
Specific reference for hash-based spatial subdivision, grid-cell hashing, and collision-detection neighborhood lookup.
Open sourceGood next jumps from the relationship graph, ranked for useful discovery.
Data Structures · Core
Balanced k-d trees support ordered spatial pruning, while spatial hashes bucket nearby coordinates.
Compare with thisSpatial hashing and k-d trees are alternative spatial indexing strategies for nearby-object lookup.