TPIE

11a2c2d
tpie::compressed_stream_base Class Reference

Base class containing the implementation details that are independent of the item type. More...

#include <tpie/compressed/stream.h>

Classes

struct  seek_state
 

Public Types

typedef file_stream_base::offset_type offset_type
 

Public Member Functions

bool is_readable () const noexcept
 
bool is_writable () const noexcept
 
memory_size_type block_items () const
 
memory_size_type block_size () const
 
template<typename TT >
void read_user_data (TT &data)
 
memory_size_type read_user_data (void *data, memory_size_type count)
 
template<typename TT >
void write_user_data (const TT &data)
 
void write_user_data (const void *data, memory_size_type count)
 
memory_size_type user_data_size () const
 
memory_size_type max_user_data_size () const
 
const std::string & path () const
 
void open (const std::string &path, access_type accessType, memory_size_type userDataSize=0, cache_hint cacheHint=access_sequential, compression_flags compressionFlags=compression_none)
 Deprecated interface for opening a named stream. More...
 
void open (memory_size_type userDataSize, cache_hint cacheHint=access_sequential, compression_flags compressionFlags=compression_none)
 Deprecated interface for opening an unnamed temporary stream. More...
 
void open (temp_file &file, access_type accessType, memory_size_type userDataSize=0, cache_hint cacheHint=access_sequential, compression_flags compressionFlags=compression_none)
 Deprecated interface for opening a temporary stream. More...
 
void open (const std::string &path, compression_flags compressionFlags)
 Deprecated interface for opening a named stream. More...
 
void open (compression_flags compressionFlags)
 Deprecated interface for opening an unnamed temporary stream. More...
 
void open (temp_file &file, compression_flags compressionFlags)
 Deprecated interface for opening a temporary stream. More...
 
void open (const std::string &path, open::type openFlags=open::defaults, memory_size_type userDataSize=0)
 Open and possibly create a stream. More...
 
void open (open::type openFlags=open::defaults, memory_size_type userDataSize=0)
 Open and create an unnamed temporary stream. More...
 
void open (temp_file &file, open::type openFlags=open::defaults, memory_size_type userDataSize=0)
 Open and possibly create a temporary stream. More...
 
void close ()
 
bool is_open () const noexcept
 
stream_size_type offset () const
 
void describe (std::ostream &out)
 For debugging: Describe the internal stream state in a string. More...
 
std::string describe ()
 For debugging: Describe the internal stream state in a string. More...
 
void seek (stream_offset_type offset, offset_type whence=beginning)
 Precondition: is_open() Precondition: offset == 0. More...
 
void truncate (stream_size_type offset)
 Truncate to given size. More...
 
void truncate (const stream_position &pos)
 Truncate to given stream position. More...
 
stream_position get_position ()
 Store the current stream position such that it may be found later on. More...
 
void set_position (const stream_position &pos)
 Seek to a position that was previously recalled with get_position. More...
 
stream_size_type size () const
 
stream_size_type file_size () const
 
bool can_read ()
 Check if the next call to read() will succeed or not. More...
 
bool can_read_back ()
 Check if the next call to read_back() will succeed or not. More...
 

Static Public Member Functions

static memory_size_type block_size (double blockFactor) noexcept
 
static double calculate_block_factor (memory_size_type blockSize) noexcept
 
static memory_size_type block_memory_usage (double blockFactor) noexcept
 

Static Public Attributes

static const file_stream_base::offset_type beginning = file_stream_base::beginning
 
static const file_stream_base::offset_type end = file_stream_base::end
 
static const file_stream_base::offset_type current = file_stream_base::current
 

Protected Member Functions

 compressed_stream_base (memory_size_type itemSize, double blockFactor)
 
void cache_read_writes ()
 Compute number of cheap, unchecked reads/writes we can do from now. More...
 
void peak_unlikely ()
 
void read_back_unlikely ()
 
void write_unlikely (const char *item)
 

Static Protected Member Functions

static memory_size_type memory_usage (double blockFactor=1.0) noexcept
 

Protected Attributes

memory_size_type m_cachedReads
 Number of cheap, unchecked reads we can do next. More...
 
