memgraph/poc/kdtree/kdnode.hpp

47 lines
933 B
C++
Raw Normal View History

#pragma once
2015-06-19 16:04:42 +08:00
#include <memory>
#include "point.hpp"
namespace kd {
template <class T, class U>
class KdNode {
public:
KdNode(const U& data)
: axis(0),
coord(Point<T>(0, 0)),
left(nullptr),
right(nullptr),
data(data) {}
2015-06-19 16:04:42 +08:00
KdNode(const Point<T>& coord, const U& data)
: axis(0), coord(coord), left(nullptr), right(nullptr), data(data) {}
2015-06-19 16:04:42 +08:00
KdNode(unsigned char axis, const Point<T>& coord, const U& data)
: axis(axis), coord(coord), left(nullptr), right(nullptr), data(data) {}
2015-06-19 16:04:42 +08:00
KdNode(unsigned char axis, const Point<T>& coord, KdNode<T, U>* left,
KdNode<T, U>* right, const U& data)
: axis(axis), coord(coord), left(left), right(right), data(data) {}
2015-06-19 16:04:42 +08:00
~KdNode();
2015-06-19 16:04:42 +08:00
unsigned char axis;
2015-06-19 16:04:42 +08:00
Point<T> coord;
2015-06-19 16:04:42 +08:00
KdNode<T, U>* left;
KdNode<T, U>* right;
2015-06-19 16:04:42 +08:00
U data;
2015-06-19 16:04:42 +08:00
};
template <class T, class U>
KdNode<T, U>::~KdNode() {
delete left;
delete right;
2015-06-19 16:04:42 +08:00
}
}