-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
k-d tree (A k-dimensional tree) #805
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #805 +/- ##
==========================================
- Coverage 95.32% 95.14% -0.18%
==========================================
Files 310 311 +1
Lines 22488 22771 +283
==========================================
+ Hits 21437 21666 +229
- Misses 1051 1105 +54 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bomenderick: thanks for interesting contribution.
Before this will be merged some work needs to be done. First of all: please add missing tests. Especially the functionality finding the closest point has to be exercised quite brutally.
Could you also describe/document in the code, which operations does your implementation support?
src/data_structures/kd_tree.rs
Outdated
|
||
impl<T: PartialOrd + Copy, const K: usize> KDTree<T, K> { | ||
// Create and empty kd-tree | ||
// #[must_use] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// #[must_use] |
// Returns true if point found, false otherwise | ||
pub fn contains(&self, point: &[T; K]) -> bool { | ||
search_rec(&self.root, point, 0) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Contains
is useful to search for the presence of a point in a k-d tree.
Or do you mean the additional call of search_rec
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does contains
need to be public?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes for interaction with the outside world. However, contains
is just to complete CRUD
operations on a k-d tree.
Indeed, the current k-d tree implementation doesn't make use of contains
. However, its implementation could help as it is just a synonym of the search
method of a k-d tree.
Would you recommend I make it private for now or remove it?
src/data_structures/kd_tree.rs
Outdated
search_rec(&self.root, point, 0) | ||
} | ||
|
||
// Returns true if successfully delete a point, false otherwise |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete?
src/data_structures/kd_tree.rs
Outdated
} | ||
|
||
// Returns the number of points in a kd-tree | ||
// #[must_use] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// #[must_use] |
src/data_structures/kd_tree.rs
Outdated
} | ||
|
||
// Returns the depth a kd-tree | ||
// #[must_use] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// #[must_use] |
src/data_structures/kd_tree.rs
Outdated
pub fn depth(&self) -> usize { | ||
depth_rec(&self.root, 0, 0) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed?
src/data_structures/kd_tree.rs
Outdated
} | ||
|
||
// Determine whether there exist points in a kd-tree or not | ||
// #[must_use] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// #[must_use] |
src/data_structures/kd_tree.rs
Outdated
} | ||
|
||
// Returns a kd-tree built from a vector points | ||
// #[must_use] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// #[must_use] |
src/data_structures/kd_tree.rs
Outdated
|
||
/// Returns a `KDTree` containing both trees | ||
/// Merging two KDTrees by collecting points and rebuilding | ||
// #[must_use] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// #[must_use] |
src/data_structures/kd_tree.rs
Outdated
pub fn merge(&mut self, other: &mut Self) -> Self { | ||
let mut points: Vec<[T; K]> = Vec::new(); | ||
collect_points(&self.root, &mut points); | ||
collect_points(&other.root, &mut points); | ||
KDTree::build(points) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really needed?
This pull request has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Description
A K-D Tree(also known as a K-Dimensional Tree) is a binary search tree where data in each node is a K-Dimensional point in space. In short, it is a space partitioning data structure for organizing points in a K-Dimensional space in other to facilitate nearest neighbor search of points.
In addition to insert, search, and delete methods, the implementation also supports nearest neighbors search, median finding for insertion in other to keep the k-d tree balanced, and a merge method to combine two k-d trees by collecting their points and building a balanced k-d tree from it.
Read more: