1 #ifndef COMMONTOOLS_RECOALGOS_FKDTREE_H
2 #define COMMONTOOLS_RECOALGOS_FKDTREE_H
21 const std::array<unsigned int, 32> MultiplyDeBruijnBitPosition{{0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16,
22 18, 22, 25, 3, 30, 8, 12, 20, 28, 15, 17,
23 24, 7, 19, 27, 23, 6, 26, 5, 4, 31}};
24 unsigned int ilog2(
unsigned int v) {
30 return MultiplyDeBruijnBitPosition[(
unsigned int)(
v * 0x07C4ACDDU) >> 27];
34 template <
class TYPE,
unsigned int numberOfDimensions>
52 std::vector<unsigned int>& foundPoints) {
64 unsigned int numberOfindicesToVisitThisDepth;
65 unsigned int numberOfSonsToVisitNext;
66 unsigned int firstSonToVisitNext;
72 numberOfindicesToVisitThisDepth = indicesToVisit.
size();
74 for (
unsigned int visitedindicesThisDepth = 0; visitedindicesThisDepth < numberOfindicesToVisitThisDepth;
75 visitedindicesThisDepth++) {
76 index = indicesToVisit[visitedindicesThisDepth];
87 numberOfSonsToVisitNext =
93 numberOfSonsToVisitNext =
98 for (
unsigned int whichSon = 0; whichSon < numberOfSonsToVisitNext; ++whichSon) {
99 indicesToVisit.
push_back(firstSonToVisitNext + whichSon);
103 indicesToVisit.
pop_front(numberOfindicesToVisitThisDepth);
115 for (
unsigned int i = 0;
i < numberOfDimensions; ++
i)
130 unsigned int firstIndexInDepth = (1 <<
depth) - 1;
132 for (
unsigned int indexInDepth = 0; indexInDepth <
maxDepth; ++indexInDepth) {
133 unsigned int indexInArray = firstIndexInDepth + indexInDepth;
134 unsigned int leftSonIndexInArray = 2 * indexInArray + 1;
135 unsigned int rightSonIndexInArray = leftSonIndexInArray + 1;
148 return a.getId() <
b.getId();
168 unsigned int firstIndexInDepth = (1 <<
theDepth) - 1;
169 for (
unsigned int indexInArray = firstIndexInDepth; indexInArray <
theNumberOfPoints; ++indexInArray) {
195 return length -
index / 2;
216 for (
unsigned int i = 0;
i < numberOfDimensions; ++
i) {
225 for (
unsigned int i = 0;
i < numberOfDimensions; ++
i)
231 for (
unsigned int i = 0;
i < numberOfDimensions; ++
i)