Tkrzw
Classes | Typedefs | Functions | Variables
tkrzw Namespace Reference

Common namespace of Tkrzw. More...

Classes

class  AtomicSet
 Thread-safe wrapper of std::set. More...
 
class  BabyDBM
 On-memory database manager implementation based on B+ tree. More...
 
class  CacheDBM
 On-memory database manager implementation with LRU deletion. More...
 
class  DBM
 Interface of database manager. More...
 
class  DoubleLRUCache
 Double-layered LRU cache. More...
 
class  File
 Interface of file operations. More...
 
class  FileIndex
 File secondary index implementation with TreeDBM. More...
 
class  FileReader
 File reader. More...
 
struct  FileStatus
 Status information of a file. More...
 
class  FlatRecord
 Flat record structure in the file. More...
 
class  FlatRecordReader
 Reader of flat records. More...
 
struct  FreeBlock
 Free block structure. More...
 
class  FreeBlockPool
 Registry of free blocks. More...
 
class  HashDBM
 File database manager implementation based on hash table. More...
 
class  HashMutex
 Mutex for a hash table. More...
 
class  HashRecord
 Key and value record structure in the file hash database. More...
 
class  LinkedHashMap
 Doubly-linked hash map. More...
 
class  LRUCache
 LRU cache. More...
 
class  MemIndex
 On-memory secondary index implementation with BabyDBM. More...
 
class  MemoryMapAtomicFile
 File implementation by memory mapping and locking for atomic operations. More...
 
class  MemoryMapFile
 Interface for memory mapping file implementations. More...
 
class  MemoryMapParallelFile
 File implementation by memory mapping and locking for parallel operations. More...
 
class  OffsetReader
 Reader of a sequence of offsets. More...
 
class  ParamDBM
 Parametric database manager interface. More...
 
class  PolyDBM
 Polymorphic database manager adapter. More...
 
class  PositionalAtomicFile
 File implementation with positional access and locking for atomic operations. More...
 
class  PositionalFile
 Interface for positional access file implementations. More...
 
class  PositionalParallelFile
 File implementation by positional access and locking for parallel operations. More...
 
class  RecordSorter
 Sorter for a large amound of records based on merge sort on files. More...
 
class  ScopedHashLock
 Scoped lock with a mutex for a hash table. More...
 
class  ScopedSlottedLock
 Scoped lock with a slotted shared mutex. More...
 
class  ShardDBM
 Sharding database manager adapter. More...
 
class  SkipDBM
 File database manager implementation based on skip list. More...
 
class  SkipRecord
 Key and value record structure in the file skip database. More...
 
class  SkipRecordCache
 Cache of skip records. More...
 
class  SlottedMutex
 Slotted shared mutex. More...
 
class  Status
 Status of operations. More...
 
class  StatusException
 Exception to convey the status of operations. More...
 
class  StdFile
 File implementation with the std::fstream. More...
 
class  StdHashDBM
 On-memory database manager implemented with std::unordered_map. More...
 
class  StdIndex
 On-memory secondary index implementation with std::map for generic types. More...
 
class  StdIndexStr
 On-memory secondary index implementation with std::map for strings. More...
 
class  StdTreeDBM
 On-memory database manager implemented with std::map. More...
 
class  TemporaryDirectory
 Temporary directory whose life duration is bound with the object. More...
 
class  TinyDBM
 On-memory database manager implementation based on hash table. More...
 
class  TreeDBM
 File database manager implementation based on B+ tree. More...
 
struct  TreeLink
 Link to a child node. More...
 
struct  TreeLinkComparator
 Comparator for TreeLink objects. More...
 
struct  TreeLinkOnStack
 Holder of TreeLink on stack for search. More...
 
struct  TreeRecord
 Key and value record structure in the file tree database. More...
 
struct  TreeRecordComparator
 Comparator for TreeRecord objects. More...
 
struct  TreeRecordOnStack
 Holder of TreeRecord on stack for search. More...
 

Typedefs

typedef int32_t(* KeyComparator) (std::string_view, std::string_view)
 Interfrace of comparator of record keys. More...
 

Functions

void Print ()
 Prints an empty string to the stdout and flush the buffer. More...
 
template<typename FIRST , typename... REST>
void Print (const FIRST &first, const REST &... rest)
 Prints strings to the stdout and flush the buffer. More...
 
void PrintL ()
 Prints an empty string and a line feed to the stdout and flush the buffer. More...
 
template<typename FIRST , typename... REST>
void PrintL (const FIRST &first, const REST &... rest)
 Prints strings and a line feed to the stdout and flush the buffer. More...
 
void PrintF (const char *format,...)
 Prints a formatted string to the stdout and flush the buffer. More...
 
void PutChar (char c)
 Prints a character to the stdout and flush the buffer. More...
 
void EPrint ()
 Prints an empty string to the stderr and flush the buffer. More...
 
template<typename FIRST , typename... REST>
void EPrint (const FIRST &first, const REST &... rest)
 Prints strings to the stderr and flush the buffer. More...
 
void EPrintL ()
 Prints an empty string and a line feed to the stderr and flush the buffer. More...
 
template<typename FIRST , typename... REST>
void EPrintL (const FIRST &first, const REST &... rest)
 Prints strings and a line feed to the stderr and flush the buffer. More...
 
void EPrintF (const char *format,...)
 Prints a formatted string to the stderr and flush the buffer. More...
 
void EPutChar (char c)
 Prints a character to the stderr and flush the buffer. More...
 
bool ParseCommandArguments (int32_t argc, const char **argv, const std::map< std::string, int32_t > &configs, std::map< std::string, std::vector< std::string >> *result, std::string *error_message)
 Parses command line arguments. More...
 
std::string GetStringArgument (const std::map< std::string, std::vector< std::string >> &args, const std::string &name, int32_t index, const std::string &default_value)
 Gets a string argument of parsed command arguments. More...
 
int64_t GetIntegerArgument (const std::map< std::string, std::vector< std::string >> &args, const std::string &name, int32_t index, int64_t default_value)
 Gets an integer argument of parsed command arguments. More...
 
double GetDoubleArgument (const std::map< std::string, std::vector< std::string >> &args, const std::string &name, int32_t index, double default_value)
 Gets a real number argument of parsed command arguments. More...
 
std::map< std::string, std::string > GetSystemInfo ()
 Gets system information of the environment. More...
 
void Die (const std::string &message)
 Throws an exception of StatusException to terminates the process with a message. More...
 
template<typename FIRST , typename... REST>
void Die (const FIRST &first, const REST &... rest)
 Throws an exception of StatusException to terminates the process with a message. More...
 
std::unique_ptr< FileMakeFileOrDie (const std::string &impl_name, int64_t alloc_init_size, double alloc_inc_factor)
 Makes a file object or die. More...
 
void SetAccessStrategyOrDie (File *file, int64_t block_size, bool is_direct_io, bool is_sync_io)
 Sets access strategy of the positional access file. More...
 
void LockMemoryOfFileOrDie (File *file, size_t size)
 Locks the memory of the beginning region or die. More...
 
void SetHeadBufferOfFileOrDie (File *file, int64_t size)
 Sets the head buffer of the positional access file. More...
 
void PrintDBMRecordsInTSV (DBM *dbm)
 Prints all records of a DBM in TSV format. More...
 
template<typename C , typename T >
void HeapByCostAdd (const C &cost, const T &payload, size_t capacity, std::vector< std::pair< C, T >> *heap)
 Adds a pair of a cont and a payload to a heap vector. More...
 
template<typename C , typename T >
void HeapByCostFinish (std::vector< std::pair< C, T >> *heap)
 Finishes a heap vector to be in sorted order. More...
 
uint64_t PrimaryHash (std::string_view data, uint64_t num_buckets)
 Primary hash function for the hash database. More...
 
uint64_t SecondaryHash (std::string_view data, uint64_t num_shards)
 Secondary hash function for sharding. More...
 
uint64_t IsPrimeNumber (uint64_t num)
 Returns true if an integer is a prime number. More...
 
int64_t GetHashBucketSize (int64_t min_size)
 Gets a proper bucket size for hashing. More...
 
Status SearchDBM (DBM *dbm, std::string_view pattern, std::vector< std::string > *matched, size_t capacity=0, bool(*matcher)(std::string_view, std::string_view)=StrContains)
 Searches a database and get keys which match a pattern. More...
 
Status SearchDBMForwardMatch (DBM *dbm, std::string_view pattern, std::vector< std::string > *matched, size_t capacity=0)
 Searches a database and get keys which begin with a pattern. More...
 
Status SearchDBMRegex (DBM *dbm, std::string_view pattern, std::vector< std::string > *matched, size_t capacity=0, bool utf=false)
 Searches a database and get keys which match a regular expression. More...
 
Status SearchDBMEditDistance (DBM *dbm, std::string_view pattern, std::vector< std::string > *matched, size_t capacity=0, bool utf=false)
 Searches a database and get keys whose edit distance with a pattern is the least. More...
 
Status ExportDBMRecordsToFlatRecords (DBM *dbm, File *file)
 Exports all records of a database to a flat record file. More...
 
Status ImportDBMRecordsFromFlatRecords (DBM *dbm, File *file)
 Imports records to a database from a flat record file. More...
 
Status ExportDBMKeysToFlatRecords (DBM *dbm, File *file)
 Exports the keys of all records of a database to a flat record file. More...
 
Status ExportDBMRecordsToTSV (DBM *dbm, File *file, bool escape=false)
 Exports all records of a database to a TSV file. More...
 
Status ImportDBMRecordsFromTSV (DBM *dbm, File *file, bool unescape=false)
 Imports records to a database from a TSV file. More...
 
Status ExportDBMKeysAsLines (DBM *dbm, File *file)
 Exports the keys of all records of a database as lines to a text file. More...
 
Status SearchTextFile (File *file, std::string_view pattern, std::vector< std::string > *matched, size_t capacity=0, bool(*matcher)(std::string_view, std::string_view)=StrContains)
 Searches a text file and get lines which match a pattern. More...
 
Status SearchTextFileRegex (File *file, std::string_view pattern, std::vector< std::string > *matched, size_t capacity=0, bool utf=false)
 Searches a text file and get lines which match a regular expression. More...
 
Status SearchTextFileEditDistance (File *file, std::string_view pattern, std::vector< std::string > *matched, size_t capacity=0, bool utf=false)
 Searches a text file and get lines whose edit distance with a pattern is the least. More...
 
TreeRecordCreateTreeRecord (std::string_view key, std::string_view value)
 Creates a tree record. More...
 
TreeRecordModifyTreeRecord (TreeRecord *record, std::string_view new_value)
 Modifies the value of a tree record. More...
 
void FreeTreeRecord (TreeRecord *record)
 Frees the region of a tree record. More...
 
void FreeTreeRecords (std::vector< TreeRecord *> *records)
 Frees the regions of tree records. More...
 
