libfoedus-core
FOEDUS Core Library
foedus::assorted::ZipfianRandom Class Reference

A simple zipfian generator based off of YCSB's Java implementation. More...

Detailed Description

A simple zipfian generator based off of YCSB's Java implementation.

The major user is YCSB. 0 <= theta < 1, higher means more skewed. Generates a random number between 0 and max_.

Definition at line 37 of file zipfian_random.hpp.

#include <zipfian_random.hpp>

Public Member Functions

void init (uint64_t items, double theta, uint64_t urnd_seed)
 
 ZipfianRandom (uint64_t items, double theta, uint64_t urnd_seed)
 
 ZipfianRandom ()
 
uint64_t next ()
 
uint64_t get_current_seed () const
 
void set_current_seed (uint64_t seed)
 

Constructor & Destructor Documentation

foedus::assorted::ZipfianRandom::ZipfianRandom ( uint64_t  items,
double  theta,
uint64_t  urnd_seed 
)
inline

Definition at line 57 of file zipfian_random.hpp.

References init().

57  {
58  init(items, theta, urnd_seed);
59  }
void init(uint64_t items, double theta, uint64_t urnd_seed)

Here is the call graph for this function:

foedus::assorted::ZipfianRandom::ZipfianRandom ( )
inline

Definition at line 61 of file zipfian_random.hpp.

61 {}

Member Function Documentation

uint64_t foedus::assorted::ZipfianRandom::get_current_seed ( ) const
inline

Definition at line 78 of file zipfian_random.hpp.

References foedus::assorted::UniformRandom::get_current_seed().

78 { return urnd_.get_current_seed(); }

Here is the call graph for this function:

void foedus::assorted::ZipfianRandom::init ( uint64_t  items,
double  theta,
uint64_t  urnd_seed 
)
inline

Definition at line 48 of file zipfian_random.hpp.

References foedus::assorted::UniformRandom::set_current_seed().

Referenced by ZipfianRandom().

48  {
49  max_ = items - 1;
50  theta_ = theta;
51  zetan_ = zeta(items);
52  alpha_ = 1.0 / (1.0 - theta_);
53  eta_ = (1 - std::pow(2.0 / items, 1 - theta_)) / (1 - zeta(2) / zetan_);
54  urnd_.set_current_seed(urnd_seed);
55  }
void set_current_seed(uint64_t seed)

Here is the call graph for this function:

Here is the caller graph for this function:

uint64_t foedus::assorted::ZipfianRandom::next ( )
inline

Definition at line 63 of file zipfian_random.hpp.

References foedus::assorted::UniformRandom::uniform_within().

63  {
64  double u = urnd_.uniform_within(0, max_) / static_cast<double>(max_);
65  double uz = u * zetan_;
66  if (uz < 1.0) {
67  return 0;
68  }
69 
70  if (uz < 1.0 + std::pow(0.5, theta_)) {
71  return 1;
72  }
73 
74  uint64_t ret = static_cast<uint64_t>(max_ * std::pow(eta_ * u - eta_ + 1, alpha_));
75  return ret;
76  }
uint32_t uniform_within(uint32_t from, uint32_t to)
In TPCC terminology, from=x, to=y.

Here is the call graph for this function:

void foedus::assorted::ZipfianRandom::set_current_seed ( uint64_t  seed)
inline

Definition at line 79 of file zipfian_random.hpp.

References foedus::assorted::UniformRandom::set_current_seed().

79 { urnd_.set_current_seed(seed); }
void set_current_seed(uint64_t seed)

Here is the call graph for this function:


The documentation for this class was generated from the following file: