# kyotocabinet Namespace Reference

Helper functions. More...

## Classes

class | CacheDB
| On-memory hash database with LRU deletion. More...
class | Comparator
| Interfrace of comparator of record keys. More...
class | LexicalComparator
| Comparator in the lexical order. More...
class | DecimalComparator
| Comparator in the decimal order. More...
class | Compressor
| Interfrace of data compression and decompression. More...
class | Zlib
| Zlib compressor. More...
class | ZlibRawCompressor
| Compressor with the Zlib raw mode. More...
class | ZlibDeflateCompressor
| Compressor with the Zlib deflate mode. More...
class | ZlibGzipCompressor
| Compressor with the Zlib gzip mode. More...
class | DB
| Interface of database abstraction. More...
class | FileDB
| Basic implementation for file database. More...
class | File
| Filesystem abstraction. More...
class | HashDB
| File hash database. More...
class | LinkedHashMap
| Double linked hash map. More...
class | PolyDB
| Polymorphic database. More...
class | ProtoDB
| Prototype implementation of file database with STL. More...
class | Thread
| Threading device. More...
class | Mutex
| Basic mutual exclusion device. More...
class | ScopedMutex
| Scoped mutex device. More...
class | SlottedMutex
| Slotted mutex device. More...
class | SpinLock
| Lightweight mutual exclusion device. More...
class | ScopedSpinLock
| Scoped spin lock device. More...
class | SlottedSpinLock
| Slotted spin lock devices. More...
class | RWLock
| Reader-writer locking device. More...
class | ScopedRWLock
| Scoped reader-writer locking device. More...
class | SlottedRWLock
| Slotted reader-writer lock devices. More...
class | SpinRWLock
| Lightweight reader-writer locking device. More...
class | ScopedSpinRWLock
| Scoped reader-writer locking device. More...
class | SlottedSpinRWLock
| Slotted lightweight reader-writer lock devices. More...
class | CondVar
| Condition variable. More...
class | TSDKey
| Key of thread specific data. More...
class | TSD
| Smart pointer to thread specific data. More...
class | AtomicInt64
| Integer with atomic operations. More...
class | TreeDB
| File tree database. More...

## Typedefs

typedef ProtoDB< StringHashMap > | ProtoHashDB
| An alias of the prototype hash database.
typedef ProtoDB< StringTreeMap > | ProtoTreeDB
| An alias of the prototype tree database.
typedef std::unordered_map < std::string, std::string > | StringHashMap
| An alias of hash map of strings.
typedef std::map< std::string, std::string > | StringTreeMap
| An alias of tree map of strings.

## Functions

int64_t | atoi (const char *str)
| Convert a string to an integer.
int64_t | atoix (const char *str)
| Convert a string with a metric prefix to an integer.
double | atof (const char *str)
| Convert a string to a real number.
uint16_t | hton16 (uint16_t num)
| Normalize a 16-bit number in the native order into the network byte order.
uint32_t | hton32 (uint32_t num)
| Normalize a 32-bit number in the native order into the network byte order.
uint64_t | hton64 (uint64_t num)
| Normalize a 64-bit number in the native order into the network byte order.
uint16_t | ntoh16 (uint16_t num)
| Denormalize a 16-bit number in the network byte order into the native order.
uint32_t | ntoh32 (uint32_t num)
| Denormalize a 32-bit number in the network byte order into the native order.
uint64_t | ntoh64 (uint64_t num)
| Denormalize a 64-bit number in the network byte order into the native order.
void | writefixnum (void *buf, uint64_t num, size_t width)
| Write a number in fixed length format into a buffer.
uint64_t | readfixnum (const void *buf, size_t width)
| Read a number in fixed length format from a buffer.
size_t | writevarnum (void *buf, uint64_t num)
| Write a number in variable length format into a buffer.
size_t | readvarnum (const void *buf, size_t size, uint64_t *np)
| Read a number in variable length format from a buffer.
uint64_t | hashmurmur (const void *buf, size_t size)
| Get the hash value by MurMur hashing.
uint64_t | hashfnv (const void *buf, size_t size)
| Get the hash value by FNV hashing.
uint64_t | nearbyprime (uint64_t num)
| Get a prime number nearby a number.
double | nan ()
| Get the quiet Not-a-Number value.
double | inf ()
| Get the positive infinity value.
bool | chknan (double num)
| Check a number is a Not-a-Number value.
bool | chkinf (double num)
| Check a number is an infinity value.
void | strprintf (std::string *dest, const char *format, va_list ap)
| Append a formatted string at the end of a string.
void | strprintf (std::string *dest, const char *format,...)
| Append a formatted string at the end of a string.
std::string | strprintf (const char *format,...)
| Generate a formatted string.
size_t | strsplit (const std::string &str, char delim, std::vector< std::string > *elems)
| Split a string with a delimiter.
char * | hexencode (const char *buf, size_t size)
| Encode a serial object with hexadecimal encoding.
char * | hexdecode (const char *str, size_t *sp)
| Decode a string encoded with hexadecimal encoding.
void * | xmalloc (size_t size)
| Allocate a region on memory.
void * | xcalloc (size_t nmemb, size_t size)
| Allocate a nullified region on memory.
void * | xrealloc (void *ptr, size_t size)
| Re-allocate a region on memory.
void | xfree (void *ptr)
| Free a region on memory.
void * | mapalloc (size_t size)
| Allocate a nullified region on mapped memory.
void | mapfree (void *ptr)
| Free a region on mapped memory.
double | time ()
| Get the time of day in seconds.
int64_t | getpid ()
| Get the process ID.
const char * | getenv (const char *name)
| Get the value of an environment variable.

