1
0
Fork 0

Merge branch 'devel' of https://github.com/triAGENS/ArangoDB into mjmh

This commit is contained in:
Jan Steemann 2014-05-31 02:57:16 +02:00
commit e106f2a38d
21 changed files with 224 additions and 528 deletions

View File

@ -1,160 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
/// @brief test suite for mersenne.c
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2012 triagens GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is triAGENS GmbH, Cologne, Germany
///
/// @author Jan Steemann
/// @author Copyright 2012, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
#include "BasicsC/mersenne.h"
#include <boost/test/unit_test.hpp>
// -----------------------------------------------------------------------------
// --SECTION-- setup / tear-down
// -----------------------------------------------------------------------------
struct CMersenneSetup {
CMersenneSetup () {
BOOST_TEST_MESSAGE("setup mersenne");
TRI_InitialiseMersenneTwister();
}
~CMersenneSetup () {
BOOST_TEST_MESSAGE("tear-down mersenne");
}
};
// -----------------------------------------------------------------------------
// --SECTION-- test suite
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief setup
////////////////////////////////////////////////////////////////////////////////
BOOST_FIXTURE_TEST_SUITE(CMersenneTest, CMersenneSetup)
////////////////////////////////////////////////////////////////////////////////
/// @brief test mersenne int32
////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE (tst_mersenne_int32) {
for (size_t i = 0; i < 100; ++i) {
int64_t value = (int64_t) TRI_Int32MersenneTwister();
BOOST_CHECK_EQUAL(true, value >= 0);
BOOST_CHECK_EQUAL(true, value <= UINT32_MAX);
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief test mersenne int31
////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE (tst_mersenne_int31) {
for (size_t i = 0; i < 100; ++i) {
int64_t value = (int64_t) TRI_Int31MersenneTwister();
BOOST_CHECK_EQUAL(true, value >= 0);
BOOST_CHECK_EQUAL(true, value <= INT32_MAX);
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief test after explicit seed
////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE (tst_mersenne_seed) {
TRI_SeedMersenneTwister((uint32_t) 0UL);
BOOST_CHECK_EQUAL((uint32_t) 2357136044UL, TRI_Int32MersenneTwister());
BOOST_CHECK_EQUAL((uint32_t) 2546248239UL, TRI_Int32MersenneTwister());
BOOST_CHECK_EQUAL((uint32_t) 3071714933UL, TRI_Int32MersenneTwister());
TRI_SeedMersenneTwister((uint32_t) 1UL);
BOOST_CHECK_EQUAL((uint32_t) 1791095845UL, TRI_Int32MersenneTwister());
BOOST_CHECK_EQUAL((uint32_t) 4282876139UL, TRI_Int32MersenneTwister());
BOOST_CHECK_EQUAL((uint32_t) 3093770124UL, TRI_Int32MersenneTwister());
TRI_SeedMersenneTwister((uint32_t) 2UL);
BOOST_CHECK_EQUAL((uint32_t) 1872583848UL, TRI_Int32MersenneTwister());
BOOST_CHECK_EQUAL((uint32_t) 794921487UL, TRI_Int32MersenneTwister());
BOOST_CHECK_EQUAL((uint32_t) 111352301UL, TRI_Int32MersenneTwister());
TRI_SeedMersenneTwister((uint32_t) 23UL);
BOOST_CHECK_EQUAL((uint32_t) 2221777491UL, TRI_Int32MersenneTwister());
BOOST_CHECK_EQUAL((uint32_t) 2873750246UL, TRI_Int32MersenneTwister());
BOOST_CHECK_EQUAL((uint32_t) 4067173416UL, TRI_Int32MersenneTwister());
TRI_SeedMersenneTwister((uint32_t) 42UL);
BOOST_CHECK_EQUAL((uint32_t) 1608637542UL, TRI_Int32MersenneTwister());
BOOST_CHECK_EQUAL((uint32_t) 3421126067UL, TRI_Int32MersenneTwister());
BOOST_CHECK_EQUAL((uint32_t) 4083286876UL, TRI_Int32MersenneTwister());
TRI_SeedMersenneTwister((uint32_t) 458735UL);
BOOST_CHECK_EQUAL((uint32_t) 1537542272UL, TRI_Int32MersenneTwister());
BOOST_CHECK_EQUAL((uint32_t) 4131475792UL, TRI_Int32MersenneTwister());
BOOST_CHECK_EQUAL((uint32_t) 2280116031UL, TRI_Int32MersenneTwister());
TRI_SeedMersenneTwister((uint32_t) 395568682893UL);
BOOST_CHECK_EQUAL((uint32_t) 2297195664UL, TRI_Int32MersenneTwister());
BOOST_CHECK_EQUAL((uint32_t) 2381406737UL, TRI_Int32MersenneTwister());
BOOST_CHECK_EQUAL((uint32_t) 4184846092UL, TRI_Int32MersenneTwister());
}
////////////////////////////////////////////////////////////////////////////////
/// @brief test after explicit seed, repeated calls
////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE (tst_mersenne_reseed) {
TRI_SeedMersenneTwister((uint32_t) 23UL);
BOOST_CHECK_EQUAL((uint32_t) 2221777491UL, TRI_Int32MersenneTwister());
BOOST_CHECK_EQUAL((uint32_t) 2873750246UL, TRI_Int32MersenneTwister());
BOOST_CHECK_EQUAL((uint32_t) 4067173416UL, TRI_Int32MersenneTwister());
// re-seed with same value and compare
TRI_SeedMersenneTwister((uint32_t) 23UL);
BOOST_CHECK_EQUAL((uint32_t) 2221777491UL, TRI_Int32MersenneTwister());
BOOST_CHECK_EQUAL((uint32_t) 2873750246UL, TRI_Int32MersenneTwister());
BOOST_CHECK_EQUAL((uint32_t) 4067173416UL, TRI_Int32MersenneTwister());
// seed with different value
TRI_SeedMersenneTwister((uint32_t) 458735UL);
BOOST_CHECK_EQUAL((uint32_t) 1537542272UL, TRI_Int32MersenneTwister());
// re-seed with original value and compare
TRI_SeedMersenneTwister((uint32_t) 23UL);
BOOST_CHECK_EQUAL((uint32_t) 2221777491UL, TRI_Int32MersenneTwister());
BOOST_CHECK_EQUAL((uint32_t) 2873750246UL, TRI_Int32MersenneTwister());
BOOST_CHECK_EQUAL((uint32_t) 4067173416UL, TRI_Int32MersenneTwister());
}
////////////////////////////////////////////////////////////////////////////////
/// @brief generate tests
////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_SUITE_END ()
// Local Variables:
// mode: outline-minor
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"
// End:

