Kyoto Cabinet

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Classes | Public Member Functions | Static Public Member Functions
kyotocabinet::TinyHashMap Class Reference

Memory-saving string hash map. More...

`#include <kcmap.h>`

List of all members.

## Classes

class | Iterator
| Iterator of records. More...
struct | Record
| Record data.
struct | RecordComparator
| Comparator for records.
class | Sorter
| Sorter of records. More...

## Public Member Functions

| TinyHashMap ()
| Default constructor.
| TinyHashMap (size_t bnum)
| Constructor.
| ~TinyHashMap ()
| Destructor.
void | set (const char *kbuf, size_t ksiz, const char *vbuf, size_t vsiz)
| Set the value of a record.
bool | add (const char *kbuf, size_t ksiz, const char *vbuf, size_t vsiz)
| Add a record.
bool | replace (const char *kbuf, size_t ksiz, const char *vbuf, size_t vsiz)
| Replace the value of a record.
void | append (const char *kbuf, size_t ksiz, const char *vbuf, size_t vsiz)
| Append the value of a record.
bool | remove (const char *kbuf, size_t ksiz)
| Remove a record.
const char * | get (const char *kbuf, size_t ksiz, size_t *sp)
| Retrieve the value of a record.
void | clear ()
| Remove all records.
size_t | count ()
| Get the number of records.

## Static Public Member Functions

static size_t | hash_record (const char *kbuf, size_t ksiz)
| Get the hash value of a record.

## Detailed Description

Memory-saving string hash map.

## Constructor & Destructor Documentation

kyotocabinet::TinyHashMap::TinyHashMap | ( |  | ) | `[explicit]`

Default constructor.

kyotocabinet::TinyHashMap::TinyHashMap | ( | size_t | bnum | ) | `[explicit]`

Constructor.

Parameters:

  bnum | the number of buckets of the hash table.

kyotocabinet::TinyHashMap::~TinyHashMap | ( |  | ) |

Destructor.

## Member Function Documentation

void kyotocabinet::TinyHashMap::set | ( | const char * | kbuf,
|  | size_t | ksiz,
|  | const char * | vbuf,
|  | size_t | vsiz
| ) |  |

Set the value of a record.

Parameters:

  kbuf | the pointer to the key region.
  ksiz | the size of the key region.
  vbuf | the pointer to the value region.
  vsiz | the size of the value region.

Note:
  If no record corresponds to the key, a new record is created. If the corresponding record exists, the value is overwritten.

bool kyotocabinet::TinyHashMap::add | ( | const char * | kbuf,
|  | size_t | ksiz,
|  | const char * | vbuf,
|  | size_t | vsiz
| ) |  |

Add a record.

Parameters:

  kbuf | the pointer to the key region.
  ksiz | the size of the key region.
  vbuf | the pointer to the value region.
  vsiz | the size of the value region.

Returns:
  true on success, or false on failure.

Note:
  If no record corresponds to the key, a new record is created. If the corresponding record exists, the record is not modified and false is returned.

bool kyotocabinet::TinyHashMap::replace | ( | const char * | kbuf,
|  | size_t | ksiz,
|  | const char * | vbuf,
|  | size_t | vsiz
| ) |  |

Replace the value of a record.

Parameters:

  kbuf | the pointer to the key region.
  ksiz | the size of the key region.
  vbuf | the pointer to the value region.
  vsiz | the size of the value region.

Returns:
  true on success, or false on failure.

Note:
  If no record corresponds to the key, no new record is created and false is returned. If the corresponding record exists, the value is modified.

void kyotocabinet::TinyHashMap::append | ( | const char * | kbuf,
|  | size_t | ksiz,
|  | const char * | vbuf,
|  | size_t | vsiz
| ) |  |

Append the value of a record.

Parameters:

  kbuf | the pointer to the key region.
  ksiz | the size of the key region.
  vbuf | the pointer to the value region.
  vsiz | the size of the value region.

Note:
  If no record corresponds to the key, a new record is created. If the corresponding record exists, the given value is appended at the end of the existing value.

bool kyotocabinet::TinyHashMap::remove | ( | const char * | kbuf,
|  | size_t | ksiz
| ) |  |

Remove a record.

Parameters:

  kbuf | the pointer to the key region.
  ksiz | the size of the key region.

Returns:
  true on success, or false on failure.

Note:
  If no record corresponds to the key, false is returned.

const char* kyotocabinet::TinyHashMap::get | ( | const char * | kbuf,
|  | size_t | ksiz,
|  | size_t * | sp
| ) |  |

Retrieve the value of a record.

Parameters:

  kbuf | the pointer to the key region.
  ksiz | the size of the key region.
  sp | the pointer to the variable into which the size of the region of the return value is assigned.

Returns:
  the pointer to the value region of the corresponding record, or NULL on failure.

void kyotocabinet::TinyHashMap::clear | ( |  | ) |

Remove all records.

size_t kyotocabinet::TinyHashMap::count | ( |  | ) |

Get the number of records.

Returns:
  the number of records.

static size_t kyotocabinet::TinyHashMap::hash_record | ( | const char * | kbuf,
|  | size_t | ksiz
| ) |  | `[static]`

Get the hash value of a record.

Parameters:

  kbuf | the pointer to the key region.
  ksiz | the size of the key region.

Returns:
  the hash value.