table of contents
| TCHDB(3) | Tokyo Cabinet | TCHDB(3) | 
NAME¶
tchdb - the hash database APIDESCRIPTION¶
Hash database is a file containing a hash table and is handled with the hash database API. To use the hash database API, include ` tcutil.h', `tchdb.h', and related standard header files. Usually, write the following description near the front of a source file.API¶
The function `tchdberrmsg' is used in order to get the message string corresponding to an error code.`ecode' specifies the error code.
The return value is the message string of the
  error code.
The return value is the new hash database
  object.
`hdb' specifies the hash database
  object.
If the database is not closed, it is closed
  implicitly. Note that the deleted object and its derivatives can not be used
  anymore.
`hdb' specifies the hash database
  object.
The return value is the last happened error
  code.
The following error codes are defined:
  `TCESUCCESS' for success, `TCETHREAD' for threading error, `TCEINVALID' for
  invalid operation, `TCENOFILE' for file not found, `TCENOPERM' for no
  permission, `TCEMETA' for invalid meta data, `TCERHEAD' for invalid record
  header, `TCEOPEN' for open error, `TCECLOSE' for close error, `TCETRUNC' for
  trunc error, `TCESYNC' for sync error, `TCESTAT' for stat error, `TCESEEK' for
  seek error, `TCEREAD' for read error, `TCEWRITE' for write error, `TCEMMAP'
  for mmap error, `TCELOCK' for lock error, `TCEUNLINK' for unlink error,
  `TCERENAME' for rename error, `TCEMKDIR' for mkdir error, `TCERMDIR' for rmdir
  error, `TCEKEEP' for existing record, `TCENOREC' for no record found, and
  `TCEMISC' for miscellaneous error.
`hdb' specifies the hash database
  object which is not opened.
If successful, the return value is true, else,
  it is false.
Note that the mutual exclusion control of the
  database should be set before the database is opened.
`hdb' specifies the hash database
  object which is not opened.
`bnum' specifies the number of elements
  of the bucket array. If it is not more than 0, the default value is specified.
  The default value is 16381. Suggested size of the bucket array is about from
  0.5 to 4 times of the number of all records to be stored.
`apow' specifies the size of record
  alignment by power of 2. If it is negative, the default value is specified.
  The default value is 4 standing for 2^4=16.
`fpow' specifies the maximum number of
  elements of the free block pool by power of 2. If it is negative, the default
  value is specified. The default value is 10 standing for 2^10=1024.
`opts' specifies options by bitwise-or:
  `HDBTLARGE' specifies that the size of the database can be larger than 2GB by
  using 64-bit bucket array, `HDBTDEFLATE' specifies that each record is
  compressed with Deflate encoding, `HDBTBZIP' specifies that each record is
  compressed with BZIP2 encoding, `HDBTTCBS' specifies that each record is
  compressed with TCBS encoding.
If successful, the return value is true, else,
  it is false.
Note that the tuning parameters should be set
  before the database is opened.
`hdb' specifies the hash database
  object which is not opened.
`rcnum' specifies the maximum number of
  records to be cached. If it is not more than 0, the record cache is disabled.
  It is disabled by default.
If successful, the return value is true, else,
  it is false.
Note that the caching parameters should be set
  before the database is opened.
`hdb' specifies the hash database
  object which is not opened.
`xmsiz' specifies the size of the extra
  mapped memory. If it is not more than 0, the extra mapped memory is disabled.
  The default size is 67108864.
If successful, the return value is true, else,
  it is false.
Note that the mapping parameters should be set
  before the database is opened.
`hdb' specifies the hash database
  object which is not opened.
`dfunit' specifie the unit step number.
  If it is not more than 0, the auto defragmentation is disabled. It is disabled
  by default.
If successful, the return value is true, else,
  it is false.
Note that the defragmentation parameters
  should be set before the database is opened.
`hdb' specifies the hash database
  object which is not opened.
