proxygen
folly::compression::BitVectorReader< Encoder, Instructions, kUnchecked > Class Template Reference

#include <BitVectorCoding.h>

Inheritance diagram for folly::compression::BitVectorReader< Encoder, Instructions, kUnchecked >:
folly::compression::detail::ForwardPointers< Encoder::forwardQuantum > folly::compression::detail::SkipPointers< Encoder::skipQuantum >

Public Types

typedef Encoder EncoderType
 
typedef Encoder::ValueType ValueType
 
typedef Encoder::ValueType SizeType
 
typedef Encoder::SkipValueType SkipValueType
 

Public Member Functions

 BitVectorReader (const typename Encoder::CompressedList &list)
 
void reset ()
 
bool next ()
 
bool skip (SizeType n)
 
bool skipTo (ValueType v)
 
SizeType size () const
 
bool valid () const
 
SizeType position () const
 
ValueType value () const
 
bool jump (SizeType n)
 
bool jumpTo (ValueType v)
 
bool setDone ()
 

Private Member Functions

bool setValue (size_t inner)
 
void reposition (size_t dest)
 
- Private Member Functions inherited from folly::compression::detail::ForwardPointers< Encoder::forwardQuantum >
 ForwardPointers (const unsigned char *ptr)
 
- Private Member Functions inherited from folly::compression::detail::SkipPointers< Encoder::skipQuantum >
 SkipPointers (const unsigned char *ptr)
 

Private Attributes

const uint8_t *const bits_
 
uint64_t block_
 
SizeType outer_
 
SizeType position_
 
ValueType value_
 
const SizeType size_
 
const ValueType upperBound_
 
- Private Attributes inherited from folly::compression::detail::ForwardPointers< Encoder::forwardQuantum >
const unsigned char *const forwardPointers_
 
- Private Attributes inherited from folly::compression::detail::SkipPointers< Encoder::skipQuantum >
const unsigned char *const skipPointers_
 

Static Private Attributes

static constexpr ValueType kInvalidValue
 
static constexpr size_t kLinearScanThreshold = 4
 

Detailed Description

template<class Encoder, class Instructions = instructions::Default, bool kUnchecked = false>
class folly::compression::BitVectorReader< Encoder, Instructions, kUnchecked >

Definition at line 247 of file BitVectorCoding.h.

Member Typedef Documentation

template<class Encoder , class Instructions = instructions::Default, bool kUnchecked = false>
typedef Encoder folly::compression::BitVectorReader< Encoder, Instructions, kUnchecked >::EncoderType

Definition at line 250 of file BitVectorCoding.h.

template<class Encoder , class Instructions = instructions::Default, bool kUnchecked = false>
typedef Encoder::ValueType folly::compression::BitVectorReader< Encoder, Instructions, kUnchecked >::SizeType

Definition at line 253 of file BitVectorCoding.h.

template<class Encoder , class Instructions = instructions::Default, bool kUnchecked = false>
typedef Encoder::SkipValueType folly::compression::BitVectorReader< Encoder, Instructions, kUnchecked >::SkipValueType

Definition at line 254 of file BitVectorCoding.h.

template<class Encoder , class Instructions = instructions::Default, bool kUnchecked = false>
typedef Encoder::ValueType folly::compression::BitVectorReader< Encoder, Instructions, kUnchecked >::ValueType

Definition at line 251 of file BitVectorCoding.h.

Constructor & Destructor Documentation

template<class Encoder , class Instructions = instructions::Default, bool kUnchecked = false>
folly::compression::BitVectorReader< Encoder, Instructions, kUnchecked >::BitVectorReader ( const typename Encoder::CompressedList &  list)
inlineexplicit

Definition at line 256 of file BitVectorCoding.h.

