Crates.io | lsph |
lib.rs | lsph |
version | 0.1.9 |
created_at | 2022-04-18 07:20:40.160353+00 |
updated_at | 2025-09-14 13:42:03.577106+00 |
description | Learned Spatial HashMap |
homepage | https://github.com/jackson211/lsph |
repository | https://github.com/jackson211/lsph |
max_upload_size | |
id | 569737 |
size | 88,191 |
fast 2d point query powered by hashmap and statistic model
The original paper of LSPH can be found here.
The LSPH uses a learned model such as a linear regression model as the hash function to predict the index in a hashmap. As a result, the learned model is more fitted to the data that stored in the hashmap, and reduces the chance of hashing collisions. Moreover, if the learned model is monotonic function(e.g. linear regression), the hash indexes are increasing as the input data increases. This property can be used to create a sorted order of buckets in a hashmap, which allow us to do range searches in a hashmap.
The LSPH supports:
use lsph::{LearnedHashMap, LinearModel};
let point_data = vec![[1., 1.], [2., 1.], [3., 2.], [4., 4.]];
let (mut map, points) = LearnedHashMap::<LinearModel<f32>, f64>::with_data(&point_data).unwrap();
assert_eq!(map.get(&[1., 1.]).is_some(), true);
assert_eq!(map.get(&[3., 1.]).is_none(), true);
assert_eq!(map.range_search(&[0., 0.], &[3., 3.]).is_some(), true);
assert_eq!(map.radius_range(&[2., 1.], 1.).is_some(), true);
assert_eq!(map.nearest_neighbor(&[2., 1.]).is_some(), true);
LSPH includes two comprehensive demo applications to showcase its capabilities:
A command-line demo using real Melbourne geographic data (6,361 points):
cd examples/demo
cargo run --release
Features:
A graphical demonstration with visual spatial operations:
cd examples/interactive_demo
cargo run --release
Interactive demo showing nearest neighbor search with responsive UI and visual feedback
Features:
cargo bench
Licensed under either of
at your option.