Skip to content

Commit

Permalink
Fixed critical bug: KDTreeIntegers caught null Node
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoBackman committed Sep 27, 2021
1 parent 5e58c11 commit 1b11cb5
Show file tree
Hide file tree
Showing 9 changed files with 76,262 additions and 76,250 deletions.
1,200 changes: 600 additions & 600 deletions data/POINTS_100_600.dat

Large diffs are not rendered by default.

19,200 changes: 9,600 additions & 9,600 deletions data/POINTS_1600_9600.dat

Large diffs are not rendered by default.

2,398 changes: 1,199 additions & 1,199 deletions data/POINTS_200_1200.dat

Large diffs are not rendered by default.

38,400 changes: 19,200 additions & 19,200 deletions data/POINTS_3200_19200.dat

Large diffs are not rendered by default.

4,800 changes: 2,400 additions & 2,400 deletions data/POINTS_400_2400.dat

Large diffs are not rendered by default.

76,800 changes: 38,400 additions & 38,400 deletions data/POINTS_6400_38400.dat

Large diffs are not rendered by default.

9,600 changes: 4,800 additions & 4,800 deletions data/POINTS_800_4800.dat

Large diffs are not rendered by default.

98 changes: 49 additions & 49 deletions data/dataProfile.txt
Original file line number Diff line number Diff line change
@@ -1,119 +1,119 @@
---------------------------
Target point: [5, 5, 5]
Sequential:Closest node: [4, 6, 7] in distance 2.3268462696046543
Target point: [3152, 2152, 1234]
Sequential:Closest node: [39, 79, 99] in distance 1135.9131792123278

KDTree:Closest node: [4, 6, 7] in distance 2.3268462696046543
KDTree:Closest node: [39, 79, 99] in distance 1135.9131792123278

---------------------------
Number of points 100

Sequential
Construction time(ns): 134285
Search time(ns): 46749
Construction time(ns): 176200
Search time(ns): 67600

KDTree
Construction time(ns): 1262882
Search time(ns): 12702
Construction time(ns): 4106500
Search time(ns): 24000

---------------------------
Target point: [5, 5, 5]
Sequential:Closest node: [29, 9, 4] in distance 2.7063915681838724
Target point: [3152, 2152, 1234]
Sequential:Closest node: [55, 126, 199] in distance 1035.9786504411197

KDTree:Closest node: [29, 9, 4] in distance 2.7063915681838724
KDTree:Closest node: [55, 126, 199] in distance 1035.9786504411197

---------------------------
Number of points 200

Sequential
Construction time(ns): 239773
Search time(ns): 65059
Construction time(ns): 1732700
Search time(ns): 2450300

KDTree
Construction time(ns): 2545068
Search time(ns): 9104
Construction time(ns): 6919900
Search time(ns): 23200

---------------------------
Target point: [5, 5, 5]
Sequential:Closest node: [335, 15, 6] in distance 4.66223566042384
Target point: [3152, 2152, 1234]
Sequential:Closest node: [4, 302, 399] in distance 836.1075592381986

KDTree:Closest node: [335, 15, 6] in distance 4.66223566042384
KDTree:Closest node: [4, 302, 399] in distance 836.1075592381986

---------------------------
Number of points 400

Sequential
Construction time(ns): 480125
Search time(ns): 104761
Construction time(ns): 1249800
Search time(ns): 604000

KDTree
Construction time(ns): 6472364
Search time(ns): 12221
Construction time(ns): 14484700
Search time(ns): 23700

---------------------------
Target point: [5, 5, 5]
Sequential:Closest node: [71, 27, 7] in distance 5.239473141368047
Target point: [3152, 2152, 1234]
Sequential:Closest node: [771, 611, 799] in distance 436.7685569689484

KDTree:Closest node: [71, 27, 7] in distance 5.239473141368047
KDTree:Closest node: [771, 611, 799] in distance 436.7685569689484