## Variables

LexicalComparator | LEXICALCOMP
| Prepared variable of the comparator in the lexical order.
DecimalComparator | DECIMALCOMP
| Prepared variable of the comparator in the decimal order.
ZlibRawCompressor | ZLIBRAWCOMP
| Prepared variable of the compressor with the Zlib raw mode.
ZlibDeflateCompressor | ZLIBDEFLCOMP
| Prepared variable of the compressor with the Zlib deflate mode.
ZlibGzipCompressor | ZLIBGZIPCOMP
| Prepared variable of the compressor with the Zlib gzip mode.
const char *const | VERSION
| The package version.
const int32_t | LIBVER
| The library version.
const int32_t | LIBREV
| The library revision.
const int32_t | FMTVER
| The database format version.
const char * | SYSNAME
| The system name.
const bool | BIGEND
| The flag for big endian environments.
const int32_t | CLOCKTICK
| The clock tick of interruption.
const int32_t | PAGESIZE
| The size of a page.
const size_t | NUMBUFSIZ = 32
| The buffer size for numeric data.
const size_t | MEMMAXSIZ = INT32_MAX / 2
| The maximum memory size for debugging.

## Detailed Description

Helper functions.

Common namespace of Kyoto Cabinet.

## Typedef Documentation

typedef ProtoDB<StringHashMap> kyotocabinet::ProtoHashDB

An alias of the prototype hash database.

typedef ProtoDB<StringTreeMap> kyotocabinet::ProtoTreeDB

An alias of the prototype tree database.

typedef std::unordered_map<std::string, std::string> kyotocabinet::StringHashMap

An alias of hash map of strings.

typedef std::map<std::string, std::string> kyotocabinet::StringTreeMap

An alias of tree map of strings.

## Function Documentation

int64_t kyotocabinet::atoi | ( | const char * | str | ) |

Convert a string to an integer.

Parameters:

  | str | specifies the string.

Returns:
  the integer. If the string does not contain numeric expression, 0 is returned.

int64_t kyotocabinet::atoix | ( | const char * | str | ) |

Convert a string with a metric prefix to an integer.

Parameters:

  | str | the string, which can be trailed by a binary metric prefix. "K", "M", "G", "T", "P", and "E" are supported. They are case-insensitive.

Returns:
  the integer. If the string does not contain numeric expression, 0 is returned. If the integer overflows the domain, INT64_MAX or INT64_MIN is returned according to the sign.

double kyotocabinet::atof | ( | const char * | str | ) |

Convert a string to a real number.

Parameters:

  | str | specifies the string.

Returns:
  the real number. If the string does not contain numeric expression, 0.0 is returned.

uint16_t kyotocabinet::hton16 | ( | uint16_t | num | ) |

Normalize a 16-bit number in the native order into the network byte order.

Parameters:

  | num | the 16-bit number in the native order.

Returns:
  the number in the network byte order.

uint32_t kyotocabinet::hton32 | ( | uint32_t | num | ) |

Normalize a 32-bit number in the native order into the network byte order.

Parameters:

  | num | the 32-bit number in the native order.

