0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Classes | Public Member Functions | Private Attributes | List of all members
Hypertable::WordStream Class Reference

A class generating a stream of words; the words are retrieved from a file and can be randomized. More...

#include <WordStream.h>

Collaboration diagram for Hypertable::WordStream:
Collaboration graph
[legend]

Classes

struct  word_info
 Internal structure for a single word. More...
 

Public Member Functions

 WordStream (const String &word_file, unsigned seed, size_t words_per_record, bool random=false, const char *separator=" ")
 Constructor. More...
 
virtual ~WordStream ()
 Releases internal resources. More...
 
const char * next ()
 Retrieves the next word, or an empty string if EOF is reached. More...
 

Private Attributes

std::mt19937 ms_rng
 Random number generator. More...
 
char * m_base
 Base pointer for the memory mapped file. More...
 
const char * m_end
 End pointer for the memory mapped file. More...
 
const char * m_separator
 The separator, as specified by the user. More...
 
size_t m_words_per_record
 Words per record, as specified by the user. More...
 
off_t m_len
 Length of the memory mapped file. More...
 
std::vector< struct word_infom_words
 All words from the mapped file. More...
 
std::vector< size_t > m_offset
 Helper for parsing the words. More...
 
String m_record
 The current string. More...
 
bool m_random
 Whether to return random strings or not. More...
 

Detailed Description

A class generating a stream of words; the words are retrieved from a file and can be randomized.

Definition at line 46 of file WordStream.h.

Constructor & Destructor Documentation

WordStream::WordStream ( const String word_file,
unsigned  seed,
size_t  words_per_record,
bool  random = false,
const char *  separator = " " 
)

Constructor.

Parameters
word_fileThe file with all the words
seedThe seed for the random number generator; if 0 then no seed will be set
words_per_recordNumber of words to retrieve when calling next
randomIf true, words will be in random order
separatorThe word separator

Definition at line 46 of file WordStream.cc.

WordStream::~WordStream ( )
virtual

Releases internal resources.

Definition at line 83 of file WordStream.cc.

Member Function Documentation

const char * WordStream::next ( )

Retrieves the next word, or an empty string if EOF is reached.

Definition at line 87 of file WordStream.cc.

Member Data Documentation

char* Hypertable::WordStream::m_base
private

Base pointer for the memory mapped file.

Definition at line 79 of file WordStream.h.

const char* Hypertable::WordStream::m_end
private

End pointer for the memory mapped file.

Definition at line 82 of file WordStream.h.

off_t Hypertable::WordStream::m_len
private

Length of the memory mapped file.

Definition at line 91 of file WordStream.h.

std::vector<size_t> Hypertable::WordStream::m_offset
private

Helper for parsing the words.

Definition at line 97 of file WordStream.h.

bool Hypertable::WordStream::m_random
private

Whether to return random strings or not.

Definition at line 103 of file WordStream.h.

String Hypertable::WordStream::m_record
private

The current string.

Definition at line 100 of file WordStream.h.

const char* Hypertable::WordStream::m_separator
private

The separator, as specified by the user.

Definition at line 85 of file WordStream.h.

std::vector<struct word_info> Hypertable::WordStream::m_words
private

All words from the mapped file.

Definition at line 94 of file WordStream.h.

size_t Hypertable::WordStream::m_words_per_record
private

Words per record, as specified by the user.

Definition at line 88 of file WordStream.h.

std::mt19937 Hypertable::WordStream::ms_rng
private

Random number generator.

Definition at line 76 of file WordStream.h.


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