257  : detail::ForwardPointers<Encoder::forwardQuantum>(list.forwardPointers),
258  detail::SkipPointers<Encoder::skipQuantum>(list.skipPointers),
259  bits_(list.bits),
260  size_(list.size),
261  upperBound_(
262  (kUnchecked || UNLIKELY(list.size == 0)) ? 0 : list.upperBound) {
263  reset();
264  }
Encoder::MutableCompressedList list
#define UNLIKELY(x)
Definition: Likely.h:48

Member Function Documentation

template<class Encoder , class Instructions = instructions::Default, bool kUnchecked = false>
bool folly::compression::BitVectorReader< Encoder, Instructions, kUnchecked >::jump ( SizeType  n)
inline

Definition at line 404 of file BitVectorCoding.h.

References folly::gen::skip().

404  {
405  reset();
406  return skip(n + 1);
407  }
template<class Encoder , class Instructions = instructions::Default, bool kUnchecked = false>
bool folly::compression::BitVectorReader< Encoder, Instructions, kUnchecked >::jumpTo ( ValueType  v)
inline

Definition at line 409 of file BitVectorCoding.h.

409  {
410  reset();
411  return skipTo(v);
412  }
template<class Encoder , class Instructions = instructions::Default, bool kUnchecked = false>
bool folly::compression::BitVectorReader< Encoder, Instructions, kUnchecked >::next ( )
inline

Definition at line 273 of file BitVectorCoding.h.

References uint64_t, and UNLIKELY.

273  {
274  if (!kUnchecked && UNLIKELY(position() + 1 >= size_)) {
275  return setDone();
276  }
277 
278  while (block_ == 0) {
279  outer_ += sizeof(uint64_t);
280  block_ = folly::loadUnaligned<uint64_t>(bits_ + outer_);
281  }
282 
283  ++position_;
284  auto inner = Instructions::ctz(block_);
285  block_ = Instructions::blsr(block_);
286 
287  return setValue(inner);
288  }
#define UNLIKELY(x)
Definition: Likely.h:48
template<class Encoder , class Instructions = instructions::Default, bool kUnchecked = false>
SizeType folly::compression::BitVectorReader< Encoder, Instructions, kUnchecked >::position ( ) const
inline

Definition at line 396 of file BitVectorCoding.h.

396  {
397  return position_;
398  }
template<class Encoder , class Instructions = instructions::Default, bool kUnchecked = false>
void folly::compression::BitVectorReader< Encoder, Instructions, kUnchecked >::reposition ( size_t  dest)
inlineprivate

Definition at line 430 of file BitVectorCoding.h.

References uint64_t.

430  {
431  outer_ = dest / 64 * 8;
432  // We maintain the invariant that outer_ is divisible by 8.
433  block_ = folly::loadUnaligned<uint64_t>(bits_ + outer_);
434  block_ &= ~((uint64_t(1) << (dest % 64)) - 1);
435  }
dest
Definition: upload.py:394
template<class Encoder , class Instructions = instructions::Default, bool kUnchecked = false>
void folly::compression::BitVectorReader< Encoder, Instructions, kUnchecked >::reset ( )
inline

Definition at line 266 of file BitVectorCoding.h.

266  {
267  block_ = (bits_ != nullptr) ? folly::loadUnaligned<uint64_t>(bits_) : 0;
268  outer_ = 0;
269  position_ = -1;
271  }
static constexpr ValueType kInvalidValue
template<class Encoder , class Instructions = instructions::Default, bool kUnchecked = false>
bool folly::compression::BitVectorReader< Encoder, Instructions, kUnchecked >::setDone ( )
inline

Definition at line 414 of file BitVectorCoding.h.

414  {
416  position_ = size_;
417  return false;
418  }
static constexpr ValueType kInvalidValue
template<class Encoder , class Instructions = instructions::Default, bool kUnchecked = false>
bool folly::compression::BitVectorReader< Encoder, Instructions, kUnchecked >::setValue ( size_t  inner)
inlineprivate

Definition at line 425 of file BitVectorCoding.h.

