Skip to content

Commit

Permalink
support c++17
Browse files Browse the repository at this point in the history
  • Loading branch information
greenbrettmichael committed Nov 5, 2018
1 parent f3a17cd commit be80cef
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
5 changes: 4 additions & 1 deletion src/cpp/flann/algorithms/kdtree_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <cstring>
#include <stdarg.h>
#include <cmath>
#include <random>

#include "flann/general.h"
#include "flann/algorithms/nn_index.h"
Expand Down Expand Up @@ -265,7 +266,9 @@ class KDTreeIndex : public NNIndex<Distance>
/* 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_;
Expand Down
5 changes: 4 additions & 1 deletion src/cpp/flann/util/heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,11 @@ class Heap
count = 0;
}

struct CompareT : public std::binary_function<T,T,bool>
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;
Expand Down
5 changes: 4 additions & 1 deletion src/cpp/flann/util/lsh_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <random>
// TODO as soon as we use C++0x, use the code in USE_UNORDERED_MAP
#if USE_UNORDERED_MAP
#include <unordered_map>
Expand Down Expand Up @@ -363,7 +364,9 @@ inline LshTable<unsigned char>::LshTable(unsigned int feature_size, unsigned int
// A bit brutal but fast to code
std::vector<size_t> 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) {
Expand Down
21 changes: 6 additions & 15 deletions src/cpp/flann/util/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <algorithm>
#include <cstdlib>
#include <cstddef>
#include <random>
#include <vector>

#include "flann/general.h"
Expand All @@ -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
Expand All @@ -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)));
}

/**
Expand All @@ -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.
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit be80cef

Please sign in to comment.