`path' specifies the path of the
  database file.
`omode' specifies the connection mode:
  `HDBOWRITER' as a writer, `HDBOREADER' as a reader. If the mode is
  `HDBOWRITER', the following may be added by bitwise-or: `HDBOCREAT', which
  means it creates a new database if not exist, `HDBOTRUNC', which means it
  creates a new database regardless if one exists, `HDBOTSYNC', which means
  every transaction synchronizes updated contents with the device. Both of
  `HDBOREADER' and `HDBOWRITER' can be added to by bitwise-or: `HDBONOLCK',
  which means it opens the database file without file locking, or `HDBOLCKNB',
  which means locking is performed without blocking.
If successful, the return value is true, else,
  it is false.
`hdb' specifies the hash database
  object.
If successful, the return value is true, else,
  it is false.
Update of a database is assured to be written
  when the database is closed. If a writer opens a database but does not close
  it appropriately, the database will be broken.
`hdb' specifies the hash database
  object connected as a writer.
`kbuf' specifies the pointer to the
  region of the key.
`ksiz' specifies the size of the region
  of the key.
`vbuf' specifies the pointer to the
  region of the value.
`vsiz' specifies the size of the region
  of the value.
If successful, the return value is true, else,
  it is false.
If a record with the same key exists in the
  database, it is overwritten.
`hdb' specifies the hash database
  object connected as a writer.
`kstr' specifies the string of the
  key.
`vstr' specifies the string of the
  value.
If successful, the return value is true, else,
  it is false.
If a record with the same key exists in the
  database, it is overwritten.
`hdb' specifies the hash database
  object connected as a writer.
`kbuf' specifies the pointer to the
  region of the key.
`ksiz' specifies the size of the region
  of the key.
`vbuf' specifies the pointer to the
  region of the value.
`vsiz' specifies the size of the region
  of the value.
If successful, the return value is true, else,
  it is false.
If a record with the same key exists in the
  database, this function has no effect.
`hdb' specifies the hash database
  object connected as a writer.
`kstr' specifies the string of the
  key.
`vstr' specifies the string of the
  value.
If successful, the return value is true, else,
  it is false.
If a record with the same key exists in the
  database, this function has no effect.
`hdb' specifies the hash database
  object connected as a writer.
`kbuf' specifies the pointer to the
  region of the key.
`ksiz' specifies the size of the region
  of the key.
`vbuf' specifies the pointer to the
  region of the value.
`vsiz' specifies the size of the region
  of the value.
If successful, the return value is true, else,
  it is false.
If there is no corresponding record, a new
  record is created.
`hdb' specifies the hash database
  object connected as a writer.
`kstr' specifies the string of the
  key.
`vstr' specifies the string of the
  value.
If successful, the return value is true, else,
  it is false.
If there is no corresponding record, a new
  record is created.
`hdb' specifies the hash database
  object connected as a writer.
`kbuf' specifies the pointer to the
  region of the key.
`ksiz' specifies the size of the region
  of the key.
`vbuf' specifies the pointer to the
  region of the value.
`vsiz' specifies the size of the region
  of the value.
If successful, the return value is true, else,
  it is false.
If a record with the same key exists in the
  database, it is overwritten. Records passed to this function are accumulated
  into the inner buffer and wrote into the file at a blast.
`hdb' specifies the hash database
  object connected as a writer.
`kstr' specifies the string of the
  key.
`vstr' specifies the string of the
  value.
If successful, the return value is true, else,
  it is false.
If a record with the same key exists in the
  database, it is overwritten. Records passed to this function are accumulated
  into the inner buffer and wrote into the file at a blast.
`hdb' specifies the hash database
  object connected as a writer.
`kbuf' specifies the pointer to the
  region of the key.
`ksiz' specifies the size of the region
  of the key.
If successful, the return value is true, else,
  it is false.
`hdb' specifies the hash database
  object connected as a writer.
`kstr' specifies the string of the
  key.
If successful, the return value is true, else,
  it is false.
`hdb' specifies the hash database
  object.