425  {
426  value_ = static_cast<ValueType>(8 * outer_ + inner);
427  return true;
428  }
template<class Encoder , class Instructions = instructions::Default, bool kUnchecked = false>
SizeType folly::compression::BitVectorReader< Encoder, Instructions, kUnchecked >::size ( ) const
inline

Definition at line 388 of file BitVectorCoding.h.

388  {
389  return size_;
390  }
template<class Encoder , class Instructions = instructions::Default, bool kUnchecked = false>
bool folly::compression::BitVectorReader< Encoder, Instructions, kUnchecked >::skip ( SizeType  n)
inline

Definition at line 290 of file BitVectorCoding.h.

References upload::dest, i, LIKELY, cpp.ast::next(), folly::popcount(), shell_builder::steps, and uint64_t.

290  {
291  CHECK_GT(n, 0);
292 
293  if (!kUnchecked && position() + n >= size_) {
294  return setDone();
295  }
296  // Small skip optimization.
297  if (LIKELY(n < kLinearScanThreshold)) {
298  for (size_t i = 0; i < n; ++i) {
299  next();
300  }
301  return true;
302  }
303 
304  position_ += n;
305 
306  // Use forward pointer.
307  if (Encoder::forwardQuantum > 0 && n > Encoder::forwardQuantum) {
308  const size_t steps = position_ / Encoder::forwardQuantum;
309  const size_t dest = folly::loadUnaligned<SkipValueType>(
310  this->forwardPointers_ + (steps - 1) * sizeof(SkipValueType));
311 
312  reposition(dest);
313  n = position_ + 1 - steps * Encoder::forwardQuantum;
314  }
315 
316  size_t cnt;
317  // Find necessary block.
318  while ((cnt = Instructions::popcount(block_)) < n) {
319  n -= cnt;
320  outer_ += sizeof(uint64_t);
321  block_ = folly::loadUnaligned<uint64_t>(bits_ + outer_);
322  }
323 
324  // Skip to the n-th one in the block.
325  DCHECK_GT(n, 0);
326  auto inner = select64<Instructions>(block_, n - 1);
327  block_ &= (uint64_t(-1) << inner) << 1;
328 
329  return setValue(inner);
330  }
constexpr unsigned int popcount(T const v)
Definition: Bits.h:130
Encoder::SkipValueType SkipValueType
#define LIKELY(x)
Definition: Likely.h:47
dest
Definition: upload.py:394
static constexpr size_t kLinearScanThreshold
template<class Encoder , class Instructions = instructions::Default, bool kUnchecked = false>
bool folly::compression::BitVectorReader< Encoder, Instructions, kUnchecked >::skipTo ( ValueType  v)
inline

Definition at line 332 of file BitVectorCoding.h.

References cpp.ast::next(), folly::popcount(), uint64_t, and folly::value().

332  {
333  // Also works when value_ == kInvalidValue.
334  if (v != kInvalidValue) {
335  DCHECK_GE(v + 1, value_ + 1);
336  }
337 
338  if (!kUnchecked && v > upperBound_) {
339  return setDone();
340  } else if (v == value_) {
341  return true;
342  }
343 
344  // Small skip optimization.
345  if (v - value_ < kLinearScanThreshold) {
346  do {
347  next();
348  } while (value() < v);
349 
350  return true;
351  }
352 
353  if (Encoder::skipQuantum > 0 && v - value_ > Encoder::skipQuantum) {
354  size_t q = v / Encoder::skipQuantum;
355  auto skipPointer = folly::loadUnaligned<SkipValueType>(
356  this->skipPointers_ + (q - 1) * sizeof(SkipValueType));
357  position_ = static_cast<SizeType>(skipPointer) - 1;
358 
359  reposition(q * Encoder::skipQuantum);
360  }
361 
362  // Find the value.
363  size_t outer = v / 64 * 8;
364 
365  while (outer_ < outer) {
367  outer_ += sizeof(uint64_t);
368  block_ = folly::loadUnaligned<uint64_t>(bits_ + outer_);
369  }
370 
371  DCHECK_EQ(outer_, outer);
372  uint64_t mask = ~((uint64_t(1) << (v % 64)) - 1);
373  position_ += Instructions::popcount(block_ & ~mask) + 1;
374  block_ &= mask;
375 
376  while (block_ == 0) {
377  outer_ += sizeof(uint64_t);
378  block_ = folly::loadUnaligned<uint64_t>(bits_ + outer_);
379  }
380 
381  auto inner = Instructions::ctz(block_);
382  block_ = Instructions::blsr(block_);
383 
384  setValue(inner);
385  return true;
386  }
constexpr unsigned int popcount(T const v)
Definition: Bits.h:130
Encoder::SkipValueType SkipValueType
static constexpr size_t kLinearScanThreshold
static constexpr ValueType kInvalidValue
template<class Encoder , class Instructions = instructions::Default, bool kUnchecked = false>
bool folly::compression::BitVectorReader< Encoder, Instructions, kUnchecked >::valid ( ) const
inline

