lsph/lib.rs
1//! This crate implements the Learned SPatial HashMap(LSPH), a high performance spatial index uses HashMap with learned model.
2//!
3//! The original paper of LSPH can be found [here].
4//!
5//! [here]: https://minerva-access.unimelb.edu.au/items/beb5c0ee-2a8d-5bd2-b349-1190a335ef1a
6//!
7//! The LSPH uses a learned model such as a linear regression model as the hash
8//! function to predict the index in a hashmap. As a result, the learned model
9//! is more fitted to the data that stored in the hashmap, and reduces the
10//! chance of hashing collisions. Moreover, if the learned model is monotonic
11//! function(e.g. linear regression), the hash indexes are increasing as the
12//! input data increases. This property can be used to create a sorted order
13//! of buckets in a hashmap, which allow us to do range searches in a hashmap.
14//!
15//! The LSPH supports:
16//! - Point Query
17//! - Rectange Query
18//! - Radius Range Query
19//! - Nearest Neighbor Query
20//!
21//! Example:
22//! ```
23//! use lsph::{LearnedHashMap, LinearModel};
24//! let point_data = vec![[1., 1.], [2., 1.], [3., 2.], [4., 4.]];
25//! let (mut map, points) = LearnedHashMap::<LinearModel<f64>, f64>::with_data(&point_data).unwrap();
26//!
27//! assert_eq!(map.get(&[1., 1.]).is_some(), true);
28//! assert_eq!(map.get(&[3., 1.]).is_none(), true);
29//! assert_eq!(map.range_search(&[0., 0.], &[3., 3.]).is_some(), true);
30//! assert_eq!(map.radius_range(&[2., 1.], 1.).is_some(), true);
31//! assert_eq!(map.nearest_neighbor(&[2., 1.]).is_some(), true);
32//!
33//! ```
34//! # License
35//!
36//! Licensed under either of
37//!
38//! - Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or <http://www.apache.org/licenses/LICENSE-2.0>)
39//! - MIT license ([LICENSE-MIT](LICENSE-MIT) or <http://opensource.org/licenses/MIT>)
40//!
41//! at your option.
42
43#[macro_use]
44mod macros;
45mod error;
46pub mod geometry;
47pub mod hasher;
48pub mod map;
49pub mod models;
50#[cfg(test)]
51pub mod test_utilities;
52
53pub use geometry::*;
54pub use hasher::*;
55pub use map::*;
56pub use models::*;