memory_size_type m_cachedWrites
 Number of cheap, unchecked writes we can do next. More...
 
stream_size_type m_size
 Number of logical items in the stream. More...
 
seek_state::type m_seekState
 Buffer manager for this entire stream. More...
 
stream_size_type m_offset
 Offset of next item to read/write, relative to beginning of stream. More...
 
char * m_bufferBegin
 Only when m_buffer.get() != 0: First item in writable buffer. More...
 
char * m_bufferEnd
 Only when m_buffer.get() != 0: End of writable buffer. More...
 
char * m_nextItem
 Next item in buffer to read/write. More...
 
compressed_stream_base_p * m_p
 

Friends

class compressed_stream_base_p
 

Detailed Description

Base class containing the implementation details that are independent of the item type.

Definition at line 79 of file stream.h.

Member Function Documentation

◆ cache_read_writes()

void tpie::compressed_stream_base::cache_read_writes ( )
protected

Compute number of cheap, unchecked reads/writes we can do from now.

◆ can_read()

bool tpie::compressed_stream_base::can_read ( )
inline

Check if the next call to read() will succeed or not.

Definition at line 328 of file stream.h.

328  {
329  if (m_cachedReads > 0) return true;
330  return offset() < size();
331  }

◆ can_read_back()

bool tpie::compressed_stream_base::can_read_back ( )
inline

Check if the next call to read_back() will succeed or not.

Definition at line 336 of file stream.h.

336  {
337  return offset() > 0;
338  }

◆ describe() [1/2]

std::string tpie::compressed_stream_base::describe ( )

For debugging: Describe the internal stream state in a string.

◆ describe() [2/2]

void tpie::compressed_stream_base::describe ( std::ostream &  out)

For debugging: Describe the internal stream state in a string.

◆ get_position()

stream_position tpie::compressed_stream_base::get_position ( )

Store the current stream position such that it may be found later on.

The stream_position object is violated if the stream is eventually truncated to before the current position.

The stream_position objects are plain old data, so they may themselves be written to streams.

Blocks to take the compressor lock.

◆ open() [1/9]

void tpie::compressed_stream_base::open ( compression_flags  compressionFlags)

Deprecated interface for opening an unnamed temporary stream.

◆ open() [2/9]

void tpie::compressed_stream_base::open ( const std::string &  path,
access_type  accessType,
memory_size_type  userDataSize = 0,
cache_hint  cacheHint = access_sequential,
compression_flags  compressionFlags = compression_none 
)

Deprecated interface for opening a named stream.

If compressionFlags is compression_none and the file does not already exist, no compression will be used when writing. If compressionFlags is compression_normal and the file does not already exist, compression will be used when writing. If the file already exists, the compression flags of the existing file are used instead.

◆ open() [3/9]

void tpie::compressed_stream_base::open ( const std::string &  path,
compression_flags  compressionFlags 
)

Deprecated interface for opening a named stream.

◆ open() [4/9]

void tpie::compressed_stream_base::open ( const std::string &  path,
open::type  openFlags = open::defaults,
memory_size_type  userDataSize = 0 
)

Open and possibly create a stream.

The stream is created if it does not exist and opened for reading and writing, but this can be changed with open::read_only or open::write_only; see below.

The flags supplied to openFlags should be a combination of the following from open::type, OR'ed together:

open::read_only Open for reading only, and fail if the stream does not exist.

open::write_only Open for writing only, and truncate the stream if it exists.

open::access_normal By default, POSIX_FADV_SEQUENTIAL is passed to the open syscall to indicate that the OS should optimize for sequential access; this flag disables that flag.

open::access_random Pass POSIX_FADV_RANDOM to the open syscall to make the OS optimize for random access.

open::compression_normal Create the stream in compression mode if it does not already exist, and compress written blocks according to available resources (for instance CPU time and memory).

open::compression_all Create the stream in compression mode if it does not already exist, and compress all written blocks using the preferred compression scheme, which can be set using tpie::the_compressor_thread().set_preferred_compression().

Parameters
pathThe path to the file to open
openFlagsA bit-wise combination of the flags; see above.
userDataSizeRequired user data capacity in stream header.