---------------------------
Number of points 800

Sequential
Construction time(ns): 910560
Search time(ns): 281506
Construction time(ns): 2008100
Search time(ns): 396600

KDTree
Construction time(ns): 14214608
Search time(ns): 14830
Construction time(ns): 25256900
Search time(ns): 29000

---------------------------
Target point: [5, 5, 5]
Sequential:Closest node: [1063, 9, 1] in distance 6.983690945076813
Target point: [3152, 2152, 1234]
Sequential:Closest node: [250, 1566, 1234] in distance 24.258419154496888

KDTree:Closest node: [1063, 9, 1] in distance 6.983690945076813
KDTree:Closest node: [250, 1566, 1234] in distance 24.258419154496888

---------------------------
Number of points 1600

Sequential
Construction time(ns): 1723079
Search time(ns): 537726
Construction time(ns): 4101300
Search time(ns): 1874200

KDTree
Construction time(ns): 36119433
Search time(ns): 24221
Construction time(ns): 59152300
Search time(ns): 100400

---------------------------
Target point: [5, 5, 5]
Sequential:Closest node: [1572, 25, 4] in distance 6.734305734303527
Target point: [3152, 2152, 1234]
Sequential:Closest node: [1993, 2180, 1233] in distance 6.714124937850679

KDTree:Closest node: [1572, 25, 4] in distance 6.734305734303527
KDTree:Closest node: [1993, 2180, 1233] in distance 6.714124937850679

---------------------------
Number of points 3200

Sequential
Construction time(ns): 3381486
Search time(ns): 1063040
Construction time(ns): 25481700
Search time(ns): 2139200

KDTree
Construction time(ns): 72048579
Search time(ns): 11020
Construction time(ns): 135538700
Search time(ns): 26900

---------------------------
Target point: [5, 5, 5]
Sequential:Closest node: [6330, 74, 4] in distance 10.309707828339219
Target point: [3152, 2152, 1234]
Sequential:Closest node: [5719, 2155, 1231] in distance 7.730091213032229

KDTree:Closest node: [6330, 74, 4] in distance 10.309707828339219
KDTree:Closest node: [5719, 2155, 1231] in distance 7.730091213032229

---------------------------
Number of points 6400

Sequential
Construction time(ns): 6150585
Search time(ns): 2089660
Construction time(ns): 9546500
Search time(ns): 2434100

KDTree
Construction time(ns): 184920261
Search time(ns): 30805
Construction time(ns): 251467600
Search time(ns): 22600

16 changes: 14 additions & 2 deletions src/datastructure/KDTreeIntegers.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,17 @@ public void insert(int depth,
public DataCarrier find(ArrayList<Integer> points) {
//start from the root
IntegerTreeNode traverse = root;
while (traverse.leftChild != null || traverse.rightChild != null) {
while (traverse.hasChild()) {
//compare value by axis
int axis = traverse.getAxis();
Integer valueToCompare = traverse.points.get(axis);
if (points.get(axis) < valueToCompare) {
traverse = traverse.leftChild;
if (traverse.leftChild == null)
break;
traverse = traverse.leftChild;
} else {
if (traverse.rightChild == null)
break;
traverse = traverse.rightChild;
}
}
Expand All @@ -142,6 +146,7 @@ private double calculateDistance(ArrayList<Integer> given,
}

public class IntegerTreeNode {
IntegerTreeNode parent;
ArrayList<Integer> points;
IntegerTreeNode leftChild;
IntegerTreeNode rightChild;
Expand All @@ -164,6 +169,13 @@ public int getDepth() {
return this.depth;
}

public boolean hasChild() {
if (leftChild == null && rightChild == null) {
return false;
}
return true;
}

public void setAxis(int axisIndex) {
this.axisIndex = axisIndex;
}
Expand Down

0 comments on commit 1b11cb5

Please sign in to comment.