`kbuf' specifies the pointer to the
  region of the key.
`ksiz' specifies the size of the region
  of the key.
`sp' specifies the pointer to the
  variable into which the size of the region of the return value is
  assigned.
If successful, the return value is the pointer
  to the region of the value of the corresponding record. `NULL' is returned if
  no record corresponds.
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 `malloc' call, it should be released with the `free' call when it is no
  longer in use.
`hdb' specifies the hash database
  object.
`kstr' specifies the string of the
  key.
If successful, the return value is the string
  of the value of the corresponding record. `NULL' is returned if no record
  corresponds.
Because the region of the return value is
  allocated with the `malloc' call, it should be released with the `free' call
  when it is no longer in use.
`hdb' specifies the hash database
  object.
`kbuf' specifies the pointer to the
  region of the key.
`ksiz' specifies the size of the region
  of the key.
`vbuf' specifies the pointer to the
  buffer into which the value of the corresponding record is written.
`max' specifies the size of the
  buffer.
If successful, the return value is the size of
  the written data, else, it is -1. -1 is returned if no record corresponds to
  the specified key.
Note that an additional zero code is not
  appended at the end of the region of the writing buffer.
`hdb' specifies the hash database
  object.
`kbuf' specifies the pointer to the
  region of the key.
`ksiz' specifies the size of the region
  of the key.
If successful, the return value is the size of
  the value of the corresponding record, else, it is -1.
`hdb' specifies the hash database
  object.
`kstr' specifies the string of the
  key.
If successful, the return value is the size of
  the value of the corresponding record, else, it is -1.
`hdb' specifies the hash database
  object.
If successful, the return value is true, else,
  it is false.
The iterator is used in order to access the
  key of every record stored in a database.
`hdb' specifies the hash database
  object.
`sp' specifies the pointer to the
  variable into which the size of the region of the return value is
  assigned.
If successful, the return value is the pointer
  to the region of the next key, else, it is `NULL'. `NULL' is returned when no
  record is to be get out of the iterator.
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 `malloc' call, it should be released with the `free' call when it is no
  longer in use. It is possible to access every record by iteration of calling
  this function. It is allowed to update or remove records whose keys are
  fetched while the iteration. However, it is not assured if updating the
  database is occurred while the iteration. Besides, the order of this traversal
  access method is arbitrary, so it is not assured that the order of storing
  matches the one of the traversal access.
`hdb' specifies the hash database
  object.
If successful, the return value is the string
  of the next key, else, it is `NULL'. `NULL' is returned when no record is to
  be get out of the iterator.
Because the region of the return value is
  allocated with the `malloc' call, it should be released with the `free' call
  when it is no longer in use. It is possible to access every record by
  iteration of calling this function. However, it is not assured if updating the
  database is occurred while the iteration. Besides, the order of this traversal
  access method is arbitrary, so it is not assured that the order of storing
  matches the one of the traversal access.
`hdb' specifies the hash database
  object.
`kxstr' specifies the object into which
  the next key is wrote down.
`vxstr' specifies the object into which
  the next value is wrote down.
If successful, the return value is true, else,
  it is false. False is returned when no record is to be get out of the
  iterator.
`hdb' specifies the hash database
  object.
`pbuf' specifies the pointer to the
  region of the prefix.
`psiz' specifies the size of the region
  of the prefix.
`max' specifies the maximum number of
  keys to be fetched. If it is negative, no limit is specified.
The return value is a list object of the
  corresponding keys. This function does never fail. It returns an empty list
  even if no key corresponds.
Because the object of the return value is
  created with the function `tclistnew', it should be deleted with the function
  `tclistdel' when it is no longer in use. Note that this function may be very
  slow because every key in the database is scanned.
`hdb' specifies the hash database
  object.
`pstr' specifies the string of the
  prefix.
`max' specifies the maximum number of
  keys to be fetched. If it is negative, no limit is specified.
The return value is a list object of the
  corresponding keys. This function does never fail. It returns an empty list
  even if no key corresponds.
