All Projects → mrhooray → kdtree-rs

mrhooray / kdtree-rs

Licence: Apache-2.0, MIT licenses found Licenses found Apache-2.0 LICENSE-APACHE MIT LICENSE-MIT
K-dimensional tree in Rust for fast geospatial indexing and lookup

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to kdtree-rs

Tinspin Indexes
Spatial index library with R*Tree, STR-Tree, Quadtree, CritBit, KD-Tree, CoverTree
Stars: ✭ 64 (-53.28%)
Mutual labels:  tree, index
Pibench
Benchmarking framework for index structures on persistent memory
Stars: ✭ 46 (-66.42%)
Mutual labels:  tree, index
kdtree
A k-d tree implementation in Go.
Stars: ✭ 98 (-28.47%)
Mutual labels:  tree, nearest-neighbor-search
kvstore
KVStore is a simple Key-Value Store based on B+Tree (disk & memory) for Java
Stars: ✭ 88 (-35.77%)
Mutual labels:  tree, index
markdown-explorer
Easily explore, view and edit markdown documentation of a file tree
Stars: ✭ 58 (-57.66%)
Mutual labels:  tree
php-sorted-collections
Sorted Collections for PHP
Stars: ✭ 22 (-83.94%)
Mutual labels:  tree
luke
Please use the luke bundled with lucene! This repo is archived and frozen now.
Stars: ✭ 101 (-26.28%)
Mutual labels:  index
TreeRep
Learning Tree structures and Tree metrics
Stars: ✭ 18 (-86.86%)
Mutual labels:  tree
gradle-dependencies-viewer
A simple web UI to analyze dependencies for your project based on the text data generated from "gradle dependencies" command.
Stars: ✭ 70 (-48.91%)
Mutual labels:  tree
qverse
Traverse any data with DPML commands.
Stars: ✭ 25 (-81.75%)
Mutual labels:  tree
radixdb
Static Radix Tree (Patricia trie) implementation in C
Stars: ✭ 34 (-75.18%)
Mutual labels:  tree
matching-engine
Superfast Matching Engine written in golang
Stars: ✭ 35 (-74.45%)
Mutual labels:  tree
index shotgun
duplicate index checker 🔥 🔫 👮
Stars: ✭ 35 (-74.45%)
Mutual labels:  index
treetime
TreeTime is a data organisation, management and analysis tool. A tree is a hierarchical structure that arranges information in units and sub-units. TreeTime uses linked trees (one data item can be part of different distinct trees) to store and organise any general purpose data.
Stars: ✭ 26 (-81.02%)
Mutual labels:  tree
dslib
🌿 A library of "connected" data structures
Stars: ✭ 122 (-10.95%)
Mutual labels:  tree
wisdomtree
Study helper for zhihuishu.com
Stars: ✭ 33 (-75.91%)
Mutual labels:  tree
react-binary-tree
Binary Tree Traversal Visualisation
Stars: ✭ 25 (-81.75%)
Mutual labels:  tree
prune
A tree library for Java 8 with functional sensibilities.
Stars: ✭ 22 (-83.94%)
Mutual labels:  tree
lshensemble
LSH index for approximate set containment search
Stars: ✭ 48 (-64.96%)
Mutual labels:  nearest-neighbor-search
stefano-tree
Framework agnostic Nested Set (MPTT) implementation for PHP
Stars: ✭ 24 (-82.48%)
Mutual labels:  tree

kdtree Build Status

K-dimensional tree in Rust for fast geospatial indexing and nearest neighbors lookup

Usage

Add kdtree to Cargo.toml

[dependencies]
kdtree = "0.5.1"

Add points to kdtree and query nearest n points with distance function

use kdtree::KdTree;
use kdtree::ErrorKind;
use kdtree::distance::squared_euclidean;

let a: ([f64; 2], usize) = ([0f64, 0f64], 0);
let b: ([f64; 2], usize) = ([1f64, 1f64], 1);
let c: ([f64; 2], usize) = ([2f64, 2f64], 2);
let d: ([f64; 2], usize) = ([3f64, 3f64], 3);

let dimensions = 2;
let mut kdtree = KdTree::new(dimensions);

kdtree.add(&a.0, a.1).unwrap();
kdtree.add(&b.0, b.1).unwrap();
kdtree.add(&c.0, c.1).unwrap();
kdtree.add(&d.0, d.1).unwrap();

assert_eq!(kdtree.size(), 4);
assert_eq!(
    kdtree.nearest(&a.0, 0, &squared_euclidean).unwrap(),
    vec![]
);
assert_eq!(
    kdtree.nearest(&a.0, 1, &squared_euclidean).unwrap(),
    vec![(0f64, &0)]
);
assert_eq!(
    kdtree.nearest(&a.0, 2, &squared_euclidean).unwrap(),
    vec![(0f64, &0), (2f64, &1)]
);
assert_eq!(
    kdtree.nearest(&a.0, 3, &squared_euclidean).unwrap(),
    vec![(0f64, &0), (2f64, &1), (8f64, &2)]
);
assert_eq!(
    kdtree.nearest(&a.0, 4, &squared_euclidean).unwrap(),
    vec![(0f64, &0), (2f64, &1), (8f64, &2), (18f64, &3)]
);
assert_eq!(
    kdtree.nearest(&a.0, 5, &squared_euclidean).unwrap(),
    vec![(0f64, &0), (2f64, &1), (8f64, &2), (18f64, &3)]
);
assert_eq!(
    kdtree.nearest(&b.0, 4, &squared_euclidean).unwrap(),
    vec![(0f64, &1), (2f64, &0), (2f64, &2), (8f64, &3)]
);

Benchmark

cargo bench with 2.3 GHz Intel i5-7360U:

cargo bench
     Running target/release/deps/bench-9e622e6a4ed9b92a

running 2 tests
test bench_add_to_kdtree_with_1k_3d_points       ... bench:         106 ns/iter (+/- 25)
test bench_nearest_from_kdtree_with_1k_3d_points ... bench:       1,237 ns/iter (+/- 266)

test result: ok. 0 passed; 0 failed; 0 ignored; 2 measured; 0 filtered out

Thanks Eh2406 for various fixes and perf improvements.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].