Definition at line 392 of file BitVectorCoding.h.

References folly::compression::BitVectorCompressedListBase< Pointer >::size.

392  {
393  return position() < size(); // Also checks that position() != -1.
394  }
template<class Encoder , class Instructions = instructions::Default, bool kUnchecked = false>
ValueType folly::compression::BitVectorReader< Encoder, Instructions, kUnchecked >::value ( ) const
inline

Definition at line 399 of file BitVectorCoding.h.

399  {
400  DCHECK(valid());
401  return value_;
402  }

Member Data Documentation

template<class Encoder , class Instructions = instructions::Default, bool kUnchecked = false>
const uint8_t* const folly::compression::BitVectorReader< Encoder, Instructions, kUnchecked >::bits_
private

Definition at line 439 of file BitVectorCoding.h.

template<class Encoder , class Instructions = instructions::Default, bool kUnchecked = false>
uint64_t folly::compression::BitVectorReader< Encoder, Instructions, kUnchecked >::block_
private

Definition at line 440 of file BitVectorCoding.h.

template<class Encoder , class Instructions = instructions::Default, bool kUnchecked = false>
constexpr ValueType folly::compression::BitVectorReader< Encoder, Instructions, kUnchecked >::kInvalidValue
staticprivate
Initial value:

Definition at line 421 of file BitVectorCoding.h.

template<class Encoder , class Instructions = instructions::Default, bool kUnchecked = false>
constexpr size_t folly::compression::BitVectorReader< Encoder, Instructions, kUnchecked >::kLinearScanThreshold = 4
staticprivate

Definition at line 437 of file BitVectorCoding.h.

template<class Encoder , class Instructions = instructions::Default, bool kUnchecked = false>
SizeType folly::compression::BitVectorReader< Encoder, Instructions, kUnchecked >::outer_
private

Definition at line 441 of file BitVectorCoding.h.

template<class Encoder , class Instructions = instructions::Default, bool kUnchecked = false>
SizeType folly::compression::BitVectorReader< Encoder, Instructions, kUnchecked >::position_
private

Definition at line 442 of file BitVectorCoding.h.

template<class Encoder , class Instructions = instructions::Default, bool kUnchecked = false>
const SizeType folly::compression::BitVectorReader< Encoder, Instructions, kUnchecked >::size_
private

Definition at line 445 of file BitVectorCoding.h.

template<class Encoder , class Instructions = instructions::Default, bool kUnchecked = false>
const ValueType folly::compression::BitVectorReader< Encoder, Instructions, kUnchecked >::upperBound_
private

Definition at line 446 of file BitVectorCoding.h.

template<class Encoder , class Instructions = instructions::Default, bool kUnchecked = false>
ValueType folly::compression::BitVectorReader< Encoder, Instructions, kUnchecked >::value_
private

Definition at line 443 of file BitVectorCoding.h.


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