0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DiscreteRandomGeneratorFactory.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; version 3 of the
9  * License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
28 #include "Common/Compat.h"
29 #include "Common/Logger.h"
30 
31 #include <cstdlib>
32 #include <vector>
33 
34 #include <boost/algorithm/string.hpp>
35 #include <boost/algorithm/string/predicate.hpp>
36 
40 
41 using namespace Hypertable;
42 using namespace std;
43 using namespace boost;
44 
47  vector<String> args;
48  String name;
49 
50  split(args, spec, is_any_of("\t "));
51 
52  if (!args.empty()) {
53  name = args.front();
54  args.erase(args.begin());
55  }
56 
57  if (name == "uniform")
58  return make_shared<DiscreteRandomGeneratorUniform>();
59 
60  if (name == "zipf") {
61  if (args.empty())
62  return make_shared<DiscreteRandomGeneratorZipf>();
63  if (starts_with(args[0], "--s=")) {
64  String s_str = args[0].substr(4);
65  double s_val;
66  s_val = strtod(s_str.c_str(), 0);
67  return make_shared<DiscreteRandomGeneratorZipf>(s_val);
68  }
69  }
70 
71  HT_FATALF("Unrecognized distribution (%s)", name.c_str());
73 }
Boost library.
Definition: Properties.cc:39
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
STL namespace.
static DiscreteRandomGeneratorPtr create(const String &spec)
Creates a new DiscreteRandomGenerator instance.
Discrete Random Generator creating a zipfian distribution.
std::shared_ptr< DiscreteRandomGenerator > DiscreteRandomGeneratorPtr
Factory for Discrete Random Generators.
Logging routines and macros.
Compatibility Macros for C/C++.
Hypertable definitions
#define HT_FATALF(msg,...)
Definition: Logger.h:343
bool split(int flags)
Tests the SPLIT bit of flags
Discreet Random Generator creating uniform distributed numbers.