View File

@ -247,7 +247,6 @@ UnitTests_basics_suite_SOURCES = \
UnitTests/Basics/json-test.cpp \
UnitTests/Basics/json-utilities-test.cpp \
UnitTests/Basics/hashes-test.cpp \
UnitTests/Basics/mersenne-test.cpp \
UnitTests/Basics/associative-pointer-test.cpp \
UnitTests/Basics/associative-multi-pointer-test.cpp \
UnitTests/Basics/associative-synced-test.cpp \
@ -855,6 +854,7 @@ unittests-arangob:
@builddir@/bin/arangob --configuration none --quiet --server.username "$(USERNAME)" --server.password "$(PASSWORD)" --server.endpoint unix://$(VOCDIR)/arango.sock --requests 500 --concurrency 3 --test aqltrx --complexity 1 || test "x$(FORCE)" == "x1"
@builddir@/bin/arangob --configuration none --quiet --server.username "$(USERNAME)" --server.password "$(PASSWORD)" --server.endpoint unix://$(VOCDIR)/arango.sock --requests 100 --concurrency 3 --test counttrx || test "x$(FORCE)" == "x1"
@builddir@/bin/arangob --configuration none --quiet --server.username "$(USERNAME)" --server.password "$(PASSWORD)" --server.endpoint unix://$(VOCDIR)/arango.sock --requests 500 --concurrency 3 --test multitrx || test "x$(FORCE)" == "x1"
@builddir@/bin/arangob --configuration none --quiet --server.username "$(USERNAME)" --server.password "$(PASSWORD)" --server.endpoint unix://$(VOCDIR)/arango.sock --requests 500 --concurrency 3 --test import-document --complexity 500 || test "x$(FORCE)" == "x1"
kill `cat $(PIDFILE)`

