by Sebastian Häni
bessere Performance
Binary Space Partitioning
Orthogonale Bereichsuche
Windowing
class BspTreeNode {
Plane partition;
List<Polygon> polygons = new ArrayList<>();
BspTreeNode front;
BspTreeNode back;
}
void buildBspTree(BspTreeNode node, List<Polygon> polygons) {
...
polygons.forEach(polygon -> {
switch(classify(polygon, node.partition)) {
case COINCIDENT: node.polygons.add(polygon); break;
case IN_BACK_OF: backlist.add(polygon); break;
case IN_FRONT_OF: frontlist.add(polygon); break;
case SPANNING: split = split(polygon, tree.partition);
backlist.add(split.getLeft());
frontlist.add(split.getRight());
}
});
...
}
Balance ←→ Schnitte
switch(classify(v, node.partition) {
case IN_BACK_OF:
renderPolygons(node.front.polygons);
renderPolygons(node.polygons);
renderPolygons(node.back.polygons); break;
case IN_FRONT_OF:
renderPolygons(node.getBack.polygons);
renderPolygons(node.polygons);
renderPolygons(node.getFront.polygons); break;
case COINCIDENT:
renderPolygons(node.front.polygons);
renderPolygons(node.back.polygons); break;
}
Einfügen und Neuberechnung haben die selbe Zeitkomplexität von O(n3)
Binary Space Partitioning
Orthogonale Bereichsuche
Windowing
Employee | |||
---|---|---|---|
Name | Birthday | Salary | Kids |
SELECT * FROM Employee WHERE
Salary > 3000 AND
Salary < 4000
SELECT * FROM Employee WHERE
Salary > 3000 AND
Salary < 4000 AND
Birthday > '01-01-1950' AND
Birthday < '01-01-1960'
SELECT * FROM Employee WHERE
Salary > 3000 AND
Salary < 4000 AND
Birthday > '01-01-1950' AND
Birthday < '01-01-1960' AND
Kids >= 2 AND
Kids <= 4
class Node {
Split split;
Point point;
Node above;
Node below;
}
class Split {
boolean even;
float coordinate;
}
Node buildKdTree(List<Point> points, int depth) {
if(points.size() == 0)
return null;
if(points.size() == 1)
return new Node(points.get(0));
boolean even = depth % 2 == 0;
{split, pointsAbove, pointsBelow} = split(points, even);
Node nodeAbove = buildKdTree(pointsAbove, depth + 1);
Node nodeBelow = buildKdTree(pointsBelow, depth + 1);
return new Node(split, nodeAbove, noveBelow);
}
Binary Space Partitioning
Orthogonale Bereichsuche
Windowing
class Interval { int start; int end; }
class Node {
int value;
SortedIntervals mid;
Node left;
Node right;
}
class SortedIntervals {
SortedSet<Interval> startpoints;
SortedSet<Interval> endpoints;
}
Node buildIntervalTree(Set<Interval> intervals) {
Node node = new Node();
int endMedian = calcEndpointMedian(intervals);
{left, mid, right} = classify(intervals, endMedian);
node.value = endMedian;
node.mid = mid;
node.left = buildIntervalTree(left);
node.right = buildIntervalTree(right);
return node;
}
Binary Space Partitioning
Painters Algorithm, BSP TreeOrthogonale Bereichsuche
Datenbank Bereichsuche, Kd TreeWindowing
Interval Tree, R-TreeSource code & documentation https://github.com/sebastianhaeni/space-partitioning