TreeLinkCreateTreeLink (std::string_view key, int64_t child)
 Creates a tree link. More...
 
void FreeTreeLink (TreeLink *link)
 Frees the region of a tree link. More...
 
void FreeTreeLinks (std::vector< TreeLink *> *links)
 Frees the regions of tree links. More...
 
std::string MakeTemporaryName ()
 Makes a unique name for a temporary file. More...
 
std::string JoinPath (const std::string &base_path, const std::string &child_name)
 Joins a base path and a child name. More...
 
std::string NormalizePath (const std::string &path)
 Normalizes a file path. More...
 
std::string PathToBaseName (const std::string &path)
 Gets the base name part of a path. More...
 
std::string PathToDirectoryName (const std::string &path)
 Gets the directory name part of a path. More...
 
std::string PathToExtension (const std::string &path)
 Gets the extention part of a path. More...
 
Status GetRealPath (const std::string &path, std::string *real_path)
 Gets the normalized and canonical form of a path. More...
 
Status ReadFileStatus (const std::string &path, FileStatus *fstats)
 Reads status information of a file. More...
 
bool PathIsFile (const std::string &path)
 Checks if a path indicates a regular file. More...
 
int64_t GetFileSize (const std::string &path)
 Gets the size of a file. More...
 
bool PathIsDirectory (const std::string &path)
 Checks if a path indicates a directory. More...
 
std::string GetPathToTemporaryDirectory ()
 Gets the path to a directory for temporary files. More...
 
Status WriteFile (const std::string &path, std::string_view content)
 Writes a file with a content. More...
 
Status ReadFile (const std::string &path, std::string *content)
 Reads the content from a file. More...
 
std::string ReadFileSimple (const std::string &path, std::string_view default_value="")
 Reads the content from a file, in a simple way. More...
 
Status TruncateFile (const std::string &path, int64_t size)
 Truncates a file. More...
 
Status RemoveFile (const std::string &path)
 Removes a file. More...
 
Status RenameFile (const std::string &src_path, const std::string &dest_path)
 Renames a file. More...
 
Status CopyFileData (const std::string &src_path, const std::string &dest_path)
 Copies the data of a file. More...
 
Status ReadDirectory (const std::string &path, std::vector< std::string > *children)
 Reads a directory. More...
 
Status MakeDirectory (const std::string &path, bool recursive=false)
 Makes a directory. More...
 
Status RemoveDirectory (const std::string &path, bool recursive=false)
 Removes a directory. More...
 
int32_t LexicalKeyComparator (std::string_view a, std::string_view b)
 Key comparator in the lexical order. More...
 
int32_t LexicalCaseKeyComparator (std::string_view a, std::string_view b)
 Key comparator in the lexical order ignoring case. More...
 
int32_t DecimalKeyComparator (std::string_view a, std::string_view b)
 Key comparator in the order of the decimal integer numeric expressions. More...
 
int32_t HexadecimalKeyComparator (std::string_view a, std::string_view b)
 Key comparator in the order of the hexadecimal integer numeric expressions. More...
 
int32_t RealNumberKeyComparator (std::string_view a, std::string_view b)
 Key comparator in the order of the decimal real number expressions. More...
 
int32_t PairLexicalKeyComparator (std::string_view a, std::string_view b)
 Key comparator for serialized pair strings in the lexical order. More...
 
int32_t PairLexicalCaseKeyComparator (std::string_view a, std::string_view b)
 Key comparator for serialized pair strings in the lexical order ignoring case. More...
 
int32_t PairDecimalKeyComparator (std::string_view a, std::string_view b)
 Key comparator for serialized pair strings in the decimal integer order. More...
 
int32_t PairHexadecimalKeyComparator (std::string_view a, std::string_view b)
 Key comparator for serialized pair strings in the hexadecimal integer order. More...
 
int32_t PairRealNumberKeyComparator (std::string_view a, std::string_view b)
 Key comparator for serialized pair strings in the decimal real number order. More...
 
bool operator== (const Status::Code &lhs, const Status &rhs)
 Checks whether a stauts code is equal to another status object. More...
 
bool operator!= (const Status::Code &lhs, const Status &rhs)
 Checks whether a stauts code is not equal to another status object. More...
 
std::string ToString (const Status &status)
 Converts a status into a string. More...
 
std::ostream & operator<< (std::ostream &os, const Status &status)
 Outputs a status string into an output stream. More...
 
void * xmalloc (size_t size)
 Allocates a region on memory. More...
 
void * xcalloc (size_t nmemb, size_t size)
 Allocates a nullified region on memory. More...
 
void * xrealloc (void *ptr, size_t size)
 Re-allocates a region on memory. More...
 
void * xreallocappend (void *ptr, size_t size)
 Re-allocates a region on memory for appending operations. More...
 
void xfree (void *ptr)
 Frees a region on memory. More...
 
void * xmallocaligned (size_t alignment, size_t size)
 Allocates an aligned region on memory. More...
 
void xfreealigned (void *ptr)
 Frees an aligned region on memory. More...
 
template<typename SET >
bool CheckSet (SET set, const typename SET::key_type &elem)
 Checks whether a set has an element. More...
 
template<typename MAP >
bool CheckMap (MAP map, const typename MAP::key_type &key)
 Checks whether a map has a key. More...
 
template<typename MAP >
MAP::value_type::first_type SearchMap (MAP map, const typename MAP::key_type &key, const typename MAP::value_type::second_type &default_value)
 Searches a map and get the value of a record. More...
 
uint64_t HashMurmur (const void *buf, size_t size, uint64_t seed)
 Gets the hash value by Murmur hashing. More...
 
uint64_t HashMurmur (std::string_view str, uint64_t seed)
 Gets the hash value by Murmur hashing. More...
 
uint64_t HashFNV (const void *buf, size_t size)
 Gets the hash value by FNV hashing. More...
 
uint64_t HashFNV (std::string_view str)
 Gets the hash value by FNV hashing. More...
 
uint32_t HashCRC32Continuous (const void *buf, size_t size, bool finish, uint32_t seed=0xFFFFFFFF)
 Gets the hash value by CRC-32, in a continuous way. More...
 
uint32_t HashCRC32 (const void *buf, size_t size)
 Gets the hash value by CRC-32. More...
 
uint32_t HashCRC32 (const std::string &str)
 Gets the hash value by CRC-32. More...
 
uint64_t MakeRandomInt ()
 Makes a random integer from a hidden seed. More...
 
double MakeRandomDouble ()
 Makes a random real number from a hidden seed. More...
 
Status GetErrnoStatus (const char *call_name, int32_t sys_err_num)
 Gets a status according to a system error number of a system call. More...
 
int64_t StrToInt (std::string_view str, int64_t defval=0)
 Converts a decimal string to an integer. More...
 
int64_t StrToIntMetric (std::string_view str, int64_t defval=0)
 Converts a decimal string with a metric prefix to an integer. More...
 
uint64_t StrToIntOct (std::string_view str, uint64_t defval=0)
 Converts a octal string to an integer. More...
 
uint64_t StrToIntHex (std::string_view str, uint64_t defval=0)
 Converts a hexadecimal string to an integer. More...
 
uint64_t StrToIntBigEndian (std::string_view str)
 Converts a big-endian binary string to an integer. More...
 
double StrToDouble (std::string_view str, double defval=0.0)
 Converts a decimal string to a real number. More...
 
bool StrToBool (std::string_view str, bool defval=false)
 Converts a boolean string to a real number. More...
 
void VSPrintF (std::string *dest, const char *format, va_list ap)
 Appends a formatted string at the end of a string. More...
 
void SPrintF (std::string *dest, const char *format,...)
 Appends a formatted string at the end of a string. More...
 
std::string SPrintF (const char *format,...)
 Generates a formatted string. More...
 
template<typename T >
std::string ToString (T data)
 Converts an integer to a decimal string. More...
 
std::string ToString (double data)
 Converts a real number to a decimal string. More...
 
std::string ToString (float data)
 Converts a real number to a decimal string. More...
 
std::string ToString (long double data)
 Converts a real number to a decimal string. More...
 
std::string ToString (bool data)
 Converts a boolean value to a decimal string. More...
 
std::string ToString (char data)
 Converts a character into a string. More...
 
std::string ToString (const char *data)
 Converts a C-style string into a string. More...
 
std::string ToString (std::string_view data)
 Converts a string view into a string. More...
 
std::string ToString (const std::string &data)
 Copies a string. More...
 
std::string IntToStrBigEndian (uint64_t data, size_t size=sizeof(uint64_t))
 Converts an integer into a big-endian binary string. More...
 
template<typename T >
std::string StrJoin (const T &elems, const std::string_view &delim)
 Converts each record of a container into strings and join them. More...
 
std::string StrCat ()
 Returns an empty string. More...
 
template<typename FIRST , typename... REST>
std::string StrCat (const FIRST &first, const REST &... rest)
 Concatenates data of arbitrary parameters into a string. More...
 
std::vector< std::string > StrSplit (std::string_view str, char delim, bool skip_empty=false)
 Splits a string with a delimiter character. More...
 
std::vector< std::string > StrSplit (std::string_view str, std::string_view delim, bool skip_empty=false)
 Splits a string with a delimiter string. More...
 
std::vector< std::string > StrSplitAny (std::string_view str, std::string_view delims, bool skip_empty=false)
 Splits a string with delimiter characters. More...
 
std::map< std::string, std::string > StrSplitIntoMap (std::string_view str, std::string_view delim_records, std::string_view delim_kv)
 Splits a string into a key-value map. More...
 
std::string StrUpperCase (std::string_view str)
 Converts letters of a string into upper case. More...
 
std::string StrLowerCase (std::string_view str)
 Converts letters of a string into lower case. More...
 
std::string StrReplace (std::string_view str, std::string_view before, std::string_view after)
 Converts a string by replacing substrings to diffent substrings. More...
 
bool StrContains (std::string_view text, std::string_view pattern)
 Checks whether a text contains a pattern. More...
 
bool StrBeginsWith (std::string_view text, std::string_view pattern)
 Checks whether a text begins with a pattern. More...
 
bool StrEndsWith (std::string_view text, std::string_view pattern)
 Checks whether a text ends with a pattern. More...
 
int32_t StrCaseCompare (std::string_view a, std::string_view b)
 Compares two strings ignoring case. More...
 
int32_t StrSearch (std::string_view text, std::string_view pattern)
 Searches a text for a pattern, with string::find. More...
 
int32_t StrSearchDoubleLoop (std::string_view text, std::string_view pattern)
 Searches a text for a pattern, by naive double loop. More...
 
int32_t StrSearchMemchr (std::string_view text, std::string_view pattern)
 Searches a text for a pattern, with memchr. More...
 
int32_t StrSearchMemmem (std::string_view text, std::string_view pattern)
 Searches a text for a pattern, with memmem. More...
 
int32_t StrSearchKMP (std::string_view text, std::string_view pattern)
 Searches a text for a pattern, by Knuth–Morris–Pratt algorithm. More...
 