View File

@ -116,7 +116,10 @@ bool V8PeriodicTask::handlePeriod () {
"(function (params) { " + _command + " } )(params);",
_parameters);
_dispatcher->addJob(job);
if (! _dispatcher->addJob(job)) {
// just in case the dispatcher cannot accept the job (e.g. when shutting down)
delete job;
}
return true;
}

View File

@ -146,7 +146,7 @@ static int TruncateDatafile (TRI_datafile_t* const datafile, const off_t length)
static int CreateSparseFile (char const* filename,
const TRI_voc_size_t maximalSize) {
off_t offset;
TRI_lseek_t offset;
char zero;
ssize_t res;
int fd;
@ -162,9 +162,9 @@ static int CreateSparseFile (char const* filename,
}
// create sparse file
offset = TRI_LSEEK(fd, maximalSize - 1, SEEK_SET);
offset = TRI_LSEEK(fd, (TRI_lseek_t) (maximalSize - 1), SEEK_SET);
if (offset == (off_t) -1) {
if (offset == (TRI_lseek_t) -1) {
TRI_set_errno(TRI_ERROR_SYS_ERROR);
TRI_CLOSE(fd);
@ -192,7 +192,6 @@ static int CreateSparseFile (char const* filename,
return fd;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief initialises a datafile
////////////////////////////////////////////////////////////////////////////////
@ -266,7 +265,6 @@ static int TruncateAndSealDatafile (TRI_datafile_t* datafile,
int fd;
int res;
size_t maximalSize;
off_t offset;
void* data;
void* mmHandle;
@ -295,9 +293,9 @@ static int TruncateAndSealDatafile (TRI_datafile_t* datafile,
}
// create sparse file
offset = TRI_LSEEK(fd, (TRI_lseek_t) maximalSize - 1, SEEK_SET);
TRI_lseek_t offset = TRI_LSEEK(fd, (TRI_lseek_t) (maximalSize - 1), SEEK_SET);
if (offset == (off_t) -1) {
if (offset == (TRI_lseek_t) -1) {
TRI_set_errno(TRI_ERROR_SYS_ERROR);
TRI_CLOSE(fd);

View File

@ -187,7 +187,7 @@
var k = getStarter();
var shutdownInfo = k.shutdown();
if (shutdownInfo.error) {
require("console").log(JSON.stringify(shutdownInfo.results));
require("console").log("%s", JSON.stringify(shutdownInfo.results));
}
});
@ -196,7 +196,7 @@
var shutdownInfo = k.shutdown();
cleanUp();
if (shutdownInfo.error) {
require("console").log(JSON.stringify(shutdownInfo.results));
require("console").log("%s", JSON.stringify(shutdownInfo.results));
return;
}
});

View File

@ -551,7 +551,7 @@
},
prepareD3Charts: function (update) {
var v, self = this, f;
var self = this;
var barCharts = {
totalTimeDistribution: [
@ -560,11 +560,6 @@
"bytesSentDistributionPercent", "bytesReceivedDistributionPercent"]
};
var dists = {
totalTimeDistribution: "Time Distribution",
dataTransferDistribution: "Size Distribution"
};
if (this.d3NotInitialised) {
update = false;
this.d3NotInitialised = false;
@ -575,7 +570,6 @@
+ 'Container .dashboard-interior-chart');
var selector = "#" + k + "Container svg";
var dist = dists[k];
nv.addGraph(function () {
var tickMarks = [0, 0.25, 0.5, 0.75, 1];

View File

@ -15,7 +15,6 @@
readJSON: function() {
var fileInput = document.getElementById('fileInput');
var fileDisplayArea = document.getElementById('fileDisplayArea');
var file = fileInput.files[0];
var textType = 'application/json';

View File

@ -31,7 +31,6 @@
var internal = require("internal");
var cluster = require("org/arangodb/cluster");
var actions = require("org/arangodb/actions");
var console = require("console");
var FoxxController = require("org/arangodb/foxx").Controller;
var controller = new FoxxController(applicationContext);

View File

@ -133,7 +133,186 @@
expect(window.modalView.show).toHaveBeenCalled();
});
it("should stop an events propagination", function() {
var e = {
stopPropagation: function(){}
};
spyOn(e, "stopPropagation");
tile1.noop(e);
expect(e.stopPropagation).toHaveBeenCalled();
});
it("should load a collection", function() {
spyOn(tile1.model, "loadCollection");
spyOn(tile1, "render");
spyOn(window.modalView, "hide");
tile1.loadCollection();
expect(tile1.model.loadCollection).toHaveBeenCalled();
expect(tile1.render).toHaveBeenCalled();
expect(window.modalView.hide).toHaveBeenCalled();
});
it("should unload a collection", function() {
spyOn(tile1.model, "unloadCollection");
spyOn(tile1, "render");
spyOn(window.modalView, "hide");
tile1.unloadCollection();
expect(tile1.model.unloadCollection).toHaveBeenCalled();
expect(tile1.render).toHaveBeenCalled();
expect(window.modalView.hide).toHaveBeenCalled();
});
it("should delete a collection with success", function() {
spyOn(tile1.model, "destroy");
spyOn(tile1.collectionsView, "render");
spyOn(window.modalView, "hide");
tile1.deleteCollection();
expect(tile1.model.destroy).toHaveBeenCalled();
expect(tile1.collectionsView.render).toHaveBeenCalled();
expect(window.modalView.hide).toHaveBeenCalled();
});
it("should save a modified collection (unloaded collection, save error)", function() {
window.App = {
notificationList: {
add: function() {
}
}
};
spyOn(arangoHelper, "arangoError");
spyOn(tile1.model, "renameCollection");
tile1.saveModifiedCollection();
expect(tile1.model.renameCollection).toHaveBeenCalled();
expect(arangoHelper.arangoError).toHaveBeenCalled();
});
it("should save a modified collection (loaded collection, save error)", function() {
tile1.model.set('status', "loaded");
window.App = {
notificationList: {
add: function() {
}
}
};
spyOn(arangoHelper, "arangoError");
spyOn(tile1.model, "renameCollection");
tile1.saveModifiedCollection();
expect(tile1.model.renameCollection).toHaveBeenCalled();
expect(arangoHelper.arangoError).toHaveBeenCalled();
});
});
it("should save a modified collection (unloaded collection, success)", function() {
window.App = {
notificationList: {
add: function() {
}
}
};
spyOn(tile1.model, "renameCollection").andReturn(true);
spyOn(tile1.collectionsView, "render");
spyOn(window.modalView, "hide");
tile1.saveModifiedCollection();
expect(window.modalView.hide).toHaveBeenCalled();
expect(tile1.collectionsView.render).toHaveBeenCalled();
expect(tile1.model.renameCollection).toHaveBeenCalled();
});
it("should save a modified collection (loaded collection, success)", function() {
tile1.model.set('status', "loaded");
window.App = {
notificationList: {
add: function() {
}
}
};
var tempdiv = document.createElement("div");
tempdiv.id = "change-collection-size";
document.body.appendChild(tempdiv);
$('#change-collection-size').val(123123123123);
spyOn(tile1.model, "changeCollection").andReturn(true);
spyOn(tile1.model, "renameCollection").andReturn(true);
spyOn(tile1.collectionsView, "render");
spyOn(window.modalView, "hide");
tile1.saveModifiedCollection();
expect(window.modalView.hide).toHaveBeenCalled();
expect(tile1.collectionsView.render).toHaveBeenCalled();
expect(tile1.model.renameCollection).toHaveBeenCalled();
document.body.removeChild(tempdiv);
});
it("should not save a modified collection (invalid data, result)", function() {
tile1.model.set('status', "loaded");
window.App = {
notificationList: {
add: function() {
}
}
};
var tempdiv = document.createElement("div");
tempdiv.id = "change-collection-size";
document.body.appendChild(tempdiv);
$('#change-collection-size').val(123123123123);
spyOn(arangoHelper, "arangoError");
spyOn(arangoHelper, "arangoNotification");
spyOn(tile1.model, "changeCollection").andReturn(false);
spyOn(tile1.model, "renameCollection").andReturn(false);
spyOn(tile1.collectionsView, "render");
spyOn(window.modalView, "hide");
tile1.saveModifiedCollection();
expect(window.modalView.hide).not.toHaveBeenCalled();
expect(tile1.collectionsView.render).not.toHaveBeenCalled();
expect(tile1.model.renameCollection).toHaveBeenCalled();
expect(arangoHelper.arangoError).toHaveBeenCalled();
document.body.removeChild(tempdiv);
});
it("should not save a modified collection (invalid data, result)", function() {
tile1.model.set('status', "loaded");
window.App = {
notificationList: {
add: function() {
}
}
};
var tempdiv = document.createElement("div");
tempdiv.id = "change-collection-size";
document.body.appendChild(tempdiv);
$('#change-collection-size').val(123123123123);
spyOn(arangoHelper, "arangoError");
spyOn(arangoHelper, "arangoNotification");
spyOn(tile1.model, "changeCollection").andReturn(false);
spyOn(tile1.model, "renameCollection").andReturn(true);
spyOn(tile1.collectionsView, "render");
spyOn(window.modalView, "hide");
tile1.saveModifiedCollection();
expect(window.modalView.hide).not.toHaveBeenCalled();
expect(tile1.collectionsView.render).not.toHaveBeenCalled();
expect(tile1.model.renameCollection).toHaveBeenCalled();
expect(arangoHelper.arangoNotification).toHaveBeenCalled();
document.body.removeChild(tempdiv);
});
});
}());

