ModErn Text Analysis
META Enumerates Textual Applications
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
meta::io::compressed_file_writer Class Reference

Writes to a file of unsigned integers using gamma compression. More...

#include <compressed_file_writer.h>

Classes

class  compressed_file_writer_exception
 Basic exception for compressed_file_writer interactions. More...
 

Public Member Functions

 compressed_file_writer (const std::string &filename, std::function< uint64_t(uint64_t)> mapping)
 Constructor; Opens a compressed file for writing or creates a new file if it doesn't exist. More...
 
 ~compressed_file_writer ()
 Destructor; closes the compressed file.
 
uint64_t bit_location () const
 
void write (uint64_t value)
 Writes a value to the end of the compressed file. More...
 
void write (const std::string &str)
 Writes a binary string to the file. More...
 
void close ()
 Closes this compressed file.
 

Private Member Functions

void write_bit (bool bit)
 Writes a bit to the file and advances the current location in the file. More...
 
void write_buffer () const
 Writes the buffer to the file.
 

Private Attributes

FILE * outfile_
 Where to write the compressed data.
 
uint64_t char_cursor_
 The current byte this reader is on.
 
uint64_t bit_cursor_
 The current bit of the current byte this reader is on.
 
uint64_t buffer_size_
 How large to make the internal writer buffer.
 
unsigned char * buffer_
 Saved data that is not yet written to disk.
 
std::function< uint64_t(uint64_t)> mapping_
 The mapping to use (actual -> compressed id)
 
uint64_t bit_location_
 The number of total bits that have been written (for seeking)
 
bool closed_
 Ensures the file isn't closed more than once.
 

Detailed Description

Writes to a file of unsigned integers using gamma compression.

Constructor & Destructor Documentation

meta::io::compressed_file_writer::compressed_file_writer ( const std::string &  filename,
std::function< uint64_t(uint64_t)>  mapping 
)

Constructor; Opens a compressed file for writing or creates a new file if it doesn't exist.

Parameters
filenameThe path to the compressed file
mappingA function to map the original numbers to their compressed id, usually to take advantage of a skewed distribution of towards many small numbers

Member Function Documentation

uint64_t meta::io::compressed_file_writer::bit_location ( ) const
Returns
the character index and bit index of the current location in the compressed file
void meta::io::compressed_file_writer::write ( uint64_t  value)

Writes a value to the end of the compressed file.

Parameters
valueThe number to write
void meta::io::compressed_file_writer::write ( const std::string &  str)

Writes a binary string to the file.

Parameters
strThe string to write
void meta::io::compressed_file_writer::write_bit ( bool  bit)
private

Writes a bit to the file and advances the current location in the file.

Parameters
bit

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