int32_t StrSearchBM (std::string_view text, std::string_view pattern)
 Searches a text for a pattern, by Boyer-Moore algorithm. More...
 
int32_t StrSearchRK (std::string_view text, std::string_view pattern)
 Searches a text for a pattern, by Rabin-Karp algorithm. More...
 
int32_t StrSearchZ (std::string_view text, std::string_view pattern)
 Searches a text for a pattern, by Z algorithm. More...
 
std::vector< int32_t > StrSearchWhole (std::string_view text, std::string_view pattern, size_t max_results=0)
 Searches a text for a pattern and get indices of all occurrences, with string::find. More...
 
std::vector< int32_t > StrSearchWholeKMP (std::string_view text, std::string_view pattern, size_t max_results=0)
 Searches a text for a pattern and get indices of all occurrences, by KMP algorithm. More...
 
std::vector< int32_t > StrSearchWholeBM (std::string_view text, std::string_view pattern, size_t max_results=0)
 Searches a text for a pattern and get indices of all occurrences, by BM algorithm. More...
 
std::vector< int32_t > StrSearchWholeRK (std::string_view text, std::string_view pattern, size_t max_results=0)
 Searches a text for a pattern and get indices of all occurrences, by RK algorithm. More...
 
std::vector< std::vector< int32_t > > StrSearchBatch (std::string_view text, const std::vector< std::string > &patterns, size_t max_results=0)
 Searches a text for patterns and get indices of all occurrences, by string::find. More...
 
std::vector< std::vector< int32_t > > StrSearchBatchKMP (std::string_view text, const std::vector< std::string > &patterns, size_t max_results=0)
 Searches a text for patterns and get indices of all occurrences, by KMP algorithm. More...
 
std::vector< std::vector< int32_t > > StrSearchBatchBM (std::string_view text, const std::vector< std::string > &patterns, size_t max_results=0)
 Searches a text for patterns and get indices of all occurrences, by BM algorithm. More...
 
std::vector< std::vector< int32_t > > StrSearchBatchRK (std::string_view text, const std::vector< std::string > &patterns, size_t max_results=0)
 Searches a text for patterns and get indices of all occurrences, by RK algorithm. More...
 
std::string StrStripSpace (std::string_view str)
 Removes space characters at the head or the tail of a string. More...
 
std::string StrStripLine (std::string_view str)
 Removes linefeed characters from the end of a string. More...
 
std::string StrSqueezeAndStripSpace (std::string_view str)
 Squeezes space characters in a string and removes spaces at both ends. More...
 
std::string StrTrimForTSV (std::string_view str, bool keep_tab=false)
 Trims a string for TSV by normalizing space and control characters. More...
 
std::string StrEscapeC (std::string_view str, bool esc_nonasc=false)
 Escapes C-style meta characters in a string. More...
 
std::string StrUnescapeC (std::string_view str)
 Unescapes C-style escape sequences in a string. More...
 
std::string StrEncodeBase64 (std::string_view str)
 Encodes a string into a Base64 string. More...
 
std::string StrDecodeBase64 (std::string_view str)
 Decodes a Base64 string into a string. More...
 
std::string StrEncodeURL (std::string_view str)
 Encodes a string into a URL part string. More...
 
std::string StrDecodeURL (std::string_view str)
 Decodes a URL part string into a string. More...
 
std::vector< uint32_t > ConvertUTF8ToUCS4 (std::string_view utf)
 Converts a UTF-8 string into a UCS-4 vector. More...
 
std::string ConvertUCS4ToUTF8 (const std::vector< uint32_t > &ucs)
 Converts a UCS-4 vector into a UTF-8 string. More...
 
std::wstring ConvertUTF8ToWide (std::string_view utf)
 Converts a UTF-8 string into a wide string. More...
 
std::string ConvertWideToUTF8 (const std::wstring &wstr)
 Converts a wide string into a UTF-8 string. More...
 
std::string MakeRandomCharacterText (int32_t length, uint8_t first_char, uint8_t last_char)
 Makes a text composed of characters selected at random. More...
 
std::string SerializeStrPair (std::string_view first, std::string_view second)
 Serializes a pair of strings into a string. More...
 
void DeserializeStrPair (std::string_view serialized, std::string_view *first, std::string_view *second)
 Deserializes a serialized string into a pair of strings. More...
 
std::string_view GetFirstFromSerializedStrPair (std::string_view serialized)
 Get the first part from a serialized string pair. More...
 
std::string SerializeStrVector (const std::vector< std::string > &values)
 Serializes a vector of strings into a string. More...
 
std::vector< std::string > DeserializeStrVector (std::string_view serialized)
 Deserializes a serialized string into a string vector. More...
 
std::string SerializeStrMap (const std::map< std::string, std::string > &records)
 Serializes a map of strings into a string. More...
 
std::map< std::string, std::string > DeserializeStrMap (std::string_view serialized)
 Deserializes a serialized string into a string map. More...
 
double GetWallTime ()
 Gets the number of seconds since the UNIX epoch. More...
 
void Sleep (double sec)
 Sleeps the current thread. More...
 

Variables

const char DIR_SEP_CHR
 Directory separator character. More...
 
const char *const DIR_SEP_STR
 Directory separator string. More...
 
const char EXT_SEP_CHR
 Extension separator character. More...
 
const char *const EXT_SEP_STR
 Extension separator string. More...
 
const char *const CURRENT_DIR_NAME
 Current directory name. More...
 
const char *const PARENT_DIR_NAME
 Parent directory name. More...
 
constexpr int8_t INT8MIN = std::numeric_limits<int8_t>::min()
 Disable macros to avoid possible name confliction. More...
 
constexpr int8_t INT8MAX = std::numeric_limits<int8_t>::max()
 The maximum value of int8_t. More...
 
constexpr uint8_t UINT8MAX = std::numeric_limits<uint8_t>::max()
 The maximum value of uint8_t. More...
 
constexpr int16_t INT16MIN = std::numeric_limits<int16_t>::min()
 The minimum value of int16_t. More...
 
constexpr int16_t INT16MAX = std::numeric_limits<int16_t>::max()
 The maximum value of int16_t. More...
 
constexpr uint16_t UINT16MAX = std::numeric_limits<uint16_t>::max()
 The maximum value of uint16_t. More...
 
constexpr int32_t INT32MIN = std::numeric_limits<int32_t>::min()
 The minimum value of int32_t. More...
 
constexpr int32_t INT32MAX = std::numeric_limits<int32_t>::max()
 The maximum value of int32_t. More...
 
constexpr uint32_t UINT32MAX = std::numeric_limits<uint32_t>::max()
 The maximum value of uint32_t. More...
 
constexpr int64_t INT64MIN = std::numeric_limits<int64_t>::min()
 The minimum value of int64_t. More...
 
constexpr int64_t INT64MAX = std::numeric_limits<int64_t>::max()
 The maximum value of int64_t. More...
 
constexpr uint64_t UINT64MAX = std::numeric_limits<uint64_t>::max()
 The maximum value of uint64_t. More...
 
constexpr size_t SIZEMAX = std::numeric_limits<size_t>::max()
 The maximum value of size_t. More...
 
constexpr float FLOATMIN = std::numeric_limits<float>::min()
 The minimum value of float. More...
 
constexpr float FLOATMAX = std::numeric_limits<float>::max()
 The maximum value of float. More...
 
constexpr double DOUBLEMIN = std::numeric_limits<double>::min()
 The minimum value of double. More...
 
constexpr double DOUBLEMAX = std::numeric_limits<double>::max()
 The maximum value of double. More...
 
constexpr double DOUBLENAN = std::numeric_limits<double>::quiet_NaN()
 The quiet Not-a-Number value of double. More...
 
constexpr double DOUBLEINF = std::numeric_limits<double>::infinity()
 The positive infinity value of double. More...
 
constexpr int32_t NUM_BUFFER_SIZE = 32
 The buffer size for a numeric string expression. More...
 
constexpr int64_t MAX_MEMORY_SIZE = (1LL << 40)
 The maximum memory size. More...
 
const int32_t PAGE_SIZE
 The size of a memory page on the OS. More...
 
const char *const PACKAGE_VERSION
 The string expression of the package version. More...
 
const char *const LIBRARY_VERSION
 The string expression of the library version. More...
 
const char *const OS_NAME
 The recognized OS name. More...
 
const bool IS_POSIX
 True if the OS is conforming to POSIX. More...
 
const bool IS_BIG_ENDIAN
 True if the byte order is big endian. More...
 

Detailed Description

Common namespace of Tkrzw.

Typedef Documentation

◆ KeyComparator

typedef int32_t(* tkrzw::KeyComparator) (std::string_view, std::string_view)

Interfrace of comparator of record keys.

The fucntion returns -1 if the first parameter is less, 1 if the first parameter is greater, and 0 if both are equivalent.

Function Documentation

◆ Print() [1/2]

void tkrzw::Print ( )

Prints an empty string to the stdout and flush the buffer.

◆ Print() [2/2]

template<typename FIRST , typename... REST>
void tkrzw::Print ( const FIRST &  first,
const REST &...  rest 
)

Prints strings to the stdout and flush the buffer.

Parameters
firstThe first string.
restThe rest strings.

◆ PrintL() [1/2]

void tkrzw::PrintL ( )

Prints an empty string and a line feed to the stdout and flush the buffer.

◆ PrintL() [2/2]

template<typename FIRST , typename... REST>
void tkrzw::PrintL ( const FIRST &  first,
const REST &...  rest 
)

Prints strings and a line feed to the stdout and flush the buffer.

Parameters
firstThe first string.
restThe rest strings.

◆ PrintF()

void tkrzw::PrintF ( const char *  format,
  ... 
)

Prints a formatted string to the stdout and flush the buffer.

Parameters
formatThe format string.
...The other arguments.

◆ PutChar()

void tkrzw::PutChar ( char  c)

Prints a character to the stdout and flush the buffer.

Parameters
cThe character to print.

◆ EPrint() [1/2]

void tkrzw::EPrint ( )

Prints an empty string to the stderr and flush the buffer.

◆ EPrint() [2/2]

template<typename FIRST , typename... REST>
void tkrzw::EPrint ( const FIRST &  first,
const REST &...  rest 
)

Prints strings to the stderr and flush the buffer.

Parameters
firstThe first string.
restThe rest strings.

◆ EPrintL() [1/2]

void tkrzw::EPrintL ( )

Prints an empty string and a line feed to the stderr and flush the buffer.

◆ EPrintL() [2/2]

template<typename FIRST , typename... REST>
void tkrzw::EPrintL ( const FIRST &  first,
const REST &...  rest 
)

Prints strings and a line feed to the stderr and flush the buffer.

Parameters
firstThe first string.
restThe rest strings.

◆ EPrintF()

void tkrzw::EPrintF ( const char *  format,
  ... 
)