View File

@ -874,7 +874,6 @@ var Graph = function(graphName, edgeDefinitions, vertexCollections, edgeCollecti
};
// remove
var old_remove = wrap.remove;
wrap.remove = function(edgeId, options) {
//if _key make _id (only on 1st call)
if (edgeId.indexOf("/") === -1) {
@ -1215,10 +1214,7 @@ Graph.prototype._getVertexCollectionByName = function(name) {
////////////////////////////////////////////////////////////////////////////////
Graph.prototype._neighbors = function(vertexExample, options) {
var current_vertex,
target_array = [],
addNeighborToList,
AQLStmt;
var AQLStmt;
if (! options) {
options = { };

View File

@ -87,8 +87,6 @@ function createStatisticsCollection (name) {
/// TODO need to fix this
////////////////////////////////////////////////////////////////////////////////
var StatisticsNames = [ "_statisticsRaw", "_statistics", "_statistics15" ];
function createStatisticsCollections () {
'use strict';

View File

@ -4900,15 +4900,16 @@ function GENERAL_GRAPH_NEIGHBORS (graphName,
options.direction = 'any';
}
var neighbors = [],match,
params = TRAVERSAL_PARAMS(), factory = TRAVERSAL.generalGraphDatasourceFactory(graphName);
var neighbors = [],
params = TRAVERSAL_PARAMS(),
factory = TRAVERSAL.generalGraphDatasourceFactory(graphName);
params.minDepth = options.minDepth === undefined ? 1 : options.minDepth;
params.maxDepth = options.maxDepth === undefined ? 1 : options.maxDepth;
params.paths = true;
options.edgeExamples = options.edgeExamples || [];
params.visitor = TRAVERSAL_NEIGHBOR_VISITOR;
var graph = RESOLVE_GRAPH_TO_DOCUMENTS(graphName, options);
params.followEdges = MERGE_EXAMPLES_WITH_EDGES(options.edgeExamples, graph.edges);

View File

@ -39,9 +39,6 @@ var assertQueryError = helper.assertQueryError;
////////////////////////////////////////////////////////////////////////////////
function ahuacatlQueryGeneralEdgesTestSuite() {
var vertex = null;
var edge = null;
return {
////////////////////////////////////////////////////////////////////////////////
@ -262,9 +259,6 @@ function ahuacatlQueryGeneralEdgesTestSuite() {
function ahuacatlQueryGeneralCommonTestSuite() {
var vertex = null;
var edge = null;
return {
////////////////////////////////////////////////////////////////////////////////
@ -450,9 +444,6 @@ function ahuacatlQueryGeneralCommonTestSuite() {
////////////////////////////////////////////////////////////////////////////////
function ahuacatlQueryGeneralPathsTestSuite() {
var vertex = null;
var edge = null;
return {
////////////////////////////////////////////////////////////////////////////////
@ -620,9 +611,6 @@ function ahuacatlQueryGeneralPathsTestSuite() {
////////////////////////////////////////////////////////////////////////////////
function ahuacatlQueryGeneralTraversalTestSuite() {
var vertex = null;
var edge = null;
return {
////////////////////////////////////////////////////////////////////////////////

View File

@ -47,7 +47,7 @@ namespace triagens {
// use the rng so the linker does not remove it from the executable
// we might need it later because .so files might refer to the symbols
Random::random_e v = Random::selectVersion(Random::RAND_MERSENNE);
Random::UniformInteger random(0, 1);
Random::UniformInteger random(0, INT32_MAX);
random.random();
Random::selectVersion(v);

View File

@ -28,7 +28,6 @@
#include "RandomGenerator.h"
#include "BasicsC/mersenne.h"
#include "BasicsC/logging.h"
#include "BasicsC/socket-utils.h"
#include "Basics/Exceptions.h"
@ -36,6 +35,9 @@
#include "Basics/MutexLocker.h"
#include "Basics/Thread.h"
#include <random>
#include <chrono>
using namespace std;
using namespace triagens::basics;
@ -92,8 +94,8 @@ namespace RandomHelper {
template<int N>
class RandomDeviceDirect : public RandomDevice {
public:
RandomDeviceDirect (string path)
: fd(1), pos(0) {
RandomDeviceDirect (std::string const& path)
: fd(-1), pos(0) {
fd = TRI_OPEN(path.c_str(), O_RDONLY);
if (fd < 0) {
@ -106,7 +108,9 @@ namespace RandomHelper {
~RandomDeviceDirect () {
TRI_CLOSE(fd);
if (fd >= 0) {
TRI_CLOSE(fd);
}
}
@ -121,6 +125,7 @@ namespace RandomHelper {
private:
void fillBuffer () {
size_t n = sizeof(buffer);
char* ptr = reinterpret_cast<char*>(&buffer);
while (0 < n) {
@ -151,7 +156,8 @@ namespace RandomHelper {
template<int N>
class RandomDeviceCombined : public RandomDevice {
public:
RandomDeviceCombined (string path) : fd(0), pos(0), rseed(0) {
RandomDeviceCombined (std::string const& path)
: fd(-1), pos(0), rseed(0) {
fd = TRI_OPEN(path.c_str(), O_RDONLY);
@ -183,7 +189,9 @@ namespace RandomHelper {
~RandomDeviceCombined () {
TRI_CLOSE(fd);
if (fd >= 0) {
TRI_CLOSE(fd);
}
}
@ -224,11 +232,12 @@ namespace RandomHelper {
}
if (0 < n) {
std::mt19937 engine;
unsigned long seed = RandomDevice::getSeed();
TRI_SeedMersenneTwister((uint32_t) (rseed ^ (uint32_t) seed));
engine.seed((uint32_t) (rseed ^ (uint32_t) seed));
while (0 < n) {
*ptr++ = TRI_Int32MersenneTwister();
*ptr++ = engine();
--n;
}
}
@ -431,16 +440,21 @@ namespace triagens {
// MERSENNE
struct UniformIntegerMersenne : public UniformIntegerImpl {
UniformIntegerMersenne ()
: engine(std::chrono::system_clock::now().time_since_epoch().count()) {
}
int32_t random (int32_t left, int32_t right) {
const int64_t range = (int64_t) right - (int64_t) left + 1LL;
int32_t result = (int32_t) TRI_Int32MersenneTwister();
assert(range > 0);
uint32_t result = engine();
result = (int32_t) (abs((int64_t) result % range) + (int64_t) left);
return result;
}
std::mt19937 engine;
};

View File

@ -30,13 +30,11 @@
#include "BasicsC/files.h"
#include "BasicsC/hashes.h"
#include "BasicsC/logging.h"
#include "BasicsC/mersenne.h"
#include "BasicsC/process-utils.h"
#include "BasicsC/random.h"
#include "BasicsC/socket-utils.h"
#include "ShapedJson/json-shaper.h"
// -----------------------------------------------------------------------------
// --SECTION-- public functions
// -----------------------------------------------------------------------------
@ -53,7 +51,6 @@
void TRI_InitialiseC (int argc, char* argv[]) {
TRI_InitialiseMemory();
TRI_InitialiseDebugging();
TRI_InitialiseMersenneTwister();
TRI_InitialiseError();
TRI_InitialiseFiles();
TRI_InitialiseMimetypes();

View File

@ -438,6 +438,8 @@ static int GenerateMessage (char* buffer,
// .............................................................................
n = 0;
// TODO: can this lock be removed? the prefix is only set at the server startup once
TRI_LockSpin(&OutputPrefixLock);
@ -445,7 +447,6 @@ static int GenerateMessage (char* buffer,
n = snprintf(buffer, size, "%s ", OutputPrefix);
}
TRI_UnlockSpin(&OutputPrefixLock);
if (n < 0) {

View File

@ -1,217 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
/// @brief mersenne twister implementation
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2004-2013 triAGENS GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is triAGENS GmbH, Cologne, Germany
///
/// @author Jan Steemann
/// @author see copyright notice of original authors below
/// @author Copyright 2012-2013, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
#include "mersenne.h"
#include "BasicsC/threads.h"
// -----------------------------------------------------------------------------
// --SECTION-- MERSENNE TWISTER
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// --SECTION-- static functions
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Random
/// @{
////////////////////////////////////////////////////////////////////////////////
/*
A C-program for MT19937, with initialization improved 2002/1/26.
Coded by Takuji Nishimura and Makoto Matsumoto.
Before using, initialize the state by using init_genrand(seed)
or init_by_array(init_key, key_length).
Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The names of its contributors may not be used to endorse or promote
products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Any feedback is very welcome.
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
*/
/* Period parameters */
#define N 624
#define M 397
#define MATRIX_A 0x9908b0dfUL /* constant vector a */
#define UPPER_MASK 0x80000000UL /* most significant w-r bits */
#define LOWER_MASK 0x7fffffffUL /* least significant r bits */
static unsigned long mt[N]; /* the array for the state vector */
static int mti = N+1; /* mti==N+1 means mt[N] is not initialized */
/* initializes mt[N] with a seed */
static void init_genrand (unsigned long s) {
mt[0]= s & 0xffffffffUL;
for (mti=1; mti<N; mti++) {
mt[mti] =
(1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
/* In the previous versions, MSBs of the seed affect */
/* only MSBs of the array mt[]. */
/* 2002/01/09 modified by Makoto Matsumoto */
mt[mti] &= 0xffffffffUL;
/* for >32 bit machines */
}
}
/* generates a random number on [0,0xffffffff]-interval */
static unsigned long genrand_int32 (void) {
unsigned long y;
static unsigned long mag01[2]={0x0UL, MATRIX_A};
/* mag01[x] = x * MATRIX_A for x=0,1 */
if (mti >= N) { /* generate N words at one time */
int kk;
if (mti == N+1) /* if init_genrand() has not been called, */
init_genrand(5489UL); /* a default initial seed is used */
for (kk=0;kk<N-M;kk++) {
y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1UL];
}
for (;kk<N-1;kk++) {
y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1UL];
}
y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK);
mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL];
mti = 0;
}
y = mt[mti++];
/* Tempering */
y ^= (y >> 11);
y ^= (y << 7) & 0x9d2c5680UL;
y ^= (y << 15) & 0xefc60000UL;
y ^= (y >> 18);
return y;
}
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- public functions
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Random
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief initialise the mersenne twister
/// this function needs to be called just once on startup
////////////////////////////////////////////////////////////////////////////////
void TRI_InitialiseMersenneTwister () {
unsigned long seed = (unsigned long) time(0);
#ifdef TRI_HAVE_GETTIMEOFDAY
struct timeval tv;
int result = gettimeofday(&tv, 0);
seed ^= (unsigned long) tv.tv_sec;
seed ^= (unsigned long) tv.tv_usec;
seed ^= (unsigned long) result;
#endif
seed ^= (unsigned long) TRI_CurrentProcessId();
init_genrand((unsigned long) seed);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief explicitly seed the mersenne twister
////////////////////////////////////////////////////////////////////////////////
void TRI_SeedMersenneTwister (uint32_t seed) {
init_genrand((unsigned long) seed);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief generate a 31 bit random number
////////////////////////////////////////////////////////////////////////////////
uint32_t TRI_Int31MersenneTwister () {
return (uint32_t) (genrand_int32() >> 1);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief generate a 32 bit random number
////////////////////////////////////////////////////////////////////////////////
uint32_t TRI_Int32MersenneTwister () {
return (uint32_t) genrand_int32();
}
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// Local Variables:
// mode: outline-minor
// outline-regexp: "/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|/// @page\\|// --SECTION--\\|/// @\\}"
// End:

View File

@ -1,92 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
/// @brief mersenne twister implementation
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2004-2013 triAGENS GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is triAGENS GmbH, Cologne, Germany
///
/// @author Jan Steemann
/// @author Copyright 2012-2013, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
#ifndef TRIAGENS_BASICS_C_MERSENNE_H
#define TRIAGENS_BASICS_C_MERSENNE_H 1
#include "BasicsC/common.h"
#ifdef __cplusplus
extern "C" {
#endif
// -----------------------------------------------------------------------------
// --SECTION-- MERSENNE TWISTER
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// --SECTION-- public functions
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Random
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief initialise the mersenne twister
/// this function needs to be called just once on startup
////////////////////////////////////////////////////////////////////////////////
void TRI_InitialiseMersenneTwister (void);
////////////////////////////////////////////////////////////////////////////////
/// @brief explicitly seed the mersenne twister
////////////////////////////////////////////////////////////////////////////////
void TRI_SeedMersenneTwister (uint32_t);
////////////////////////////////////////////////////////////////////////////////
/// @brief generate a 31 bit random number
///
/// generates a random number on [0,0x7fffffff]-interval
////////////////////////////////////////////////////////////////////////////////
uint32_t TRI_Int31MersenneTwister (void);
////////////////////////////////////////////////////////////////////////////////
/// @brief generate a 32 bit random number
///
/// generates a random number on [0,0xffffffff]-interval
////////////////////////////////////////////////////////////////////////////////
uint32_t TRI_Int32MersenneTwister (void);
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
}
#endif
#endif
// Local Variables:
// mode: outline-minor
// outline-regexp: "/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|/// @page\\|// --SECTION--\\|/// @\\}"
// End:

View File

@ -84,7 +84,6 @@ add_library(
BasicsC/linked-list.c
BasicsC/logging.c
BasicsC/memory.c
BasicsC/mersenne.c
BasicsC/mimetypes.c
BasicsC/prime-numbers.c
BasicsC/process-utils.c

View File

@ -54,7 +54,6 @@ lib_libarango_a_SOURCES = \
lib/BasicsC/logging.c \
lib/BasicsC/memory.c \
lib/BasicsC/memory-map-posix.c \
lib/BasicsC/mersenne.c \
lib/BasicsC/mimetypes.c \
lib/BasicsC/prime-numbers.c \
lib/BasicsC/process-utils.c \