Returns:
  the number in the network byte order.

uint64_t kyotocabinet::hton64 | ( | uint64_t | num | ) |

Normalize a 64-bit number in the native order into the network byte order.

Parameters:

  | num | the 64-bit number in the native order.

Returns:
  the number in the network byte order.

uint16_t kyotocabinet::ntoh16 | ( | uint16_t | num | ) |

Denormalize a 16-bit number in the network byte order into the native order.

Parameters:

  | num | the 16-bit number in the network byte order.

Returns:
  the converted number in the native order.

uint32_t kyotocabinet::ntoh32 | ( | uint32_t | num | ) |

Denormalize a 32-bit number in the network byte order into the native order.

Parameters:

  | num | the 32-bit number in the network byte order.

Returns:
  the converted number in the native order.

uint64_t kyotocabinet::ntoh64 | ( | uint64_t | num | ) |

Denormalize a 64-bit number in the network byte order into the native order.

Parameters:

  | num | the 64-bit number in the network byte order.

Returns:
  the converted number in the native order.

void kyotocabinet::writefixnum | ( | void * | buf,
|  | uint64_t | num,
|  | size_t | width |
| ) |  |  |

Write a number in fixed length format into a buffer.

Parameters:

  | buf | the desitination buffer.
  | num | the number.
  | width | the width.

uint64_t kyotocabinet::readfixnum | ( | const void * | buf,
|  | size_t | width |
| ) |  |  |

Read a number in fixed length format from a buffer.

Parameters:

  | buf | the source buffer.
  | width | the width.

Returns:
  the read number.

size_t kyotocabinet::writevarnum | ( | void * | buf,
|  | uint64_t | num |
| ) |  |  |

Write a number in variable length format into a buffer.

Parameters:

  | buf | the desitination buffer.
  | num | the number.

Returns:
  the length of the written region.

size_t kyotocabinet::readvarnum | ( | const void * | buf,
|  | size_t | size,
|  | uint64_t * | np |
| ) |  |  |

Read a number in variable length format from a buffer.

Parameters:

  | buf | the source buffer.
  | size | the size of the source buffer.
  | np | the pointer to the variable into which the read number is assigned.

Returns:
  the length of the read region, or 0 on failure.

uint64_t kyotocabinet::hashmurmur | ( | const void * | buf,
|  | size_t | size |
| ) |  |  |

Get the hash value by MurMur hashing.

Parameters:

  | buf | the source buffer.
  | size | the size of the source buffer.

Returns:
  the hash value.

uint64_t kyotocabinet::hashfnv | ( | const void * | buf,
|  | size_t | size |
| ) |  |  |

Get the hash value by FNV hashing.

Parameters:

  | buf | the source buffer.
  | size | the size of the source buffer.

Returns:
  the hash value.

uint64_t kyotocabinet::nearbyprime | ( | uint64_t | num | ) |

Get a prime number nearby a number.

Parameters:

  | num | a natural number.

Returns:
  the result number.

double kyotocabinet::nan | ( |  | ) |

Get the quiet Not-a-Number value.

Returns:
  the quiet Not-a-Number value.

double kyotocabinet::inf | ( |  | ) |

Get the positive infinity value.

Returns:
  the positive infinity value.

bool kyotocabinet::chknan | ( | double | num | ) |

Check a number is a Not-a-Number value.

Returns:
  true for the number is a Not-a-Number value, or false if not.

bool kyotocabinet::chkinf | ( | double | num | ) |

Check a number is an infinity value.

Returns:
  true for the number is an infinity value, or false if not.

void kyotocabinet::strprintf | ( | std::string * | dest,
|  | const char * | format,
|  | va_list | ap |
| ) |  |  |

Append a formatted string at the end of a string.

Parameters:

  | dest | the destination string.
  | format | the 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 `'. `S' treats the pointer to a std::string object.
  | ap | used according to the format string.

void kyotocabinet::strprintf | ( | std::string * | dest,
|  | const char * | format,
|  |  | ... |
| ) |  |  |

Append a formatted string at the end of a string.

Parameters:

  | dest | the destination string.
  | format | the 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 `'. `S' treats the pointer to a std::string object.
  | ... | used according to the format string.

std::string kyotocabinet::strprintf | ( | const char * | format,
|  |  | ... |
| ) |  |  |

Generate a formatted string.

Generate a formatted string on memory.

