Commit a00ca7fe authored by Tiago Peixoto's avatar Tiago Peixoto

Make alias Sampler default-constructible

parent 4296b96e
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "random.hh" #include "random.hh"
#include <functional> #include <functional>
#include <boost/mpl/if.hpp>
namespace graph_tool namespace graph_tool
{ {
...@@ -31,7 +32,7 @@ using namespace boost; ...@@ -31,7 +32,7 @@ using namespace boost;
// See http://www.keithschwarz.com/darts-dice-coins/ for a very clear // See http://www.keithschwarz.com/darts-dice-coins/ for a very clear
// explanation, // explanation,
template <class Value> template <class Value, class KeepReference = mpl::true_>
class Sampler class Sampler
{ {
public: public:
...@@ -76,6 +77,8 @@ public: ...@@ -76,6 +77,8 @@ public:
_small.clear(); _small.clear();
} }
Sampler() {}
template <class RNG> template <class RNG>
const Value& sample(RNG& rng) const Value& sample(RNG& rng)
{ {
...@@ -103,7 +106,10 @@ private: ...@@ -103,7 +106,10 @@ private:
} }
}; };
const vector<Value>& _items; typedef typename mpl::if_<KeepReference,
const vector<Value>&,
vector<Value> >::type items_t;
items_t _items;
vector<double> _probs; vector<double> _probs;
vector<size_t> _alias; vector<size_t> _alias;
vector<size_t> _small; vector<size_t> _small;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment