-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkdtree_test.cpp
More file actions
60 lines (50 loc) · 1.74 KB
/
Copy pathkdtree_test.cpp
File metadata and controls
60 lines (50 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <limits>
#include <memory>
#include <atomic>
#include <kdtree_define.h>
#include <print_tree.hpp>
#include <lock_free_stack.h>
// #include <experimental/atomic>
int main() {
std::vector<Point> point_v {{30,40}, {5,25}, {10,12}, {70,70}, {50,30}, {35,45}};
TreeNode* root = nullptr;
for (auto& p : point_v) {
insert(p, root, 0);
}
if (!root) {
std::cout << "tree is empty" << std::endl;
}
printtree(root);
std::cout << "min x point node is " << FindMin(root, 0, 0)->point_ << std::endl;
std::cout << "min y point node is " << FindMin(root, 1, 0)->point_ << std::endl;
// delete_node_safely(Point(70,70), root, 0);
// printtree(root);
auto BoundingBox = UpdateBounding(root, 0);
PrintBox(root->current_bound);
// PrintBox(root->left_node_->current_bound);
// PrintBox(root->right_node_->current_bound);
Point* nearest_point = GetNearestPoint(Point(9, 9), root);
if (nearest_point) {
std::cout << " nearest distance to point 71,71 node is " << *nearest_point << std::endl;
}
// test node delete, especially root node
for (auto& p : point_v) {
delete_node_safely(p, root, 0);
printtree(root);
}
// must be final to release memory
if (root) {
delete root;
}
auto test = std::make_shared<DeriveTest>();
std::atomic<Point*> node_ptr;
// std::shared_ptr<Point> node_ptr = std::make_shared<Point>(30,40);
bool is_ptr_lock_free = std::atomic_is_lock_free(&node_ptr);
// bool is_ptr_lock_free = std::atomic<std::shared_ptr<Point>>()::is_lock_free();
std::cout << " is ptr lock free " << is_ptr_lock_free << "\n";
return 0;
}