Remove rand from dba
Reviewers: florijan, buda Reviewed By: florijan Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D721
This commit is contained in:
parent
30ff78bf93
commit
9a39a125b2
@ -9,9 +9,7 @@
|
||||
#include "utils/on_scope_exit.hpp"
|
||||
|
||||
GraphDbAccessor::GraphDbAccessor(GraphDb &db)
|
||||
: db_(db), transaction_(db.tx_engine_.Begin()) {
|
||||
pseudo_rand_gen_.seed(std::random_device()());
|
||||
}
|
||||
: db_(db), transaction_(db.tx_engine_.Begin()) {}
|
||||
|
||||
GraphDbAccessor::~GraphDbAccessor() {
|
||||
if (!commited_ && !aborted_) {
|
||||
@ -334,5 +332,3 @@ const std::string &GraphDbAccessor::PropertyName(
|
||||
debug_assert(!commited_ && !aborted_, "Accessor committed or aborted");
|
||||
return *property;
|
||||
}
|
||||
|
||||
double GraphDbAccessor::Rand() { return rand_dist_(pseudo_rand_gen_); }
|
||||
|
@ -553,11 +553,6 @@ class GraphDbAccessor {
|
||||
if (!accessor.new_) accessor.new_ = accessor.vlist_->update(*transaction_);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a uniformly random-generated number from the [0, 1) interval.
|
||||
*/
|
||||
double Rand();
|
||||
|
||||
private:
|
||||
/**
|
||||
* Insert this vertex into corresponding label and label+property (if it
|
||||
@ -598,8 +593,4 @@ class GraphDbAccessor {
|
||||
|
||||
bool commited_{false};
|
||||
bool aborted_{false};
|
||||
|
||||
// Random number generation stuff.
|
||||
std::mt19937 pseudo_rand_gen_;
|
||||
std::uniform_real_distribution<> rand_dist_{0, 1};
|
||||
};
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <functional>
|
||||
#include <random>
|
||||
|
||||
#include "query/exceptions.hpp"
|
||||
#include "utils/string.hpp"
|
||||
@ -453,11 +454,13 @@ TypedValue Pi(const std::vector<TypedValue> &args, GraphDbAccessor &) {
|
||||
return M_PI;
|
||||
}
|
||||
|
||||
TypedValue Rand(const std::vector<TypedValue> &args, GraphDbAccessor &dba) {
|
||||
TypedValue Rand(const std::vector<TypedValue> &args, GraphDbAccessor &) {
|
||||
static thread_local std::mt19937 pseudo_rand_gen_{std::random_device{}()};
|
||||
static thread_local std::uniform_real_distribution<> rand_dist_{0, 1};
|
||||
if (args.size() != 0U) {
|
||||
throw QueryRuntimeException("rand shouldn't be called with arguments");
|
||||
}
|
||||
return dba.Rand();
|
||||
return rand_dist_(pseudo_rand_gen_);
|
||||
}
|
||||
|
||||
template <bool (*Predicate)(const std::string &s1, const std::string &s2)>
|
||||
|
@ -352,19 +352,6 @@ TEST(GraphDbAccessorTest, Transfer) {
|
||||
EXPECT_EQ(dba3->Transfer(e12)->PropsAt(prop).Value<int64_t>(), 12);
|
||||
}
|
||||
|
||||
TEST(GraphDbAccessorTest, Rand) {
|
||||
Dbms dbms;
|
||||
auto dba = dbms.active();
|
||||
|
||||
double a = dba->Rand();
|
||||
EXPECT_GE(a, 0.0);
|
||||
EXPECT_LT(a, 1.0);
|
||||
double b = dba->Rand();
|
||||
EXPECT_GE(b, 0.0);
|
||||
EXPECT_LT(b, 1.0);
|
||||
EXPECT_NE(a, b);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
// ::testing::GTEST_FLAG(filter) = "*.DetachRemoveVertex";
|
||||
|
Loading…
Reference in New Issue
Block a user