Because the object of the return value is
  created with the function `tclistnew', it should be deleted with the function
  `tclistdel' when it is no longer in use. Note that this function may be very
  slow because every key in the database is scanned.
`hdb' specifies the hash database
  object connected as a writer.
`kbuf' specifies the pointer to the
  region of the key.
`ksiz' specifies the size of the region
  of the key.
`num' specifies the additional
  value.
If successful, the return value is the
  summation value, else, it is `INT_MIN'.
If the corresponding record exists, the value
  is treated as an integer and is added to. If no record corresponds, a new
  record of the additional value is stored.
`hdb' specifies the hash database
  object connected as a writer.
`kbuf' specifies the pointer to the
  region of the key.
`ksiz' specifies the size of the region
  of the key.
`num' specifies the additional
  value.
If successful, the return value is the
  summation value, else, it is Not-a-Number.
If the corresponding record exists, the value
  is treated as a real number and is added to. If no record corresponds, a new
  record of the additional value is stored.
`hdb' specifies the hash database
  object connected as a writer.
If successful, the return value is true, else,
  it is false.
This function is useful when another process
  connects to the same database file.
`hdb' specifies the hash database
  object connected as a writer.
`bnum' specifies the number of elements
  of the bucket array. If it is not more than 0, the default value is specified.
  The default value is two times of the number of records.
`apow' specifies the size of record
  alignment by power of 2. If it is negative, the current setting is not
  changed.
`fpow' specifies the maximum number of
  elements of the free block pool by power of 2. If it is negative, the current
  setting is not changed.
`opts' specifies options by bitwise-or:
  `HDBTLARGE' specifies that the size of the database can be larger than 2GB by
  using 64-bit bucket array, `HDBTDEFLATE' specifies that each record is
  compressed with Deflate encoding, `HDBTBZIP' specifies that each record is
  compressed with BZIP2 encoding, `HDBTTCBS' specifies that each record is
  compressed with TCBS encoding. If it is `UINT8_MAX', the current setting is
  not changed.
If successful, the return value is true, else,
  it is false.
This function is useful to reduce the size of
  the database file with data fragmentation by successive updating.
`hdb' specifies the hash database
  object connected as a writer.
If successful, the return value is true, else,
  it is false.
`hdb' specifies the hash database
  object.
`path' specifies the path of the
  destination file. If it begins with `@', the trailing substring is executed as
  a command line.
If successful, the return value is true, else,
  it is false. False is returned if the executed command returns non-zero
  code.
The database file is assured to be kept
  synchronized and not modified while the copying or executing operation is in
  progress. So, this function is useful to create a backup file of the database
  file.
`hdb' specifies the hash database
  object connected as a writer.
If successful, the return value is true, else,
  it is false.
The database is locked by the thread while the
  transaction so that only one transaction can be activated with a database
  object at the same time. Thus, the serializable isolation level is assumed if
  every database operation is performed in the transaction. All updated regions
  are kept track of by write ahead logging while the transaction. If the
  database is closed during transaction, the transaction is aborted
  implicitly.
`hdb' specifies the hash database
  object connected as a writer.
If successful, the return value is true, else,
  it is false.
Update in the transaction is fixed when it is
  committed successfully.
`hdb' specifies the hash database
  object connected as a writer.
If successful, the return value is true, else,
  it is false.
Update in the transaction is discarded when it
  is aborted. The state of the database is rollbacked to before
  transaction.
`hdb' specifies the hash database
  object.
The return value is the path of the database
  file or `NULL' if the object does not connect to any database file.
`hdb' specifies the hash database
  object.
The return value is the number of records or 0
  if the object does not connect to any database file.
`hdb' specifies the hash database
  object.
The return value is the size of the database
  file or 0 if the object does not connect to any database file.
SEE ALSO¶
tchtest(1), tchmttest(1), tchmgr(1), tokyocabinet(3)| 2011-02-12 | Man Page |