Prints a formatted string to the stderr and flush the buffer.

Parameters
formatThe format string.
...The other arguments.

◆ EPutChar()

void tkrzw::EPutChar ( char  c)

Prints a character to the stderr and flush the buffer.

Parameters
cThe character to print.

◆ ParseCommandArguments()

bool tkrzw::ParseCommandArguments ( int32_t  argc,
const char **  argv,
const std::map< std::string, int32_t > &  configs,
std::map< std::string, std::vector< std::string >> *  result,
std::string *  error_message 
)

Parses command line arguments.

Parameters
argcThe number of input arguments.
argvThe input arguments.
configsA map of option names and numbers of the required arguments. If an empty string represents positional arguments.
resultThe pointer to a map object to contain option names and their arguments.
error_messageThe pointer to a string object to contain the error message.
Returns
True on success or false on failure.

◆ GetStringArgument()

std::string tkrzw::GetStringArgument ( const std::map< std::string, std::vector< std::string >> &  args,
const std::string &  name,
int32_t  index,
const std::string &  default_value 
)

Gets a string argument of parsed command arguments.

Parameters
argsThe parsed command arguments.
nameThe name of the argument.
indexThe index of the value.
default_valueThe value to be returned on failure.
Returns
The value of the matching argument on success, or the default value on failure.

◆ GetIntegerArgument()

int64_t tkrzw::GetIntegerArgument ( const std::map< std::string, std::vector< std::string >> &  args,
const std::string &  name,
int32_t  index,
int64_t  default_value 
)

Gets an integer argument of parsed command arguments.

Parameters
argsThe parsed command arguments.
nameThe name of the argument.
indexThe index of the value.
default_valueThe value to be returned on failure.
Returns
The value of the matching argument on success, or the default value on failure.

◆ GetDoubleArgument()

double tkrzw::GetDoubleArgument ( const std::map< std::string, std::vector< std::string >> &  args,
const std::string &  name,
int32_t  index,
double  default_value 
)

Gets a real number argument of parsed command arguments.

Parameters
argsThe parsed command arguments.
nameThe name of the argument.
indexThe index of the value.
default_valueThe value to be returned on failure.
Returns
The value of the matching argument on success, or the default value on failure.

◆ GetSystemInfo()

std::map<std::string, std::string> tkrzw::GetSystemInfo ( )

Gets system information of the environment.

Returns
A map of labels and their values.

◆ Die() [1/2]

void tkrzw::Die ( const std::string &  message)

Throws an exception of StatusException to terminates the process with a message.

Parameters
messageThe message to print.

◆ Die() [2/2]

template<typename FIRST , typename... REST>
void tkrzw::Die ( const FIRST &  first,
const REST &...  rest 
)

Throws an exception of StatusException to terminates the process with a message.

Parameters
firstThe first parameter.
restThe rest parameters.

◆ MakeFileOrDie()

std::unique_ptr<File> tkrzw::MakeFileOrDie ( const std::string &  impl_name,
int64_t  alloc_init_size,
double  alloc_inc_factor 
)

Makes a file object or die.

Parameters
impl_nameThe name of a File implementation: "mmap-para" for MemoryMapParallelFile, "mmap-atom" for MemoryMapAtomicFile, "pos-para" for PositionalParallelFile. "pos-atom" fo PositionalAtomicFile,
alloc_init_sizeAn initial size of allocation.
alloc_inc_factorA factor to increase the size of allocation.
Returns
The created object.

◆ SetAccessStrategyOrDie()

void tkrzw::SetAccessStrategyOrDie ( File file,
int64_t  block_size,
bool  is_direct_io,
bool  is_sync_io 
)

Sets access strategy of the positional access file.

Parameters
fileThe file object.
block_sizeThe block size to which all records should be aligned.
is_direct_ioIf true, the direct I/O access option is set.
is_sync_ioIf true, the synchronous I/O access option is set.

◆ LockMemoryOfFileOrDie()

void tkrzw::LockMemoryOfFileOrDie ( File file,
size_t  size 
)

Locks the memory of the beginning region or die.

Parameters
fileThe file object.
sizeThe size of the beginning region to lock.

If the operation is not supported, this does nothing.

◆ SetHeadBufferOfFileOrDie()

void tkrzw::SetHeadBufferOfFileOrDie ( File file,
int64_t  size 
)

Sets the head buffer of the positional access file.

Parameters
fileThe file object.
sizeThe size of the head buffer.

◆ PrintDBMRecordsInTSV()

void tkrzw::PrintDBMRecordsInTSV ( DBM dbm)

Prints all records of a DBM in TSV format.

Parameters
dbmThe DBM object.

◆ HeapByCostAdd()

template<typename C , typename T >
void tkrzw::HeapByCostAdd ( const C &  cost,
const T &  payload,
size_t  capacity,
std::vector< std::pair< C, T >> *  heap 
)

Adds a pair of a cont and a payload to a heap vector.

Parameters
costThe cost.
payloadThe payload.
capacityThe capacity of the heap vector.
heapThe pointer to the heap vector.

◆ HeapByCostFinish()

template<typename C , typename T >
void tkrzw::HeapByCostFinish ( std::vector< std::pair< C, T >> *  heap)

Finishes a heap vector to be in sorted order.

Parameters
heapThe heap vector.

◆ PrimaryHash()

uint64_t tkrzw::PrimaryHash ( std::string_view  data,
uint64_t  num_buckets 
)

Primary hash function for the hash database.

Parameters
dataThe data to calculate the hash value for.
num_bucketsThe number of buckets of the hash table.
Returns
The hash value.

◆ SecondaryHash()

uint64_t tkrzw::SecondaryHash ( std::string_view  data,
uint64_t  num_shards 
)

Secondary hash function for sharding.

Parameters
dataThe data to calculate the hash value for.
num_shardsThe number of shards.
Returns
The hash value.

◆ IsPrimeNumber()

uint64_t tkrzw::IsPrimeNumber ( uint64_t  num)

Returns true if an integer is a prime number.

Parameters
numThe integer.
Returns
True if the integer is a prime number.

◆ GetHashBucketSize()

int64_t tkrzw::GetHashBucketSize ( int64_t  min_size)

Gets a proper bucket size for hashing.

Parameters
min_sizeThe minimum size.
Returns
The calculated bucket size.

◆ SearchDBM()

Status tkrzw::SearchDBM ( DBM dbm,
std::string_view  pattern,
std::vector< std::string > *  matched,
size_t  capacity = 0,
bool(*)(std::string_view, std::string_view)  matcher = StrContains 
)

Searches a database and get keys which match a pattern.

Parameters
dbmThe DBM object of the database.
patternThe pattern for matching.
matchedA vector to contain the result.
capacityThe maximum records to obtain. 0 means unlimited.
matcherA matching function which takes the pattern and a candidate.
Returns
The result status.

This scans the whole database so it can take long time.

◆ SearchDBMForwardMatch()

Status tkrzw::SearchDBMForwardMatch ( DBM dbm,
std::string_view  pattern,
std::vector< std::string > *  matched,
size_t  capacity = 0 
)

Searches a database and get keys which begin with a pattern.

Parameters
dbmThe DBM object of the database.
patternThe pattern for forward matching.
matchedA vector to contain the result.
capacityThe maximum records to obtain. 0 means unlimited.
Returns
The result status.

If the database is ordered, an efficient way is used. However, if the key comparator is not LexicalKeyComparator, all matching keys are not extracted. If the database is unordered, this scans the whole database so it can take long time.

◆ SearchDBMRegex()

Status tkrzw::SearchDBMRegex ( DBM dbm,
std::string_view  pattern,
std::vector< std::string > *  matched,
size_t  capacity = 0,
bool  utf = false 
)

Searches a database and get keys which match a regular expression.

Parameters
dbmThe DBM object of the database.
patternThe regular expression pattern for partial matching.
matchedA vector to contain the result.
capacityThe maximum records to obtain. 0 means unlimited.
utfIf true, text is treated as UTF-8 and matching is done with UCS sequences.
Returns
The result status.

This scans the whole database so it can take long time.

◆ SearchDBMEditDistance()

Status tkrzw::SearchDBMEditDistance ( DBM dbm,
std::string_view  pattern,
std::vector< std::string > *  matched,
size_t  capacity = 0,
bool  utf = false 
)

Searches a database and get keys whose edit distance with a pattern is the least.

Parameters
dbmThe DBM object of the database.
patternThe pattern for matching.
matchedA vector to contain the result.
capacityThe maximum records to obtain. 0 means unlimited.
utfIf true, text is treated as UTF-8 and the distance is calculated between UCS sequences.
Returns
The result status.

This scans the whole database so it can take long time.

◆ ExportDBMRecordsToFlatRecords()

Status tkrzw::ExportDBMRecordsToFlatRecords ( DBM dbm,
File file 
)

Exports all records of a database to a flat record file.

Parameters
dbmThe DBM object of the database.
fileThe file object to write records in.
Returns
The result status.

◆ ImportDBMRecordsFromFlatRecords()

Status tkrzw::ImportDBMRecordsFromFlatRecords ( DBM dbm,
File file 
)

Imports records to a database from a flat record file.

Parameters
dbmThe DBM object of the database.
fileThe file object to read records from.
Returns
The result status.

◆ ExportDBMKeysToFlatRecords()

Status tkrzw::ExportDBMKeysToFlatRecords ( DBM dbm,
File file 
)

Exports the keys of all records of a database to a flat record file.

Parameters
dbmThe DBM object of the database.
fileThe file object to write keys in.
Returns
The result status.

◆ ExportDBMRecordsToTSV()

Status tkrzw::ExportDBMRecordsToTSV ( DBM dbm,
File file,
bool  escape = false 
)

Exports all records of a database to a TSV file.

Parameters
dbmThe DBM object of the database.
fileThe file object to write records in.
escapeIf true, C-style escaping is applied to the output.
Returns
The result status.

◆ ImportDBMRecordsFromTSV()

Status tkrzw::ImportDBMRecordsFromTSV ( DBM dbm,
File file,
bool  unescape = false 
)

Imports records to a database from a TSV file.

Parameters
dbmThe DBM object of the database.
fileThe file object to read records from.
unescapeIf true, C-style unescaping is applied to the input.
Returns
The result status.

◆ ExportDBMKeysAsLines()

Status tkrzw::ExportDBMKeysAsLines ( DBM dbm,
File file 
)

Exports the keys of all records of a database as lines to a text file.

Parameters
dbmThe DBM object of the database.
fileThe file object to write keys in.
Returns
The result status.

◆ SearchTextFile()

Status tkrzw::SearchTextFile ( File file,
std::string_view  pattern,
std::vector< std::string > *  matched,
size_t  capacity = 0,
bool(*)(std::string_view, std::string_view)  matcher = StrContains 
)

Searches a text file and get lines which match a pattern.