◆ open() [5/9]

void tpie::compressed_stream_base::open ( memory_size_type  userDataSize,
cache_hint  cacheHint = access_sequential,
compression_flags  compressionFlags = compression_none 
)

Deprecated interface for opening an unnamed temporary stream.

◆ open() [6/9]

void tpie::compressed_stream_base::open ( open::type  openFlags = open::defaults,
memory_size_type  userDataSize = 0 
)

Open and create an unnamed temporary stream.

Parameters
openFlagsA bit-wise combination of the flags; see above.
userDataSizeRequired user data capacity in stream header.

◆ open() [7/9]

void tpie::compressed_stream_base::open ( temp_file file,
access_type  accessType,
memory_size_type  userDataSize = 0,
cache_hint  cacheHint = access_sequential,
compression_flags  compressionFlags = compression_none 
)

Deprecated interface for opening a temporary stream.

◆ open() [8/9]

void tpie::compressed_stream_base::open ( temp_file file,
compression_flags  compressionFlags 
)

Deprecated interface for opening a temporary stream.

◆ open() [9/9]

void tpie::compressed_stream_base::open ( temp_file file,
open::type  openFlags = open::defaults,
memory_size_type  userDataSize = 0 
)

Open and possibly create a temporary stream.

Parameters
fileThe temporary file to open
openFlagsA bit-wise combination of the flags; see above.
userDataSizeRequired user data capacity in stream header.

◆ seek()

void tpie::compressed_stream_base::seek ( stream_offset_type  offset,
offset_type  whence = beginning 
)

Precondition: is_open() Precondition: offset == 0.

◆ set_position()

void tpie::compressed_stream_base::set_position ( const stream_position pos)

Seek to a position that was previously recalled with get_position.

◆ truncate() [1/2]

void tpie::compressed_stream_base::truncate ( const stream_position pos)

Truncate to given stream position.

◆ truncate() [2/2]

void tpie::compressed_stream_base::truncate ( stream_size_type  offset)

Truncate to given size.

Precondition: compression is disabled or offset is size() or 0. Blocks to take the compressor lock.

Member Data Documentation

◆ m_bufferBegin

char* tpie::compressed_stream_base::m_bufferBegin
protected

Only when m_buffer.get() != 0: First item in writable buffer.

Definition at line 367 of file stream.h.

◆ m_bufferEnd

char* tpie::compressed_stream_base::m_bufferEnd
protected

Only when m_buffer.get() != 0: End of writable buffer.

Definition at line 370 of file stream.h.

◆ m_cachedReads

memory_size_type tpie::compressed_stream_base::m_cachedReads
protected

Number of cheap, unchecked reads we can do next.

Definition at line 341 of file stream.h.

◆ m_cachedWrites

memory_size_type tpie::compressed_stream_base::m_cachedWrites
protected

Number of cheap, unchecked writes we can do next.

Definition at line 343 of file stream.h.

◆ m_nextItem

char* tpie::compressed_stream_base::m_nextItem
protected

Next item in buffer to read/write.

Definition at line 373 of file stream.h.

◆ m_offset

stream_size_type tpie::compressed_stream_base::m_offset
protected

Offset of next item to read/write, relative to beginning of stream.

Invariants:

block_number() in [0, m_streamBlocks] offset in [0, size] block_item_index() in [0, m_blockSize) offset == block_number() * m_blockItems + block_item_index()

block_item_index() <= offset.

If block_number() == m_streamBlocks, we are in a block that has not yet been written to disk.

Definition at line 364 of file stream.h.

◆ m_seekState

seek_state::type tpie::compressed_stream_base::m_seekState
protected

Buffer manager for this entire stream.

Definition at line 349 of file stream.h.

◆ m_size

stream_size_type tpie::compressed_stream_base::m_size
protected

Number of logical items in the stream.

Definition at line 346 of file stream.h.


The documentation for this class was generated from the following file:
tpie::compressed_stream_base::m_cachedReads
memory_size_type m_cachedReads
Number of cheap, unchecked reads we can do next.
Definition: stream.h:341