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

Represents a file of unsigned integers compressed using gamma compression. More...

#include <compressed_file_reader.h>

Classes

class  compressed_file_reader_exception
 Basic exception for compressed_file_reader interactions. More...
 

Public Member Functions

 compressed_file_reader (const mmap_file &file, std::function< uint64_t(uint64_t)> mapping)
 Constructor; opens a compressed file for reading using the given mapping. More...
 
 compressed_file_reader (const std::string &filename, std::function< uint64_t(uint64_t)> mapping)
 Constructor to create a new mmap file for reading. More...
 
 ~compressed_file_reader ()
 Destructor.
 
void reset ()
 Sets the cursor back to the beginning of the file.
 
void close ()
 Closes this compressed file.
 
void seek (uint64_t bit_offset)
 Sets the cursor to the specified position in the file. More...
 
bool has_next () const
 
uint64_t next ()
 
std::string next_string ()
 
uint64_t bit_location () const
 
 operator bool () const
 

Private Member Functions

void get_next ()
 Seeks to the next compressed number and returns the current cached value.
 
bool read_bit ()
 

Private Attributes

std::unique_ptr< mmap_filefile_
 Pointer to the mmap_file we are reading: nullptr if we don't own it, initialized if we do.
 
char * start_
 Pointer to the beginning of the compressed file (which will be in memory most of the time)
 
uint64_t size_
 the number of bytes in this compressed file
 
int status_
 reading/writing status
 
uint64_t current_value_
 current numeric value that was read
 
uint64_t current_char_
 current byte in the compressed file
 
uint8_t current_bit_
 current bit inside the current byte
 
std::function< uint64_t(uint64_t)> mapping_
 hold the (actual -> compressed id) mapping
 

Detailed Description

Represents a file of unsigned integers compressed using gamma compression.

Constructor & Destructor Documentation

meta::io::compressed_file_reader::compressed_file_reader ( const mmap_file file,
std::function< uint64_t(uint64_t)>  mapping 
)

Constructor; opens a compressed file for reading using the given mapping.

Parameters
fileThe file to read from
mappingA function to map the original numbers to their compressed id, usually to take advantage of a skewed distribution of towards many small numbers
meta::io::compressed_file_reader::compressed_file_reader ( const std::string &  filename,
std::function< uint64_t(uint64_t)>  mapping 
)

Constructor to create a new mmap file for reading.

Parameters
filenameThe filename for the new file to read from
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

void meta::io::compressed_file_reader::seek ( uint64_t  bit_offset)

Sets the cursor to the specified position in the file.

It is up to the user to specify a valid position.

Parameters
bit_offsetBit offset into the file
bool meta::io::compressed_file_reader::has_next ( ) const
Returns
whether there is another number in the file
uint64_t meta::io::compressed_file_reader::next ( )
Returns
the next compressed number
std::string meta::io::compressed_file_reader::next_string ( )
Returns
the next string from this compressed file
uint64_t meta::io::compressed_file_reader::bit_location ( ) const
Returns
the current bit location in this file
meta::io::compressed_file_reader::operator bool ( ) const
inline
Returns
whether reading from this compressed file is still good
bool meta::io::compressed_file_reader::read_bit ( )
private
Returns
the next bit in the file

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