Parameters
fileThe file to search.
patternThe pattern for matching.
matchedA vector to contain the result.
capacityThe maximum records to obtain. 0 means unlimited.
matcherA matching function which takes the pattern and a candidate.
Returns
The result status.

◆ SearchTextFileRegex()

Status tkrzw::SearchTextFileRegex ( File file,
std::string_view  pattern,
std::vector< std::string > *  matched,
size_t  capacity = 0,
bool  utf = false 
)

Searches a text file and get lines which match a regular expression.

Parameters
fileThe file to search.
patternThe regular expression pattern for partial matching.
matchedA vector to contain the result.
capacityThe maximum records to obtain. 0 means unlimited.
utfIf true, text is decoded as UTF-8 and edit distance is calculated by the unicode characters.
Returns
The result status.

◆ SearchTextFileEditDistance()

Status tkrzw::SearchTextFileEditDistance ( File file,
std::string_view  pattern,
std::vector< std::string > *  matched,
size_t  capacity = 0,
bool  utf = false 
)

Searches a text file and get lines whose edit distance with a pattern is the least.

Parameters
fileThe file to search.
patternThe pattern for matching.
matchedA vector to contain the result.
capacityThe maximum records to obtain. 0 means unlimited.
utfIf true, text is decoded as UTF-8 and edit distance is calculated by the unicode characters.
Returns
The result status.

◆ CreateTreeRecord()

TreeRecord* tkrzw::CreateTreeRecord ( std::string_view  key,
std::string_view  value 
)

Creates a tree record.

Parameters
keyThe key data.
valueThe value data.
Returns
A new record object.

◆ ModifyTreeRecord()

TreeRecord* tkrzw::ModifyTreeRecord ( TreeRecord record,
std::string_view  new_value 
)

Modifies the value of a tree record.

Parameters
recordThe record to modify.
new_valueThe new value data.
Returns
A modified record object, which might be reallocated.

◆ FreeTreeRecord()

void tkrzw::FreeTreeRecord ( TreeRecord record)

Frees the region of a tree record.

Parameters
recordThe record to free.

◆ FreeTreeRecords()

void tkrzw::FreeTreeRecords ( std::vector< TreeRecord *> *  records)

Frees the regions of tree records.

Parameters
recordsA vector of the records to free.

◆ CreateTreeLink()

TreeLink* tkrzw::CreateTreeLink ( std::string_view  key,
int64_t  child 
)

Creates a tree link.

Parameters
keyThe key data.
childThe page ID of the child node.
Returns
A new link object.

◆ FreeTreeLink()

void tkrzw::FreeTreeLink ( TreeLink link)

Frees the region of a tree link.

Parameters
linkThe link to free.

◆ FreeTreeLinks()

void tkrzw::FreeTreeLinks ( std::vector< TreeLink *> *  links)

Frees the regions of tree links.

Parameters
linksA vector of the links to free.

◆ MakeTemporaryName()

std::string tkrzw::MakeTemporaryName ( )

Makes a unique name for a temporary file.

Returns
The unique name.

◆ JoinPath()

std::string tkrzw::JoinPath ( const std::string &  base_path,
const std::string &  child_name 
)

Joins a base path and a child name.

Parameters
base_pathThe base path.
child_nameThe child name.
Returns
The joined path.

◆ NormalizePath()

std::string tkrzw::NormalizePath ( const std::string &  path)

Normalizes a file path.

Parameters
pathThe path to normalize.
Returns
The normalized path.

◆ PathToBaseName()

std::string tkrzw::PathToBaseName ( const std::string &  path)

Gets the base name part of a path.

Parameters
pathThe path.
Returns
The base name part

◆ PathToDirectoryName()

std::string tkrzw::PathToDirectoryName ( const std::string &  path)

Gets the directory name part of a path.

Parameters
pathThe path.
Returns
The directory name part.

◆ PathToExtension()

std::string tkrzw::PathToExtension ( const std::string &  path)

Gets the extention part of a path.

Parameters
pathThe path.
Returns
The extension part or an empty string on failure.

◆ GetRealPath()

Status tkrzw::GetRealPath ( const std::string &  path,
std::string *  real_path 
)

Gets the normalized and canonical form of a path.

Parameters
pathThe path to check.
real_pathThe pointer to a string object to store the content.
Returns
The result status.

◆ ReadFileStatus()

Status tkrzw::ReadFileStatus ( const std::string &  path,
FileStatus fstats 
)

Reads status information of a file.

Parameters
pathThe path to the file.
fstatsThe pointer to a file status object.
Returns
The result status.

◆ PathIsFile()

bool tkrzw::PathIsFile ( const std::string &  path)

Checks if a path indicates a regular file.

Parameters
pathThe path to check.
Returns
True if the path indicates a regular file.

◆ GetFileSize()

int64_t tkrzw::GetFileSize ( const std::string &  path)

Gets the size of a file.

Parameters
pathThe path to the file.
Returns
The file size on success or -1 on failure.

◆ PathIsDirectory()

bool tkrzw::PathIsDirectory ( const std::string &  path)

Checks if a path indicates a directory.

Parameters
pathThe path to check.
Returns
True if the path indicates a directory.

◆ GetPathToTemporaryDirectory()

std::string tkrzw::GetPathToTemporaryDirectory ( )

Gets the path to a directory for temporary files.

Returns
The path of the directory for temporary files.

◆ WriteFile()

Status tkrzw::WriteFile ( const std::string &  path,
std::string_view  content 
)

Writes a file with a content.

Parameters
pathThe path of the file to write.
contentThe content.
Returns
The result status.

◆ ReadFile()

Status tkrzw::ReadFile ( const std::string &  path,
std::string *  content 
)

Reads the content from a file.

Parameters
pathThe path of the file to make.
contentThe pointer to a string object to contain the content.
Returns
The result status.

◆ ReadFileSimple()

std::string tkrzw::ReadFileSimple ( const std::string &  path,
std::string_view  default_value = "" 
)

Reads the content from a file, in a simple way.

Parameters
pathThe path of the file to make.
default_valueThe value to be returned on failure.
Returns
The content of the file on success, or the default value on failure.

◆ TruncateFile()

Status tkrzw::TruncateFile ( const std::string &  path,
int64_t  size 
)

Truncates a file.

Parameters
pathThe path of the file to truncate.
sizeThe new size of the file.
Returns
The result status.

◆ RemoveFile()

Status tkrzw::RemoveFile ( const std::string &  path)

Removes a file.

Parameters
pathThe path of the file.
Returns
The result status.

◆ RenameFile()

Status tkrzw::RenameFile ( const std::string &  src_path,
const std::string &  dest_path 
)

Renames a file.

Parameters
src_pathThe source path of the file.
dest_pathThe destination path of the file.
Returns
The result status.

If there is a file at the destination path, the file is overwritten. This function can rename directories too.

◆ CopyFileData()

Status tkrzw::CopyFileData ( const std::string &  src_path,
const std::string &  dest_path 
)

Copies the data of a file.

Parameters
src_pathThe source path of the file.
dest_pathThe destination path of the file.
Returns
The result status.

◆ ReadDirectory()

Status tkrzw::ReadDirectory ( const std::string &  path,
std::vector< std::string > *  children 
)

Reads a directory.

Parameters
pathThe path of the directory.
childrenA vector object to contain the names of all children.
Returns
The result status.

◆ MakeDirectory()

Status tkrzw::MakeDirectory ( const std::string &  path,
bool  recursive = false 
)

Makes a directory.

Parameters
pathThe path of the directory.
recursiveIf true, parent directories are made recursively.
Returns
The result status.

◆ RemoveDirectory()

Status tkrzw::RemoveDirectory ( const std::string &  path,
bool  recursive = false 
)

Removes a directory.

Parameters
pathThe path of the directory.
recursiveIf true, contents of children are removed recursively.
Returns
The result status.

◆ LexicalKeyComparator()

int32_t tkrzw::LexicalKeyComparator ( std::string_view  a,
std::string_view  b 
)

Key comparator in the lexical order.

Parameters
aOne key.
bThe other key.
Returns
-1 if "a" is less, 1 if "a" is greater, and 0 if both are equivalent.

◆ LexicalCaseKeyComparator()

int32_t tkrzw::LexicalCaseKeyComparator ( std::string_view  a,
std::string_view  b 
)

Key comparator in the lexical order ignoring case.

Parameters
aOne key.
bThe other key.
Returns
-1 if "a" is less, 1 if "a" is greater, and 0 if both are equivalent.

◆ DecimalKeyComparator()

int32_t tkrzw::DecimalKeyComparator ( std::string_view  a,
std::string_view  b 
)

Key comparator in the order of the decimal integer numeric expressions.

Parameters
aOne key.
bThe other key.
Returns
-1 if "a" is less, 1 if "a" is greater, and 0 if both are equivalent.

◆ HexadecimalKeyComparator()

int32_t tkrzw::HexadecimalKeyComparator ( std::string_view  a,
std::string_view  b 
)

Key comparator in the order of the hexadecimal integer numeric expressions.

Parameters
aOne key.
bThe other key.
Returns
-1 if "a" is less, 1 if "a" is greater, and 0 if both are equivalent.

◆ RealNumberKeyComparator()

int32_t tkrzw::RealNumberKeyComparator ( std::string_view  a,
std::string_view  b 
)

Key comparator in the order of the decimal real number expressions.

Parameters
aOne key.
bThe other key.
Returns
-1 if "a" is less, 1 if "a" is greater, and 0 if both are equivalent.

◆ PairLexicalKeyComparator()

int32_t tkrzw::PairLexicalKeyComparator ( std::string_view  a,
std::string_view  b 
)

Key comparator for serialized pair strings in the lexical order.

Parameters
aOne key.
bThe other key.
Returns
-1 if "a" is less, 1 if "a" is greater, and 0 if both are equivalent.

◆ PairLexicalCaseKeyComparator()

int32_t tkrzw::PairLexicalCaseKeyComparator ( std::string_view  a,
std::string_view  b 
)

Key comparator for serialized pair strings in the lexical order ignoring case.

Parameters
aOne key.
bThe other key.
Returns
-1 if "a" is less, 1 if "a" is greater, and 0 if both are equivalent.

◆ PairDecimalKeyComparator()

int32_t tkrzw::PairDecimalKeyComparator ( std::string_view  a,
std::string_view  b 
)

Key comparator for serialized pair strings in the decimal integer order.

Parameters
aOne key.
bThe other key.
Returns
-1 if "a" is less, 1 if "a" is greater, and 0 if both are equivalent.

◆ PairHexadecimalKeyComparator()

int32_t tkrzw::PairHexadecimalKeyComparator ( std::string_view  a,
std::string_view  b 
)

Key comparator for serialized pair strings in the hexadecimal integer order.

Parameters
aOne key.
bThe other key.
Returns
-1 if "a" is less, 1 if "a" is greater, and 0 if both are equivalent.

◆ PairRealNumberKeyComparator()

int32_t tkrzw::PairRealNumberKeyComparator ( std::string_view  a,
std::string_view  b 
)

