From be80cefa69b314a3d9e1ab971715e84145863ebb Mon Sep 17 00:00:00 2001 From: green_machine Date: Mon, 5 Nov 2018 18:53:20 -0500 Subject: [PATCH] support c++17 --- src/cpp/flann/algorithms/kdtree_index.h | 5 ++++- src/cpp/flann/util/heap.h | 5 ++++- src/cpp/flann/util/lsh_table.h | 5 ++++- src/cpp/flann/util/random.h | 21 ++++++--------------- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/cpp/flann/algorithms/kdtree_index.h b/src/cpp/flann/algorithms/kdtree_index.h index 1f609fbb..8185df32 100644 --- a/src/cpp/flann/algorithms/kdtree_index.h +++ b/src/cpp/flann/algorithms/kdtree_index.h @@ -37,6 +37,7 @@ #include #include #include +#include #include "flann/general.h" #include "flann/algorithms/nn_index.h" @@ -265,7 +266,9 @@ class KDTreeIndex : public NNIndex /* Construct the randomized trees. */ for (int i = 0; i < trees_; i++) { /* Randomize the order of vectors to allow for unbiased sampling. */ - std::random_shuffle(ind.begin(), ind.end()); + std::random_device rd; + std::mt19937 g(rd()); + std::shuffle(ind.begin(), ind.end(), g); tree_roots_[i] = divideTree(&ind[0], int(size_) ); } delete[] mean_; diff --git a/src/cpp/flann/util/heap.h b/src/cpp/flann/util/heap.h index d54a99cb..4d758807 100644 --- a/src/cpp/flann/util/heap.h +++ b/src/cpp/flann/util/heap.h @@ -105,8 +105,11 @@ class Heap count = 0; } - struct CompareT : public std::binary_function + struct CompareT { + typedef T first_argument_type; + typedef T second_argument_type; + typedef bool result_type; bool operator()(const T& t_1, const T& t_2) const { return t_2 < t_1; diff --git a/src/cpp/flann/util/lsh_table.h b/src/cpp/flann/util/lsh_table.h index d6057235..58c644ec 100644 --- a/src/cpp/flann/util/lsh_table.h +++ b/src/cpp/flann/util/lsh_table.h @@ -39,6 +39,7 @@ #include #include #include +#include // TODO as soon as we use C++0x, use the code in USE_UNORDERED_MAP #if USE_UNORDERED_MAP #include @@ -363,7 +364,9 @@ inline LshTable::LshTable(unsigned int feature_size, unsigned int // A bit brutal but fast to code std::vector indices(feature_size * CHAR_BIT); for (size_t i = 0; i < feature_size * CHAR_BIT; ++i) indices[i] = i; - std::random_shuffle(indices.begin(), indices.end()); + std::random_device rd; + std::mt19937 g(rd()); + std::shuffle(indices.begin(), indices.end(),g); // Generate a random set of order of subsignature_size_ bits for (unsigned int i = 0; i < key_size_; ++i) { diff --git a/src/cpp/flann/util/random.h b/src/cpp/flann/util/random.h index b7b51b43..74269b7e 100644 --- a/src/cpp/flann/util/random.h +++ b/src/cpp/flann/util/random.h @@ -34,6 +34,7 @@ #include #include #include +#include #include #include "flann/general.h" @@ -50,9 +51,6 @@ inline void seed_random(unsigned int seed) srand(seed); } -/* - * Generates a random double value. - */ /** * Generates a random double value. * @param high Upper limit @@ -61,7 +59,7 @@ inline void seed_random(unsigned int seed) */ inline double rand_double(double high = 1.0, double low = 0) { - return low + ((high-low) * (std::rand() / (RAND_MAX + 1.0))); + return low + ((high - low) * (std::rand() / (RAND_MAX + 1.0))); } /** @@ -72,17 +70,10 @@ inline double rand_double(double high = 1.0, double low = 0) */ inline int rand_int(int high = RAND_MAX, int low = 0) { - return low + (int) ( double(high-low) * (std::rand() / (RAND_MAX + 1.0))); + return low + (int)(double(high - low) * (std::rand() / (RAND_MAX + 1.0))); } -class RandomGenerator -{ -public: - ptrdiff_t operator() (ptrdiff_t i) { return rand_int(i); } -}; - - /** * Random number generator that returns a distinct number from * the [0,n) interval each time. @@ -110,14 +101,14 @@ class UniqueRandom */ void init(int n) { - static RandomGenerator generator; // create and initialize an array of size n vals_.resize(n); size_ = n; for (int i = 0; i < size_; ++i) vals_[i] = i; - // shuffle the elements in the array - std::random_shuffle(vals_.begin(), vals_.end(), generator); + std::random_device rd; + std::mt19937 g(rd()); + std::shuffle(vals_.begin(), vals_.end(), g); counter_ = 0; }