Parameters:

  | format | the 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 `'. `S' treats the pointer to a std::string object.
  | ... | used according to the format string.

Returns:
  the result string.

size_t kyotocabinet::strsplit | ( | const std::string & | str,
|  | char | delim,
|  | std::vector< std::string > * | elems |
| ) |  |  |

Split a string with a delimiter.

Parameters:

  | str | the string.
  | delim | the delimiter.
  | elems | a vector object into which the result elements are pushed.

Returns:
  the number of result elements.

char * kyotocabinet::hexencode | ( | const char * | buf,
|  | size_t | size |
| ) |  |  |

Encode a serial object with hexadecimal encoding.

Parameters:

  | buf | the pointer to the region.
  | size | the size of the region.

Returns:
  the result string.

Note:
  Because the region of the return value is allocated with the the new[] operator, it should be released with the delete[] operator when it is no longer in use.

char * kyotocabinet::hexdecode | ( | const char * | str,
|  | size_t * | sp |
| ) |  |  |

Decode a string encoded with hexadecimal encoding.

Parameters:

  | str | specifies the encoded string.
  | sp | the pointer to the variable into which the size of the region of the return value is assigned.

Returns:
  the pointer to the region of the result.

Note:
  Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the the new[] operator, it should be released with the delete[] operator when it is no longer in use.

void * kyotocabinet::xmalloc | ( | size_t | size | ) |

Allocate a region on memory.

Parameters:

  | size | the size of the region.

Returns:
  the pointer to the allocated region.

void * kyotocabinet::xcalloc | ( | size_t | nmemb,
|  | size_t | size |
| ) |  |  |

Allocate a nullified region on memory.

Parameters:

  | nmemb | the number of elements.
  | size | the size of each element.

Returns:
  the pointer to the allocated region.

void * kyotocabinet::xrealloc | ( | void * | ptr,
|  | size_t | size |
| ) |  |  |

Re-allocate a region on memory.

Parameters:

  | ptr | the pointer to the region.
  | size | the size of the region.

Returns:
  the pointer to the re-allocated region.

void kyotocabinet::xfree | ( | void * | ptr | ) |

Free a region on memory.

Parameters:

  | ptr | the pointer to the region.

void* kyotocabinet::mapalloc | ( | size_t | size | ) |

Allocate a nullified region on mapped memory.

Parameters:

  | size | the size of the region.

Returns:
  the pointer to the allocated region. It should be released with the memfree call.

void kyotocabinet::mapfree | ( | void * | ptr | ) |

Free a region on mapped memory.

Parameters:

  | ptr | the pointer to the allocated region.

double kyotocabinet::time | ( |  | ) |

Get the time of day in seconds.

Returns:
  the time of day in seconds. The accuracy is in microseconds.

int64_t kyotocabinet::getpid | ( |  | ) |

Get the process ID.

Returns:
  the process ID.

const char* kyotocabinet::getenv | ( | const char * | name | ) |

Get the value of an environment variable.

Returns:
  the value of the environment variable, or NULL on failure.

## Variable Documentation

LexicalComparator kyotocabinet::LEXICALCOMP

Prepared variable of the comparator in the lexical order.

DecimalComparator kyotocabinet::DECIMALCOMP

Prepared variable of the comparator in the decimal order.

ZlibRawCompressor kyotocabinet::ZLIBRAWCOMP

Prepared variable of the compressor with the Zlib raw mode.

ZlibDeflateCompressor kyotocabinet::ZLIBDEFLCOMP

Prepared variable of the compressor with the Zlib deflate mode.

ZlibGzipCompressor kyotocabinet::ZLIBGZIPCOMP

Prepared variable of the compressor with the Zlib gzip mode.

const char* const kyotocabinet::VERSION

The package version.

const int32_t kyotocabinet::LIBVER

The library version.

const int32_t kyotocabinet::LIBREV

The library revision.

const int32_t kyotocabinet::FMTVER

The database format version.

const char* kyotocabinet::SYSNAME

The system name.

const bool kyotocabinet::BIGEND

The flag for big endian environments.

const int32_t kyotocabinet::CLOCKTICK

The clock tick of interruption.

const int32_t kyotocabinet::PAGESIZE

The size of a page.

const size_t kyotocabinet::NUMBUFSIZ = 32

The buffer size for numeric data.

const size_t kyotocabinet::MEMMAXSIZ = INT32_MAX / 2

The maximum memory size for debugging.