Key comparator for serialized pair strings in the decimal real number order.

Parameters
aOne key.
bThe other key.
Returns
-1 if "a" is less, 1 if "a" is greater, and 0 if both are equivalent.

◆ operator==()

bool tkrzw::operator== ( const Status::Code lhs,
const Status rhs 
)

Checks whether a stauts code is equal to another status object.

Parameters
lhsThe status code to compare.
rhsThe status object to compare.
Returns
True if The stauts code is equal to the status object.

◆ operator!=()

bool tkrzw::operator!= ( const Status::Code lhs,
const Status rhs 
)

Checks whether a stauts code is not equal to another status object.

Parameters
lhsThe status code to compare.
rhsThe status object to compare.
Returns
True if The stauts code is equal to the status object.

◆ ToString() [1/10]

std::string tkrzw::ToString ( const Status status)

Converts a status into a string.

Parameters
statusThe status object.
Returns
The converted string.

◆ operator<<()

std::ostream& tkrzw::operator<< ( std::ostream &  os,
const Status status 
)

Outputs a status string into an output stream.

Parameters
osThe output stream.
statusThe status.
Returns
The output stream.

◆ xmalloc()

void* tkrzw::xmalloc ( size_t  size)

Allocates a region on memory.

Parameters
sizeThe size of the region.
Returns
The pointer to the allocated region.

◆ xcalloc()

void* tkrzw::xcalloc ( size_t  nmemb,
size_t  size 
)

Allocates a nullified region on memory.

Parameters
nmembThe number of elements.
sizeThe size of each element.
Returns
The pointer to the allocated region.

◆ xrealloc()

void* tkrzw::xrealloc ( void *  ptr,
size_t  size 
)

Re-allocates a region on memory.

Parameters
ptrThe pointer to the region.
sizeThe size of the region.
Returns
The pointer to the re-allocated region.

◆ xreallocappend()

void* tkrzw::xreallocappend ( void *  ptr,
size_t  size 
)

Re-allocates a region on memory for appending operations.

Parameters
ptrThe pointer to the region.
sizeThe size of the region.
Returns
The pointer to the re-allocated region.

◆ xfree()

void tkrzw::xfree ( void *  ptr)

Frees a region on memory.

Parameters
ptrThe pointer to the region.

◆ xmallocaligned()

void* tkrzw::xmallocaligned ( size_t  alignment,
size_t  size 
)

Allocates an aligned region on memory.

Parameters
alignmentThe alignment of the address.
sizeThe size of the region.
Returns
The pointer to the allocated region.

◆ xfreealigned()

void tkrzw::xfreealigned ( void *  ptr)

Frees an aligned region on memory.

Parameters
ptrThe pointer to the region.

◆ CheckSet()

template<typename SET >
bool tkrzw::CheckSet ( SET  set,
const typename SET::key_type &  elem 
)

Checks whether a set has an element.

Parameters
setThe set to search.
elemThe element to search for.
Returns
True if the set has the element.

◆ CheckMap()

template<typename MAP >
bool tkrzw::CheckMap ( MAP  map,
const typename MAP::key_type &  key 
)

Checks whether a map has a key.

Parameters
mapThe map to search.
keyThe key to search for.
Returns
True if the map has the key.

◆ SearchMap()

template<typename MAP >
MAP::value_type::first_type tkrzw::SearchMap ( MAP  map,
const typename MAP::key_type &  key,
const typename MAP::value_type::second_type &  default_value 
)

Searches a map and get the value of a record.

Parameters
mapThe map to search.
keyThe key to search for.
default_valueThe value to be returned on failure.
Returns
The value of the matching record on success, or the default value on failure.

◆ HashMurmur() [1/2]

uint64_t tkrzw::HashMurmur ( const void *  buf,
size_t  size,
uint64_t  seed 
)

Gets the hash value by Murmur hashing.

Parameters
bufThe source buffer.
sizeThe size of the source buffer.
seedThe seed value.
Returns
The hash value.

◆ HashMurmur() [2/2]

uint64_t tkrzw::HashMurmur ( std::string_view  str,
uint64_t  seed 
)

Gets the hash value by Murmur hashing.

See also
HashMurmur

◆ HashFNV() [1/2]

uint64_t tkrzw::HashFNV ( const void *  buf,
size_t  size 
)

Gets the hash value by FNV hashing.

Parameters
bufThe source buffer.
sizeThe size of the source buffer.
Returns
The hash value.

◆ HashFNV() [2/2]

uint64_t tkrzw::HashFNV ( std::string_view  str)

Gets the hash value by FNV hashing.

See also
HashFNV

◆ HashCRC32Continuous()

uint32_t tkrzw::HashCRC32Continuous ( const void *  buf,
size_t  size,
bool  finish,
uint32_t  seed = 0xFFFFFFFF 
)

Gets the hash value by CRC-32, in a continuous way.

Parameters
bufThe source buffer.
sizeThe size of the source buffer.
finishTrue if the cycle is to be finished.
seedA seed value. This should be 0xFFFFFFFF for the frist call of the cycle.
Returns
The hash value.

◆ HashCRC32() [1/2]

uint32_t tkrzw::HashCRC32 ( const void *  buf,
size_t  size 
)

Gets the hash value by CRC-32.

Parameters
bufThe source buffer.
sizeThe size of the source buffer.
Returns
The hash value.

◆ HashCRC32() [2/2]

uint32_t tkrzw::HashCRC32 ( const std::string &  str)

Gets the hash value by CRC-32.

See also
HashCRC32

◆ MakeRandomInt()

uint64_t tkrzw::MakeRandomInt ( )

Makes a random integer from a hidden seed.

Returns
the random integer in a range [0, UINT64MAX] with the inclusive end.

◆ MakeRandomDouble()

double tkrzw::MakeRandomDouble ( )

Makes a random real number from a hidden seed.

Returns
the random real number in a range [0.0, 1.0) with the exclusive end.

◆ GetErrnoStatus()

Status tkrzw::GetErrnoStatus ( const char *  call_name,
int32_t  sys_err_num 
)

Gets a status according to a system error number of a system call.

Parameters
call_nameThe name of the system call.
sys_err_numThe value of "errno".
Returns
The status object.

◆ StrToInt()

int64_t tkrzw::StrToInt ( std::string_view  str,
int64_t  defval = 0 
)

Converts a decimal string to an integer.

Parameters
strThe decimal string.
defvalThe default value to be returned on failure.
Returns
The converted integer.

◆ StrToIntMetric()

int64_t tkrzw::StrToIntMetric ( std::string_view  str,
int64_t  defval = 0 
)

Converts a decimal string with a metric prefix to an integer.

Parameters
strThe decimal string, which can be trailed by a binary metric prefix. "K", "M", "G", "T", "P", and "E" are supported. They are case-insensitive.
defvalThe default value to be returned on failure.
Returns
The converted integer. If the integer overflows the domain, tkrzw::INT64MAX or tkrzw::INT64_MIN is returned according to the sign.

◆ StrToIntOct()

uint64_t tkrzw::StrToIntOct ( std::string_view  str,
uint64_t  defval = 0 
)

Converts a octal string to an integer.

Parameters
strThe octal string.
defvalThe default value to be returned on failure.
Returns
The converted integer.

◆ StrToIntHex()

uint64_t tkrzw::StrToIntHex ( std::string_view  str,
uint64_t  defval = 0 
)

Converts a hexadecimal string to an integer.

Parameters
strThe hexadecimal string.
defvalThe default value to be returned on failure.
Returns
The converted integer.

◆ StrToIntBigEndian()

uint64_t tkrzw::StrToIntBigEndian ( std::string_view  str)

Converts a big-endian binary string to an integer.

Parameters
strThe big endian binary string.
Returns
The converted integer.

◆ StrToDouble()

double tkrzw::StrToDouble ( std::string_view  str,
double  defval = 0.0 
)

Converts a decimal string to a real number.

Parameters
strThe decimal string.
defvalThe default value to be returned on failure.
Returns
The converted real number.

◆ StrToBool()

bool tkrzw::StrToBool ( std::string_view  str,
bool  defval = false 
)

Converts a boolean string to a real number.

Parameters
strThe decimal string.
defvalThe default value to be returned on failure.
Returns
The converted boolean value.

◆ VSPrintF()

void tkrzw::VSPrintF ( std::string *  dest,
const char *  format,
va_list  ap 
)

Appends a formatted string at the end of a string.

Parameters
destThe destination string.
formatThe printf-like format string. The conversion character ‘%’ can be used with such flag characters as ‘s’, ‘d’, ‘o’, ‘u’, ‘x’, ‘X’, ‘c’, ‘e’, ‘E’, ‘f’, ‘g’, ‘G’, and ‘%’.
apArguments used according to the format string.

◆ SPrintF() [1/2]

void tkrzw::SPrintF ( std::string *  dest,
const char *  format,
  ... 
)

Appends a formatted string at the end of a string.

Parameters
destThe destination string.
formatThe printf-like format string. The conversion character ‘%’ can be used with such flag characters as ‘s’, ‘d’, ‘o’, ‘u’, ‘x’, ‘X’, ‘c’, ‘e’, ‘E’, ‘f’, ‘g’, ‘G’, and ‘%’.
...Arguments used according to the format string.

◆ SPrintF() [2/2]

std::string tkrzw::SPrintF ( const char *  format,
  ... 
)

Generates a formatted string.

Parameters
formatThe printf-like format string. The conversion character ‘%’ can be used with such flag characters as ‘s’, ‘d’, ‘o’, ‘u’, ‘x’, ‘X’, ‘c’, ‘e’, ‘E’, ‘f’, ‘g’, ‘G’, and ‘%’.
...Arguments used according to the format string.
Returns
The result string.

◆ ToString() [2/10]

template<typename T >
std::string tkrzw::ToString ( data)

Converts an integer to a decimal string.

Parameters
dataThe integer to convert.
Returns
The converted string.

◆ ToString() [3/10]

std::string tkrzw::ToString ( double  data)

Converts a real number to a decimal string.

Parameters
dataThe real number to convert.
Returns
The converted string.

◆ ToString() [4/10]

std::string tkrzw::ToString ( float  data)

Converts a real number to a decimal string.

Parameters
dataThe real number to convert.
Returns
The converted string.

◆ ToString() [5/10]

std::string tkrzw::ToString ( long double  data)

Converts a real number to a decimal string.

Parameters
dataThe real number to convert.
Returns
The converted string.

◆ ToString() [6/10]

std::string tkrzw::ToString ( bool  data)

Converts a boolean value to a decimal string.

Parameters
dataThe integer to convert.
Returns
The converted string.

◆ ToString() [7/10]

std::string tkrzw::ToString ( char  data)

Converts a character into a string.

Parameters
dataThe character.
Returns
The converted string.

◆ ToString() [8/10]

std::string tkrzw::ToString ( const char *  data)

Converts a C-style string into a string.

