SHORE API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
shore::line_sorter< StrictWeakOrdering > Class Template Reference

ASCII text file sorting. More...

Public Member Functions

 line_sorter (StrictWeakOrdering cmp, const std::string &tmp=".", const double max_blockMB=2048.0, const bool uniq=false, const bool assertuniq=false, const size_t maxopenfiles=0)
 Constructor.
 
line_sortersafe ()
 Reset a call to unsafe().
 
line_sorterunsafe ()
 Do not check if input file are sorted in merge().
 
line_sortermmapmerge ()
 
line_sorternommapmerge ()
 
void sort_block (const char *const data_begin, const char *const data_end, std::ostream &out)
 Sort a block of lines in memory to a stream.
 
void sort_file (const std::string &fn_in, std::ostream &out)
 Sort a file.
 
void sort_file (std::istream &is, std::ostream &out)
 Sort a stream.
 
void sort_file (const std::string &fn_in, const std::string &fn_out)
 Sort a file.
 
void sort_file (const std::string &fn)
 Sort and replace a file.
 
void sort_files (const std::vector< std::string > &fn, std::ostream &out)
 Sort & merge multiple files.
 
void sort_files (const std::vector< std::string > &fn, const std::string &fn_out)
 Sort & merge multiple files.
 
bool is_sorted (std::istream &in)
 Check if a file is sorted. More...
 
bool is_sorted (std::istream &in, size_t *const line)
 Check if a file is sorted. More...
 
bool is_sorted (const std::string &fn, size_t *const line=0)
 Check if a file is sorted. More...
 
void merge_files (const std::vector< std::string > &infiles, std::ostream &out)
 Merge sorted text files. More...
 
void merge_files (const std::vector< std::string > &infiles, const std::string &fn_out)
 Merge sorted text files.
 
std::pair< off_t, std::string > upper_bound (std::istream &in, const std::string &what, const off_t rangemin=0l, off_t rangemax=-1l)
 Binary search on a text file. More...
 
std::pair< off_t, std::string > lower_bound (std::istream &in, const std::string &what, const off_t rangemin=0l, off_t rangemax=-1l)
 Binary search on a text file. More...
 

Detailed Description

template<class StrictWeakOrdering = bool(*)(const char*,const char*)>
class shore::line_sorter< StrictWeakOrdering >

ASCII text file sorting.

Member Function Documentation

template<class StrictWeakOrdering = bool(*)(const char*,const char*)>
bool shore::line_sorter< StrictWeakOrdering >::is_sorted ( std::istream &  in)
inline

Check if a file is sorted.

If uniq is set, check for strict sorting (default weak).

template<class StrictWeakOrdering = bool(*)(const char*,const char*)>
bool shore::line_sorter< StrictWeakOrdering >::is_sorted ( std::istream &  in,
size_t *const  line 
)
inline

Check if a file is sorted.

If uniq is set, check for strict sorting (default weak). The line number where the check failes is stored in line.

template<class StrictWeakOrdering = bool(*)(const char*,const char*)>
bool shore::line_sorter< StrictWeakOrdering >::is_sorted ( const std::string &  fn,
size_t *const  line = 0 
)
inline

Check if a file is sorted.

The line number where the check failes is stored in line.

template<class StrictWeakOrdering = bool(*)(const char*,const char*)>
std::pair<off_t,std::string> shore::line_sorter< StrictWeakOrdering >::lower_bound ( std::istream &  in,
const std::string &  what,
const off_t  rangemin = 0l,
off_t  rangemax = -1l 
)
inline

Binary search on a text file.

Returns
The position and text of the first line that does not compare less than 'what' in a file sorted according to comp (and also seeks to that position).
template<class StrictWeakOrdering = bool(*)(const char*,const char*)>
void shore::line_sorter< StrictWeakOrdering >::merge_files ( const std::vector< std::string > &  infiles,
std::ostream &  out 
)
inline

Merge sorted text files.

Also checks if input files are sorted unless unsafe() was called.

template<class StrictWeakOrdering = bool(*)(const char*,const char*)>
std::pair<off_t,std::string> shore::line_sorter< StrictWeakOrdering >::upper_bound ( std::istream &  in,
const std::string &  what,
const off_t  rangemin = 0l,
off_t  rangemax = -1l 
)
inline

Binary search on a text file.

Returns
The position and text of the first line that compares greater than 'what' in a file sorted according to comp and also seeks to that position).

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