Skip to content

Commit

Permalink
Also use Dimension for divfeat
Browse files Browse the repository at this point in the history
  • Loading branch information
David Wright committed Aug 13, 2021
1 parent 1bac65c commit bef2b48
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions include/nanoflann.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ class PooledAllocator {

void internal_init() {
remaining = 0;
base = NULL;
base = nullptr;
usedMemory = 0;
wastedMemory = 0;
}
Expand All @@ -664,7 +664,7 @@ class PooledAllocator {

/** Frees all allocated memory chunks */
void free_all() {
while (base != NULL) {
while (base != nullptr) {
void *prev =
*(static_cast<void **>(base)); /* Get pointer to prev block. */
::free(base);
Expand Down Expand Up @@ -782,8 +782,13 @@ class KDTreeBaseClass {
typedef typename Distance::ElementType ElementType;
typedef typename Distance::DistanceType DistanceType;

using Offset = uint32_t;
using Size = uint32_t;
/**
* Array of indices to vectors in the dataset.
*/
std::vector<AccessorType> vAcc;

using Offset = typename decltype(vAcc)::size_type;
using Size = typename decltype(vAcc)::size_type;
using Dimension = int32_t;

/*--------------------- Internal Data Structures --------------------------*/
Expand All @@ -795,8 +800,8 @@ class KDTreeBaseClass {
Offset left, right; //!< Indices of points in leaf node
} lr;
struct nonleaf {
int divfeat; //!< Dimension used for subdivision.
DistanceType divlow, divhigh; //!< The values used for subdivision.
Dimension divfeat; //!< Dimension used for subdivision.
DistanceType divlow, divhigh; //!< The values used for subdivision.
} sub;
} node_type;
Node *child1, *child2; //!< Child nodes (both=NULL mean its a leaf node)
Expand All @@ -808,11 +813,6 @@ class KDTreeBaseClass {
ElementType low, high;
};

/**
* Array of indices to vectors in the dataset.
*/
std::vector<AccessorType> vAcc;

NodePtr root_node;

Size m_leaf_max_size;
Expand Down Expand Up @@ -915,7 +915,7 @@ class KDTreeBaseClass {
}
} else {
Offset idx;
int cutfeat;
Dimension cutfeat;
DistanceType cutval;
middleSplit_(obj, left, right - left, idx, cutfeat, cutval, bbox);

Expand All @@ -942,9 +942,9 @@ class KDTreeBaseClass {
}

void middleSplit_(Derived &obj, Offset ind, Size count, Offset &index,
int &cutfeat, DistanceType &cutval,
Dimension &cutfeat, DistanceType &cutval,
const BoundingBox &bbox) {
const DistanceType EPS = static_cast<DistanceType>(0.00001);
const auto EPS = static_cast<DistanceType>(0.00001);
ElementType max_span = bbox[0].high - bbox[0].low;
for (Dimension i = 1; i < (DIM > 0 ? DIM : obj.dim); ++i) {
ElementType span = bbox[i].high - bbox[i].low;
Expand Down Expand Up @@ -998,7 +998,7 @@ class KDTreeBaseClass {
* dataset[ind[lim1..lim2-1]][cutfeat]==cutval
* dataset[ind[lim2..count]][cutfeat]>cutval
*/
void planeSplit(Derived &obj, Offset ind, const Size count, int cutfeat,
void planeSplit(Derived &obj, Offset ind, const Size count, Dimension cutfeat,
DistanceType &cutval, Offset &lim1, Offset &lim2) {
/* Move vector indices for left subtree to front of list. */
Offset left = 0;
Expand Down Expand Up @@ -1406,7 +1406,7 @@ class KDTreeSingleIndexAdaptor
}

/* Which child branch should be taken first? */
int idx = node->node_type.sub.divfeat;
Dimension idx = node->node_type.sub.divfeat;
ElementType val = vec[idx];
DistanceType diff1 = val - node->node_type.sub.divlow;
DistanceType diff2 = val - node->node_type.sub.divhigh;
Expand Down Expand Up @@ -1764,7 +1764,7 @@ class KDTreeSingleIndexDynamicAdaptor_
}

/* Which child branch should be taken first? */
int idx = node->node_type.sub.divfeat;
Dimension idx = node->node_type.sub.divfeat;
ElementType val = vec[idx];
DistanceType diff1 = val - node->node_type.sub.divlow;
DistanceType diff2 = val - node->node_type.sub.divhigh;
Expand Down

0 comments on commit bef2b48

Please sign in to comment.