Parameters
dataThe C-style string to convert.
Returns
The converted string.

◆ ToString() [9/10]

std::string tkrzw::ToString ( std::string_view  data)

Converts a string view into a string.

Parameters
dataThe string view.
Returns
The converted string.

◆ ToString() [10/10]

std::string tkrzw::ToString ( const std::string &  data)

Copies a string.

Parameters
dataThe string.
Returns
The copied string.

◆ IntToStrBigEndian()

std::string tkrzw::IntToStrBigEndian ( uint64_t  data,
size_t  size = sizeof(uint64_t) 
)

Converts an integer into a big-endian binary string.

Parameters
dataThe integer to convert.
sizeThe size of the converted string.
Returns
The converted string.

◆ StrJoin()

template<typename T >
std::string tkrzw::StrJoin ( const T &  elems,
const std::string_view &  delim 
)

Converts each record of a container into strings and join them.

Parameters
elemsAn iterable container.
delimA string to delimit elements.
Returns
The joined string.

◆ StrCat() [1/2]

std::string tkrzw::StrCat ( )

Returns an empty string.

Returns
The empty string.

◆ StrCat() [2/2]

template<typename FIRST , typename... REST>
std::string tkrzw::StrCat ( const FIRST &  first,
const REST &...  rest 
)

Concatenates data of arbitrary parameters into a string.

Parameters
firstThe first parameter.
restThe rest parameters.
Returns
The concatenated string.

◆ StrSplit() [1/2]

std::vector<std::string> tkrzw::StrSplit ( std::string_view  str,
char  delim,
bool  skip_empty = false 
)

Splits a string with a delimiter character.

Parameters
strThe string.
delimThe delimiter character.
skip_emptyIf true, fields with empty values are skipped.
Returns
A vector object into which the result segments are pushed.

◆ StrSplit() [2/2]

std::vector<std::string> tkrzw::StrSplit ( std::string_view  str,
std::string_view  delim,
bool  skip_empty = false 
)

Splits a string with a delimiter string.

Parameters
strThe string.
delimThe delimiter string. If it is empty, each character is separated.
skip_emptyIf true, fields with empty values are skipped.
Returns
A vector object into which the result segments are pushed.

◆ StrSplitAny()

std::vector<std::string> tkrzw::StrSplitAny ( std::string_view  str,
std::string_view  delims,
bool  skip_empty = false 
)

Splits a string with delimiter characters.

Parameters
strThe string to split.
delimsA string containing a set of the delimiters.
skip_emptyIf true, fields with empty values are skipped.
Returns
A vector object into which the result segments are pushed.

◆ StrSplitIntoMap()

std::map<std::string, std::string> tkrzw::StrSplitIntoMap ( std::string_view  str,
std::string_view  delim_records,
std::string_view  delim_kv 
)

Splits a string into a key-value map.

Parameters
strThe string to split.
delim_recordsThe delimiter string between records.
delim_kvThe delimiter string between the key and the value.
Returns
A map object containing key-value pairs.

◆ StrUpperCase()

std::string tkrzw::StrUpperCase ( std::string_view  str)

Converts letters of a string into upper case.

Parameters
strThe string to convert.
Returns
The converted string.

◆ StrLowerCase()

std::string tkrzw::StrLowerCase ( std::string_view  str)

Converts letters of a string into lower case.

Parameters
strThe string to convert.
Returns
The converted string.

◆ StrReplace()

std::string tkrzw::StrReplace ( std::string_view  str,
std::string_view  before,
std::string_view  after 
)

Converts a string by replacing substrings to diffent substrings.

Parameters
strThe string to convert.
beforeThe substring before replacement.
afterThe substring after replacement.
Returns
The converted string.

◆ StrContains()

bool tkrzw::StrContains ( std::string_view  text,
std::string_view  pattern 
)

Checks whether a text contains a pattern.

Parameters
textThe text to search.
patternThe pattern to search for.
Returns
True if the text contains the pattern.

◆ StrBeginsWith()

bool tkrzw::StrBeginsWith ( std::string_view  text,
std::string_view  pattern 
)

Checks whether a text begins with a pattern.

Parameters
textThe text to search.
patternThe pattern to search for.
Returns
True if the text begins with the pattern.

◆ StrEndsWith()

bool tkrzw::StrEndsWith ( std::string_view  text,
std::string_view  pattern 
)

Checks whether a text ends with a pattern.

Parameters
textThe text to search.
patternThe pattern to search for.
Returns
True if the text ends with the pattern.

◆ StrCaseCompare()

int32_t tkrzw::StrCaseCompare ( std::string_view  a,
std::string_view  b 
)

Compares two strings ignoring case.

Parameters
aA string.
bThe other string.
Returns
Negative if the former is less, 0 if both are equivalent, positive if latter is less.

◆ StrSearch()

int32_t tkrzw::StrSearch ( std::string_view  text,
std::string_view  pattern 
)

Searches a text for a pattern, with string::find.

Parameters
textThe text to search.
patternThe pattern to search for.
Returns
The index of the first matched position, or -1 if there's no matches.

◆ StrSearchDoubleLoop()

int32_t tkrzw::StrSearchDoubleLoop ( std::string_view  text,
std::string_view  pattern 
)

Searches a text for a pattern, by naive double loop.

Parameters
textThe text to search.
patternThe pattern to search for.
Returns
The index of the first matched position, or -1 if there's no matches.

◆ StrSearchMemchr()

int32_t tkrzw::StrSearchMemchr ( std::string_view  text,
std::string_view  pattern 
)

Searches a text for a pattern, with memchr.

Parameters
textThe text to search.
patternThe pattern to search for.
Returns
The index of the first matched position, or -1 if there's no matches.

◆ StrSearchMemmem()

int32_t tkrzw::StrSearchMemmem ( std::string_view  text,
std::string_view  pattern 
)

Searches a text for a pattern, with memmem.

Parameters
textThe text to search.
patternThe pattern to search for.
Returns
The index of the first matched position, or -1 if there's no matches.

◆ StrSearchKMP()

int32_t tkrzw::StrSearchKMP ( std::string_view  text,
std::string_view  pattern 
)

Searches a text for a pattern, by Knuth–Morris–Pratt algorithm.

Parameters
textThe text to search.
patternThe pattern to search for.
Returns
The index of the first matched position, or -1 if there's no matches.

◆ StrSearchBM()

int32_t tkrzw::StrSearchBM ( std::string_view  text,
std::string_view  pattern 
)

Searches a text for a pattern, by Boyer-Moore algorithm.

Parameters
textThe text to search.
patternThe pattern to search for.
Returns
The index of the first matched position, or -1 if there's no matches.

◆ StrSearchRK()

int32_t tkrzw::StrSearchRK ( std::string_view  text,
std::string_view  pattern 
)

Searches a text for a pattern, by Rabin-Karp algorithm.

Parameters
textThe text to search.
patternThe pattern to search for.
Returns
The index of the first matched position, or -1 if there's no matches.

◆ StrSearchZ()

int32_t tkrzw::StrSearchZ ( std::string_view  text,
std::string_view  pattern 
)

Searches a text for a pattern, by Z algorithm.

'

Parameters
textThe text to search.
patternThe pattern to search for.
Returns
The index of the first matched position, or -1 if there's no matches.

◆ StrSearchWhole()

std::vector<int32_t> tkrzw::StrSearchWhole ( std::string_view  text,
std::string_view  pattern,
size_t  max_results = 0 
)

Searches a text for a pattern and get indices of all occurrences, with string::find.

Parameters
textThe text to search.
patternThe pattern to search for.
max_resultsThe maximum number of results to store. 0 means unlimited.
Returns
A vector of indeces of all ocurrences of the pattern.

◆ StrSearchWholeKMP()

std::vector<int32_t> tkrzw::StrSearchWholeKMP ( std::string_view  text,
std::string_view  pattern,
size_t  max_results = 0 
)

Searches a text for a pattern and get indices of all occurrences, by KMP algorithm.

Parameters
textThe text to search.
patternThe pattern to search for.
max_resultsThe maximum number of results to store. 0 means unlimited.
Returns
A vector of indeces of all ocurrences of the pattern.

◆ StrSearchWholeBM()

std::vector<int32_t> tkrzw::StrSearchWholeBM ( std::string_view  text,
std::string_view  pattern,
size_t  max_results = 0 
)

Searches a text for a pattern and get indices of all occurrences, by BM algorithm.

Parameters
textThe text to search.
patternThe pattern to search for.
max_resultsThe maximum number of results to store. 0 means unlimited.
Returns
A vector of indeces of all ocurrences of the pattern.

◆ StrSearchWholeRK()

std::vector<int32_t> tkrzw::StrSearchWholeRK ( std::string_view  text,
std::string_view  pattern,
size_t  max_results = 0 
)

Searches a text for a pattern and get indices of all occurrences, by RK algorithm.

Parameters
textThe text to search.
patternThe pattern to search for.
max_resultsThe maximum number of results to store. 0 means unlimited.
Returns
A vector of indeces of all ocurrences of the pattern.

◆ StrSearchBatch()

std::vector<std::vector<int32_t> > tkrzw::StrSearchBatch ( std::string_view  text,
const std::vector< std::string > &  patterns,
size_t  max_results = 0 
)

Searches a text for patterns and get indices of all occurrences, by string::find.

Parameters
textThe text to search.
patternsThe patterns to search for.
max_resultsThe maximum number of results to store for each pattern. 0 means unlimited.
Returns
A vector of the result for each pattern. Each element is a vector of indices of all occurrences of the pattern.

◆ StrSearchBatchKMP()

std::vector<std::vector<int32_t> > tkrzw::StrSearchBatchKMP ( std::string_view  text,
const std::vector< std::string > &  patterns,
size_t  max_results = 0 
)

Searches a text for patterns and get indices of all occurrences, by KMP algorithm.

Parameters
textThe text to search.
patternsThe patterns to search for.
max_resultsThe maximum number of results to store for each pattern. 0 means unlimited.
Returns
A vector of the result for each pattern. Each element is a vector of indices of all occurrences of the pattern.

◆ StrSearchBatchBM()

std::vector<std::vector<int32_t> > tkrzw::StrSearchBatchBM ( std::string_view  text,
const std::vector< std::string > &  patterns,
size_t  max_results = 0 
)

Searches a text for patterns and get indices of all occurrences, by BM algorithm.

Parameters
textThe text to search.
patternsThe patterns to search for.
max_resultsThe maximum number of results to store for each pattern. 0 means unlimited.
Returns
A vector of the result for each pattern. Each element is a vector of indices of all occurrences of the pattern.

◆ StrSearchBatchRK()

std::vector<std::vector<int32_t> > tkrzw::StrSearchBatchRK ( std::string_view  text,
const std::vector< std::string > &  patterns,
size_t  max_results = 0 
)

Searches a text for patterns and get indices of all occurrences, by RK algorithm.

