Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
impala::BitWriter Class Reference

#include <bit-stream-utils.h>

Collaboration diagram for impala::BitWriter:

Public Member Functions

 BitWriter (uint8_t *buffer, int buffer_len)
 
void Clear ()
 
int bytes_written () const
 
uint8_t * buffer () const
 
int buffer_len () const
 
bool PutValue (uint64_t v, int num_bits)
 
template<typename T >
bool PutAligned (T v, int num_bytes)
 
bool PutVlqInt (int32_t v)
 
uint8_t * GetNextBytePtr (int num_bytes=1)
 
void Flush (bool align=false)
 

Private Attributes

uint8_t * buffer_
 
int max_bytes_
 
uint64_t buffered_values_
 
int byte_offset_
 
int bit_offset_
 

Detailed Description

Utility class to write bit/byte streams. This class can write data to either be bit packed or byte aligned (and a single stream that has a mix of both). This class does not allocate memory.

Definition at line 30 of file bit-stream-utils.h.

Constructor & Destructor Documentation

impala::BitWriter::BitWriter ( uint8_t *  buffer,
int  buffer_len 
)
inline

buffer: buffer to write bits to. Buffer should be preallocated with 'buffer_len' bytes.

Definition at line 34 of file bit-stream-utils.h.

References Clear().

Member Function Documentation

uint8_t* impala::BitWriter::buffer ( ) const
inline

Definition at line 49 of file bit-stream-utils.h.

References buffer_.

Referenced by impala::RleEncoder::buffer().

int impala::BitWriter::buffer_len ( ) const
inline

Definition at line 50 of file bit-stream-utils.h.

References max_bytes_.

Referenced by impala::RleEncoder::CheckBufferFull().

int impala::BitWriter::bytes_written ( ) const
inline

The number of current bytes written, including the current byte (i.e. may include a fraction of a byte). Includes buffered values.

Definition at line 48 of file bit-stream-utils.h.

References bit_offset_, byte_offset_, and impala::BitUtil::Ceil().

Referenced by impala::RleEncoder::CheckBufferFull(), impala::RleEncoder::Flush(), impala::RleEncoder::len(), and impala::TestBitArrayValues().

void impala::BitWriter::Clear ( )
inline

Definition at line 40 of file bit-stream-utils.h.

References bit_offset_, buffered_values_, and byte_offset_.

Referenced by BitWriter(), and impala::RleEncoder::Clear().

void impala::BitWriter::Flush ( bool  align = false)
inline

Flushes all buffered values to the buffer. Call this when done writing to the buffer. If 'align' is true, buffered_values_ is reset and any future writes will be written to the next byte boundary.

Definition at line 45 of file bit-stream-utils.inline.h.

References bit_offset_, buffer_, buffered_values_, byte_offset_, impala::BitUtil::Ceil(), and max_bytes_.

Referenced by impala::RleEncoder::Flush(), GetNextBytePtr(), impala::TEST(), impala::TestBitArrayValues(), and TestBitWriterEncode().

uint8_t * impala::BitWriter::GetNextBytePtr ( int  num_bytes = 1)
inline

Get a pointer to the next aligned byte and advance the underlying buffer by num_bytes. Returns NULL if there was not enough space.

Definition at line 57 of file bit-stream-utils.inline.h.

References buffer_, byte_offset_, Flush(), and max_bytes_.

Referenced by impala::RleEncoder::FlushLiteralRun(), and PutAligned().

template<typename T >
bool impala::BitWriter::PutAligned ( v,
int  num_bytes 
)
inline

Writes v to the next aligned byte using num_bytes. If T is larger than num_bytes, the extra high-order bytes will be ignored. Returns false if there was not enough space.

Definition at line 67 of file bit-stream-utils.inline.h.

References GetNextBytePtr().

Referenced by impala::RleEncoder::FlushRepeatedRun().

bool impala::BitWriter::PutValue ( uint64_t  v,
int  num_bits 
)
inline

Writes a value to buffered_values_, flushing to buffer_ if necessary. This is bit packed. Returns false if there was not enough space. num_bits must be <= 32.

Definition at line 23 of file bit-stream-utils.inline.h.

References bit_offset_, buffer_, buffered_values_, byte_offset_, max_bytes_, and UNLIKELY.

Referenced by impala::RleEncoder::FlushLiteralRun(), impala::TEST(), impala::TestBitArrayValues(), and TestBitWriterEncode().

bool impala::BitWriter::PutVlqInt ( int32_t  v)
inline

Write a Vlq encoded int to the buffer. Returns false if there was not enough room. The value is written byte aligned. For more details on vlq: en.wikipedia.org/wiki/Variable-length_quantity

Definition at line 74 of file bit-stream-utils.inline.h.

Referenced by impala::RleEncoder::FlushRepeatedRun().

Member Data Documentation

int impala::BitWriter::bit_offset_
private

Definition at line 86 of file bit-stream-utils.h.

Referenced by bytes_written(), Clear(), Flush(), and PutValue().

uint8_t* impala::BitWriter::buffer_
private

Definition at line 78 of file bit-stream-utils.h.

Referenced by buffer(), Flush(), GetNextBytePtr(), and PutValue().

uint64_t impala::BitWriter::buffered_values_
private

Bit-packed values are initially written to this variable before being memcpy'd to buffer_. This is faster than writing values byte by byte directly to buffer_.

Definition at line 83 of file bit-stream-utils.h.

Referenced by Clear(), Flush(), and PutValue().

int impala::BitWriter::byte_offset_
private

Definition at line 85 of file bit-stream-utils.h.

Referenced by bytes_written(), Clear(), Flush(), GetNextBytePtr(), and PutValue().

int impala::BitWriter::max_bytes_
private

Definition at line 79 of file bit-stream-utils.h.

Referenced by buffer_len(), Flush(), GetNextBytePtr(), and PutValue().


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