proxygen
folly::detail::SkipListRandomHeight Class Reference

#include <ConcurrentSkipList-inl.h>

Public Member Functions

int getHeight (int maxHeight) const
 
size_t getSizeLimit (int height) const
 

Static Public Member Functions

static SkipListRandomHeightinstance ()
 

Private Types

enum  { kMaxHeight = 64 }
 

Private Member Functions

 SkipListRandomHeight ()
 
void initLookupTable ()
 

Static Private Member Functions

static double randomProb ()
 

Private Attributes

double lookupTable_ [kMaxHeight]
 
size_t sizeLimitTable_ [kMaxHeight]
 

Detailed Description

Definition at line 194 of file ConcurrentSkipList-inl.h.

Member Enumeration Documentation

anonymous enum
private
Enumerator
kMaxHeight 

Definition at line 195 of file ConcurrentSkipList-inl.h.

Constructor & Destructor Documentation

folly::detail::SkipListRandomHeight::SkipListRandomHeight ( )
inlineprivate

Definition at line 221 of file ConcurrentSkipList-inl.h.

Member Function Documentation

int folly::detail::SkipListRandomHeight::getHeight ( int  maxHeight) const
inline

Definition at line 204 of file ConcurrentSkipList-inl.h.

References i.

Referenced by folly::ConcurrentSkipList< T, Comp, NodeAlloc, MAX_HEIGHT >::addOrGetData().

204  {
205  DCHECK_LE(maxHeight, kMaxHeight) << "max height too big!";
206  double p = randomProb();
207  for (int i = 0; i < maxHeight; ++i) {
208  if (p < lookupTable_[i]) {
209  return i + 1;
210  }
211  }
212  return maxHeight;
213  }
size_t folly::detail::SkipListRandomHeight::getSizeLimit ( int  height) const
inline
void folly::detail::SkipListRandomHeight::initLookupTable ( )
inlineprivate

Definition at line 225 of file ConcurrentSkipList-inl.h.

References i, and max.

225  {
226  // set skip prob = 1/E
227  static const double kProbInv = exp(1);
228  static const double kProb = 1.0 / kProbInv;
229  static const size_t kMaxSizeLimit = std::numeric_limits<size_t>::max();
230 
231  double sizeLimit = 1;
232  double p = lookupTable_[0] = (1 - kProb);
233  sizeLimitTable_[0] = 1;
234  for (int i = 1; i < kMaxHeight - 1; ++i) {
235  p *= kProb;
236  sizeLimit *= kProbInv;
237  lookupTable_[i] = lookupTable_[i - 1] + p;
238  sizeLimitTable_[i] = sizeLimit > kMaxSizeLimit
239  ? kMaxSizeLimit
240  : static_cast<size_t>(sizeLimit);
241  }
242  lookupTable_[kMaxHeight - 1] = 1;
243  sizeLimitTable_[kMaxHeight - 1] = kMaxSizeLimit;
244  }
LogLevel max
Definition: LogLevel.cpp:31
static SkipListRandomHeight* folly::detail::SkipListRandomHeight::instance ( )
inlinestatic

Definition at line 199 of file ConcurrentSkipList-inl.h.

Referenced by folly::ConcurrentSkipList< T, Comp, NodeAlloc, MAX_HEIGHT >::addOrGetData().

199  {
200  static SkipListRandomHeight instance_;
201  return &instance_;
202  }
static double folly::detail::SkipListRandomHeight::randomProb ( )
inlinestaticprivate

Definition at line 246 of file ConcurrentSkipList-inl.h.

246  {
247  static ThreadLocal<boost::lagged_fibonacci2281> rng_;
248  return (*rng_)();
249  }

Member Data Documentation

double folly::detail::SkipListRandomHeight::lookupTable_[kMaxHeight]
private

Definition at line 251 of file ConcurrentSkipList-inl.h.

size_t folly::detail::SkipListRandomHeight::sizeLimitTable_[kMaxHeight]
private

Definition at line 252 of file ConcurrentSkipList-inl.h.


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