Parameters
textThe text to search.
patternsThe patterns to search for.
max_resultsThe maximum number of results to store for each pattern. 0 means unlimited.
Returns
A vector of the result for each pattern. Each element is a vector of indices of all occurrences of the pattern.

◆ StrStripSpace()

std::string tkrzw::StrStripSpace ( std::string_view  str)

Removes space characters at the head or the tail of a string.

Parameters
strThe string to convert.
Returns
The converted string.

◆ StrStripLine()

std::string tkrzw::StrStripLine ( std::string_view  str)

Removes linefeed characters from the end of a string.

Parameters
strThe string to convert.
Returns
The converted string.

◆ StrSqueezeAndStripSpace()

std::string tkrzw::StrSqueezeAndStripSpace ( std::string_view  str)

Squeezes space characters in a string and removes spaces at both ends.

Parameters
strThe string to convert.
Returns
The converted string.

◆ StrTrimForTSV()

std::string tkrzw::StrTrimForTSV ( std::string_view  str,
bool  keep_tab = false 
)

Trims a string for TSV by normalizing space and control characters.

Parameters
strThe string to convert.
keep_tabIf true, tab is kept and not escaped.
Returns
The converted string.

◆ StrEscapeC()

std::string tkrzw::StrEscapeC ( std::string_view  str,
bool  esc_nonasc = false 
)

Escapes C-style meta characters in a string.

Parameters
strThe string to convert.
esc_nonascIf true, non-ASCII characters are excaped.
Returns
The converted string.

◆ StrUnescapeC()

std::string tkrzw::StrUnescapeC ( std::string_view  str)

Unescapes C-style escape sequences in a string.

Parameters
strThe string to convert.
Returns
The converted string.

◆ StrEncodeBase64()

std::string tkrzw::StrEncodeBase64 ( std::string_view  str)

Encodes a string into a Base64 string.

Parameters
strThe string to encode.
Returns
The encoded string.

◆ StrDecodeBase64()

std::string tkrzw::StrDecodeBase64 ( std::string_view  str)

Decodes a Base64 string into a string.

Parameters
strThe Base64 string to decode.
Returns
The decoded string.

◆ StrEncodeURL()

std::string tkrzw::StrEncodeURL ( std::string_view  str)

Encodes a string into a URL part string.

Parameters
strThe string to encode.
Returns
The encoded string.

◆ StrDecodeURL()

std::string tkrzw::StrDecodeURL ( std::string_view  str)

Decodes a URL part string into a string.

Parameters
strThe URL part string to decode.
Returns
The decoded string.

◆ ConvertUTF8ToUCS4()

std::vector<uint32_t> tkrzw::ConvertUTF8ToUCS4 ( std::string_view  utf)

Converts a UTF-8 string into a UCS-4 vector.

Parameters
utfThe UTF-8 string.
Returns
The UCS-4 vector.

◆ ConvertUCS4ToUTF8()

std::string tkrzw::ConvertUCS4ToUTF8 ( const std::vector< uint32_t > &  ucs)

Converts a UCS-4 vector into a UTF-8 string.

Parameters
ucsThe UCS-4 vector.
Returns
The UTF-8 string.

◆ ConvertUTF8ToWide()

std::wstring tkrzw::ConvertUTF8ToWide ( std::string_view  utf)

Converts a UTF-8 string into a wide string.

Parameters
utfThe UTF-8 string.
Returns
The wide string.

◆ ConvertWideToUTF8()

std::string tkrzw::ConvertWideToUTF8 ( const std::wstring &  wstr)

Converts a wide string into a UTF-8 string.

Parameters
wstrThe wide string.
Returns
The UTF-8 string.

◆ MakeRandomCharacterText()

std::string tkrzw::MakeRandomCharacterText ( int32_t  length,
uint8_t  first_char,
uint8_t  last_char 
)

Makes a text composed of characters selected at random.

Parameters
lengthLength of the result text.
first_charThe first character of the character range.
last_charThe last character of the character range.
Returns
The result text.

◆ SerializeStrPair()

std::string tkrzw::SerializeStrPair ( std::string_view  first,
std::string_view  second 
)

Serializes a pair of strings into a string.

Parameters
firstThe first string.
secondThe second string.
Returns
The serialized string.

The size of the first value and the size of the second value come in the byte delta encoding. The first data and the second data follow them.

◆ DeserializeStrPair()

void tkrzw::DeserializeStrPair ( std::string_view  serialized,
std::string_view *  first,
std::string_view *  second 
)

Deserializes a serialized string into a pair of strings.

Parameters
serializedThe serialized string.
firstThe pointer to a string view object to refer to the first string.
secondThe pointer to a string view object to refer to the second string.

◆ GetFirstFromSerializedStrPair()

std::string_view tkrzw::GetFirstFromSerializedStrPair ( std::string_view  serialized)

Get the first part from a serialized string pair.

Parameters
serializedThe serialized string.
Returns
The first part string.

◆ SerializeStrVector()

std::string tkrzw::SerializeStrVector ( const std::vector< std::string > &  values)

Serializes a vector of strings into a string.

Parameters
valuesThe string vector.
Returns
The serialized string.

The size of a value comes in the byte delta encoding and the data follows. The pairs for all values come consequitively.

◆ DeserializeStrVector()

std::vector<std::string> tkrzw::DeserializeStrVector ( std::string_view  serialized)

Deserializes a serialized string into a string vector.

Parameters
serializedThe serialized string.
Returns
The result string vector.

◆ SerializeStrMap()

std::string tkrzw::SerializeStrMap ( const std::map< std::string, std::string > &  records)

Serializes a map of strings into a string.

Parameters
recordsThe string map.
Returns
The serialized string.

The size of a kay comes in the byte delta encoding and the data follows. The size of its value comes in the byte delta encoding and the data follows. The tuples for all records come consequitively.

◆ DeserializeStrMap()

std::map<std::string, std::string> tkrzw::DeserializeStrMap ( std::string_view  serialized)

Deserializes a serialized string into a string map.

Parameters
serializedThe serialized string.
Returns
The result string map.

◆ GetWallTime()

double tkrzw::GetWallTime ( )

Gets the number of seconds since the UNIX epoch.

Returns
The number of seconds since the UNIX epoch with microsecond precision.

◆ Sleep()

void tkrzw::Sleep ( double  sec)

Sleeps the current thread.

Parameters
secThe duration in seconds to sleep for.

Variable Documentation

◆ DIR_SEP_CHR

const char tkrzw::DIR_SEP_CHR

Directory separator character.

◆ DIR_SEP_STR

const char* const tkrzw::DIR_SEP_STR

Directory separator string.

◆ EXT_SEP_CHR

const char tkrzw::EXT_SEP_CHR

Extension separator character.

◆ EXT_SEP_STR

const char* const tkrzw::EXT_SEP_STR

Extension separator string.

◆ CURRENT_DIR_NAME

const char* const tkrzw::CURRENT_DIR_NAME

Current directory name.

◆ PARENT_DIR_NAME

const char* const tkrzw::PARENT_DIR_NAME

Parent directory name.

◆ INT8MIN

constexpr int8_t tkrzw::INT8MIN = std::numeric_limits<int8_t>::min()

Disable macros to avoid possible name confliction.

The minimum value of int8_t.

◆ INT8MAX

constexpr int8_t tkrzw::INT8MAX = std::numeric_limits<int8_t>::max()

The maximum value of int8_t.

◆ UINT8MAX

constexpr uint8_t tkrzw::UINT8MAX = std::numeric_limits<uint8_t>::max()

The maximum value of uint8_t.

◆ INT16MIN

constexpr int16_t tkrzw::INT16MIN = std::numeric_limits<int16_t>::min()

The minimum value of int16_t.

◆ INT16MAX

constexpr int16_t tkrzw::INT16MAX = std::numeric_limits<int16_t>::max()

The maximum value of int16_t.

◆ UINT16MAX

constexpr uint16_t tkrzw::UINT16MAX = std::numeric_limits<uint16_t>::max()

The maximum value of uint16_t.

◆ INT32MIN

constexpr int32_t tkrzw::INT32MIN = std::numeric_limits<int32_t>::min()

The minimum value of int32_t.

◆ INT32MAX

constexpr int32_t tkrzw::INT32MAX = std::numeric_limits<int32_t>::max()

The maximum value of int32_t.

◆ UINT32MAX

constexpr uint32_t tkrzw::UINT32MAX = std::numeric_limits<uint32_t>::max()

The maximum value of uint32_t.

◆ INT64MIN

constexpr int64_t tkrzw::INT64MIN = std::numeric_limits<int64_t>::min()

The minimum value of int64_t.

◆ INT64MAX

constexpr int64_t tkrzw::INT64MAX = std::numeric_limits<int64_t>::max()

The maximum value of int64_t.

◆ UINT64MAX

constexpr uint64_t tkrzw::UINT64MAX = std::numeric_limits<uint64_t>::max()

The maximum value of uint64_t.

◆ SIZEMAX

constexpr size_t tkrzw::SIZEMAX = std::numeric_limits<size_t>::max()

The maximum value of size_t.

◆ FLOATMIN

constexpr float tkrzw::FLOATMIN = std::numeric_limits<float>::min()

The minimum value of float.

◆ FLOATMAX

constexpr float tkrzw::FLOATMAX = std::numeric_limits<float>::max()

The maximum value of float.

◆ DOUBLEMIN

constexpr double tkrzw::DOUBLEMIN = std::numeric_limits<double>::min()

The minimum value of double.

◆ DOUBLEMAX

constexpr double tkrzw::DOUBLEMAX = std::numeric_limits<double>::max()

The maximum value of double.

◆ DOUBLENAN

constexpr double tkrzw::DOUBLENAN = std::numeric_limits<double>::quiet_NaN()

The quiet Not-a-Number value of double.

◆ DOUBLEINF

constexpr double tkrzw::DOUBLEINF = std::numeric_limits<double>::infinity()

The positive infinity value of double.

◆ NUM_BUFFER_SIZE

constexpr int32_t tkrzw::NUM_BUFFER_SIZE = 32

The buffer size for a numeric string expression.

◆ MAX_MEMORY_SIZE

constexpr int64_t tkrzw::MAX_MEMORY_SIZE = (1LL << 40)

The maximum memory size.

◆ PAGE_SIZE

const int32_t tkrzw::PAGE_SIZE

The size of a memory page on the OS.

◆ PACKAGE_VERSION

const char* const tkrzw::PACKAGE_VERSION

The string expression of the package version.

◆ LIBRARY_VERSION

const char* const tkrzw::LIBRARY_VERSION

The string expression of the library version.

◆ OS_NAME

const char* const tkrzw::OS_NAME

The recognized OS name.

◆ IS_POSIX

const bool tkrzw::IS_POSIX

True if the OS is conforming to POSIX.

◆ IS_BIG_ENDIAN

const bool tkrzw::IS_BIG_ENDIAN

True if the byte order is big endian.