Module tokyocabinet
The Lua binding of Tokyo Cabinet.
Functions
bdb:adddouble (key, num) | Add a real number to a record. |
bdb:addint (key, num) | Add an integer to a record. |
bdb:close () | Close the database file. |
bdb:copy (path) | Copy the database file. |
bdb:ecode () | Get the last happened error code. |
bdb:errmsg (ecode) | Get the message string corresponding to an error code. |
bdb:foreach (func) | Process each record atomically. |
bdb:fsiz () | Get the size of the database file. |
bdb:fwmkeys (prefix, max) | Get forward matching keys. |
bdb:get (key) | Retrieve a record. |
bdb:getlist (key) | Retrieve records. |
bdb:open (path, omode) | Open a database file. |
bdb:optimize (lmemb, nmemb, bnum, apow, fpow, opts) | Optimize the database file. |
bdb:out (key) | Remove a record. |
bdb:outlist (key) | Remove records. |
bdb:pairs () | Get the iterator for generic "for" loop. |
bdb:path () | Get the path of the database file. |
bdb:put (key, value) | Store a record. |
bdb:putcat (key, value) | Concatenate a value at the end of the existing record. |
bdb:putdup (key, value) | Store a record with allowing duplication of keys. |
bdb:putkeep (key, value) | Store a new record. |
bdb:putlist (key, values) | Store records with allowing duplication of keys. |
bdb:range (bkey, binc, ekey, einc, max) | Get keys of ranged records. |
bdb:rnum () | Get the number of records. |
bdb:setcache (lcnum, ncnum) | Set the caching parameters. |
bdb:setcmpfunc (cmp) | Set the custom comparison function. |
bdb:setxmsiz (xmsiz) | Set the size of the extra mapped memory. |
bdb:sync () | Synchronize updated contents with the file and the device. |
bdb:tranabort () | Abort the transaction. |
bdb:tranbegin () | Begin the transaction. |
bdb:trancommit () | Commit the transaction. |
bdb:tune (lmemb, nmemb, bnum, apow, fpow, opts) | Set the tuning parameters. |
bdb:vanish () | Remove all records. |
bdb:vnum (key) | Get the number of records corresponding a key. |
bdb:vsiz (key) | Get the size of the value of a record. |
bdbcur:first () | Move the cursor to the first record. |
bdbcur:jump (key) | Move the cursor to the front of records corresponding a key. |
bdbcur:key () | Get the key of the record where the cursor is. |
bdbcur:last () | Move the cursor to the last record. |
bdbcur:next () | Move the cursor to the next record. |
bdbcur:out () | Remove the record where the cursor is. |
bdbcur:prev () | Move the cursor to the previous record. |
bdbcur:put (value, cpmode) | Insert a record around the cursor. |
bdbcur:val () | Get the value of the record where the cursor is. |
fdb:adddouble (key, num) | Add a real number to a record. |
fdb:addint (key, num) | Add an integer to a record. |
fdb:close () | Close the database file. |
fdb:copy (path) | Copy the database file. |
fdb:ecode () | Get the last happened error code. |
fdb:errmsg (ecode) | Get the message string corresponding to an error code. |
fdb:foreach (func) | Process each record atomically. |
fdb:fsiz () | Get the size of the database file. |
fdb:get (key) | Retrieve a record. |
fdb:iterinit () | Initialize the iterator. |
fdb:iternext () | Get the next key of the iterator. |
fdb:open (path, omode) | Open a database file. |
fdb:optimize (width, limsiz) | Optimize the database file. |
fdb:out (key) | Remove a record. |
fdb:pairs () | Get the iterator for generic "for" loop. |
fdb:path () | Get the path of the database file. |
fdb:put (key, value) | Store a record. |
fdb:putcat (key, value) | Concatenate a value at the end of the existing record. |
fdb:putkeep (key, value) | Store a new record. |
fdb:range (interval, max) | Get keys with an interval notation. |
fdb:rnum () | Get the number of records. |
fdb:sync () | Synchronize updated contents with the file and the device. |
fdb:tune (width, limsiz) | Set the tuning parameters. |
fdb:vanish () | Remove all records. |
fdb:vsiz (key) | Get the size of the value of a record. |
hdb:adddouble (key, num) | Add a real number to a record. |
hdb:addint (key, num) | Add an integer to a record. |
hdb:close () | Close the database file. |
hdb:copy (path) | Copy the database file. |
hdb:ecode () | Get the last happened error code. |
hdb:errmsg (ecode) | Get the message string corresponding to an error code. |
hdb:foreach (func) | Process each record atomically. |
hdb:fsiz () | Get the size of the database file. |
hdb:fwmkeys (prefix, max) | Get forward matching keys. |
hdb:get (key) | Retrieve a record. |
hdb:iterinit () | Initialize the iterator. |
hdb:iternext () | Get the next key of the iterator. |
hdb:open (path, omode) | Open a database file. |
hdb:optimize (bnum, apow, fpow, opts) | Optimize the database file. |
hdb:out (key) | Remove a record. |
hdb:pairs () | Get the iterator for generic "for" loop. |
hdb:path () | Get the path of the database file. |
hdb:put (key, value) | Store a record. |
hdb:putasync (key, value) | Store a record in asynchronous fashion. |
hdb:putcat (key, value) | Concatenate a value at the end of the existing record. |
hdb:putkeep (key, value) | Store a new record. |
hdb:rnum () | Get the number of records. |
hdb:setcache (rcnum) | Set the caching parameters. |
hdb:setxmsiz (xmsiz) | Set the size of the extra mapped memory. |
hdb:sync () | Synchronize updated contents with the file and the device. |
hdb:tranabort () | Abort the transaction. |
hdb:tranbegin () | Begin the transaction. |
hdb:trancommit () | Commit the transaction. |
hdb:tune (bnum, apow, fpow, opts) | Set the tuning parameters. |
hdb:vanish () | Remove all records. |
hdb:vsiz (key) | Get the size of the value of a record. |
tokyocabinet.bdbcurnew (bdb) | Create a cursor object of a B+ tree database object. |
tokyocabinet.bdbnew () | Create a B+ tree database object. |
tokyocabinet.chdir (path) | Change the current working directory. |
tokyocabinet.codec (mode, str) | Encode or decode a string. |
tokyocabinet.dist (astr, bstr, isutf) | Calculate the edit distance of two UTF-8 strings. |
tokyocabinet.fdbnew () | Create a fixed-length database object. |
tokyocabinet.glob (pattern) | Find pathnames matching a pattern. |
tokyocabinet.hash (mode, str) | Get the hash value of a string. |
tokyocabinet.hdbnew () | Create a hash database object. |
tokyocabinet.isect (ary, ...) | Calculate the intersection set of arrays. |
tokyocabinet.mkdir (path) | Create a directory. |
tokyocabinet.pack (format, ary, ...) | Serialize an array of numbers into a string. |
tokyocabinet.remove (path) | Remove a file or a directory and its sub ones recursively. |
tokyocabinet.sleep (sec) | Suspend execution for the specified interval. |
tokyocabinet.stat (path) | Get the status of a file. |
tokyocabinet.tablenew (anum, rnum) | Create a table with specifying the number of array elements and the number of hash records. |
tokyocabinet.time () | Get the time of day in seconds. |
tokyocabinet.ucs (data) | Convert a UTF-8 string into a UCS-2 array or its inverse. |
tokyocabinet.union (ary, ...) | Calculate the union set of arrays. |
tokyocabinet.unpack (format, str) | Deserialize a binary string into an array of numbers. |
Functions
- bdb:adddouble (key, num)
-
Add a real number to a record. 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.
Parameters
- key: the key.
- num: the additional value.
Return value:
If successful, it is the summation value, else, it is `nil'. - bdb:addint (key, num)
-
Add an integer to a record. 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.
Parameters
- key: the key.
- num: the additional value.
Return value:
If successful, it is the summation value, else, it is `nil'. - bdb:close ()
-
Close the database file. 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.
Return value:
If successful, it is true, else, it is false. - bdb:copy (path)
-
Copy the database file. The database file is assured to be kept synchronized and not modified while the copying or executing operation is in progress. So, this method is useful to create a backup file of the database file.
Parameters
- path: the path of the destination file. If it begins with `@', the trailing substring is executed as a command line.
Return value:
If successful, it is true, else, it is false. False is returned if the executed command returns non-zero code. - bdb:ecode ()
-
Get the last happened error code.
Return value:
the last happened error code. The following error codes are defined: `bdb.ESUCCESS' for success, `bdb.ETHREAD' for threading error, `bdb.EINVALID' for invalid operation, `bdb.ENOFILE' for file not found, `bdb.ENOPERM' for no permission, `bdb.EMETA' for invalid meta data, `bdb.ERHEAD' for invalid record header, `bdb.EOPEN' for open error, `bdb.ECLOSE' for close error, `bdb.ETRUNC' for trunc error, `bdb.ESYNC' for sync error, `bdb.ESTAT' for stat error, `bdb.ESEEK' for seek error, `bdb.EREAD' for read error, `bdb.EWRITE' for write error, `bdb.EMMAP' for mmap error, `bdb.ELOCK' for lock error, `bdb.EUNLINK' for unlink error, `bdb.ERENAME' for rename error, `bdb.EMKDIR' for mkdir error, `bdb.ERMDIR' for rmdir error, `bdb.EKEEP' for existing record, `bdb.ENOREC' for no record found, and `bdb.EMISC' for miscellaneous error. - bdb:errmsg (ecode)
-
Get the message string corresponding to an error code.
Parameters
- ecode: the error code. If it is not defined or negative, the last happened error code is specified.
Return value:
The return value is the message string of the error code. - bdb:foreach (func)
-
Process each record atomically.
Parameters
- func: the iterator function called for each record. It receives two parameters of the key and the value, and returns true to continue iteration or false to stop iteration.
Return value:
If successful, it is true, else, it is false. - bdb:fsiz ()
-
Get the size of the database file.
Return value:
the size of the database file or 0 if the object does not connect to any database file. - bdb:fwmkeys (prefix, max)
-
Get forward matching keys.
Parameters
- prefix: the prefix of the corresponding keys.
- max: the maximum number of keys to be fetched. If it is not defined or negative, no limit is specified.
Return value:
an array of the keys of the corresponding records. This method does never fail and return an empty array even if no record corresponds. - bdb:get (key)
-
Retrieve a record. If the key of duplicated records is specified, the first one is selected.
Parameters
- key: the key.
Return value:
If successful, it is the value of the corresponding record. `nil' is returned if no record corresponds. - bdb:getlist (key)
-
Retrieve records.
Parameters
- key: the key.
Return value:
If successful, it is an array of the values of the corresponding records. `nil' is returned if no record corresponds. - bdb:open (path, omode)
-
Open a database file.
Parameters
- path: the path of the database file.
- omode: the connection mode: `bdb.OWRITER' as a writer, `bdb.OREADER' as a reader. If the mode is `bdb.OWRITER', the following may be added by bitwise or: `bdb.OCREAT', which means it creates a new database if not exist, `bdb.OTRUNC', which means it creates a new database regardless if one exists, `bdb.OTSYNC', which means every transaction synchronizes updated contents with the device. Both of `bdb.OREADER' and `bdb.OWRITER' can be added to by bitwise or: `bdb.ONOLCK', which means it opens the database file without file locking, or `bdb.OLCKNB', which means locking is performed without blocking. If it is not defined or `bdb.OREADER' is specified.
Return value:
If successful, it is true, else, it is false. - bdb:optimize (lmemb, nmemb, bnum, apow, fpow, opts)
-
Optimize the database file. This method is useful to reduce the size of the database file with data fragmentation by successive updating.
Parameters
- lmemb: the number of members in each leaf page. If it is not defined or not more than 0, the current setting is not changed.
- nmemb: the number of members in each non-leaf page. If it is not defined or not more than 0, the current setting is not changed.
- bnum: the number of elements of the bucket array. If it is not defined or not more than 0, the default value is specified. The default value is two times of the number of pages.
- apow: the size of record alignment by power of 2. If it is not defined or negative, the current setting is not changed.
- fpow: the maximum number of elements of the free block pool by power of 2. If it is not defined or negative, the current setting is not changed.
- opts: options by bitwise or: `bdb.TLARGE' specifies that the size of the database can be larger than 2GB by using 64-bit bucket array, `bdb.TDEFLATE' specifies that each record is compressed with Deflate encoding, `bdb.TBZIP' specifies that each record is compressed with BZIP2 encoding, `bdb.TTCBS' specifies that each record is compressed with TCBS encoding. If it is not defined or 0xff, the current setting is not changed.
Return value:
If successful, it is true, else, it is false. - bdb:out (key)
-
Remove a record. If the key of duplicated records is specified, the first one is selected.
Parameters
- key: the key.
Return value:
If successful, it is true, else, it is false. - bdb:outlist (key)
-
Remove records. If the key of duplicated records is specified, all of them are removed.
Parameters
- key: the key.
Return value:
If successful, it is true, else, it is false. - bdb:pairs ()
-
Get the iterator for generic "for" loop.
Return value:
plural values; the iterator to retrieve the key and the value of the next record, the cursor for iteration, and nil. - bdb:path ()
-
Get the path of the database file.
Return value:
the path of the database file or `nil' if the object does not connect to any database file. - bdb:put (key, value)
-
Store a record. If a record with the same key exists in the database, it is overwritten.
Parameters
- key: the key.
- value: the value.
Return value:
If successful, it is true, else, it is false. - bdb:putcat (key, value)
-
Concatenate a value at the end of the existing record. If there is no corresponding record, a new record is created.
Parameters
- key: the key.
- value: the value.
Return value:
If successful, it is true, else, it is false. - bdb:putdup (key, value)
-
Store a record with allowing duplication of keys. If a record with the same key exists in the database, the new record is placed after the existing one.
Parameters
- key: the key.
- value: the value.
Return value:
If successful, it is true, else, it is false. - bdb:putkeep (key, value)
-
Store a new record. If a record with the same key exists in the database, this method has no effect.
Parameters
- key: the key.
- value: the value.
Return value:
If successful, it is true, else, it is false. - bdb:putlist (key, values)
-
Store records with allowing duplication of keys. If a record with the same key exists in the database, the new records are placed after the existing one.
Parameters
- key: the key.
- values: an array of the values.
Return value:
If successful, it is true, else, it is false. - bdb:range (bkey, binc, ekey, einc, max)
-
Get keys of ranged records.
Parameters
- bkey: the key of the beginning border. If it is not defined, the first record is specified.
- binc: whether the beginning border is inclusive or not. If it is not defined, false is specified.
- ekey: the key of the ending border. If it is not defined, the last record is specified.
- einc: whether the ending border is inclusive or not. If it is not defined, false is specified.
- max: the maximum number of keys to be fetched. If it is not defined or negative, no limit is specified.
Return value:
an array of the keys of the corresponding records. This method does never fail and return an empty array even if no record corresponds. - bdb:rnum ()
-
Get the number of records.
Return value:
the number of records or 0 if the object does not connect to any database file. - bdb:setcache (lcnum, ncnum)
-
Set the caching parameters. The tuning parameters of the database should be set before the database is opened.
Parameters
- lcnum: the maximum number of leaf nodes to be cached. If it is not defined or not more than 0, the default value is specified. The default value is 1024.
- ncnum: the maximum number of non-leaf nodes to be cached. If it is not defined or not more than 0, the default value is specified. The default value is 512.
Return value:
If successful, it is true, else, it is false. - bdb:setcmpfunc (cmp)
-
Set the custom comparison function. The default comparison function compares keys of two records by lexical order. The constants `bdb.CMPLEXICAL' (dafault), `bdb.CMPDECIMAL', `bdb.CMPINT32', and `bdb.CMPINT64' are built-in. Note that the comparison function should be set before the database is opened. Moreover, user-defined comparison functions should be set every time the database is being opened.
Parameters
- cmp: the custom comparison function.
Return value:
If successful, the return value is true, else, it is false. - bdb:setxmsiz (xmsiz)
-
Set the size of the extra mapped memory. The mapping parameters should be set before the database is opened.
Parameters
- xmsiz: the size of the extra mapped memory. If it is not defined or not more than 0, the extra mapped memory is disabled. It is disabled by default.
Return value:
If successful, the return value is true, else, it is false. - bdb:sync ()
-
Synchronize updated contents with the file and the device. This method is useful when another process connects the same database file.
Return value:
If successful, it is true, else, it is false. - bdb:tranabort ()
-
Abort the transaction. Update in the transaction is discarded when it is aborted. The state of the database is rollbacked to before transaction.
Return value:
If successful, it is true, else, it is false. - bdb:tranbegin ()
-
Begin the transaction. 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. Because all pages are cached on memory while the transaction, the amount of referred records is limited by the memory capacity. If the database is closed during transaction, the transaction is aborted implicitly.
Return value:
If successful, it is true, else, it is false. - bdb:trancommit ()
-
Commit the transaction. Update in the transaction is fixed when it is committed successfully.
Return value:
If successful, it is true, else, it is false. - bdb:tune (lmemb, nmemb, bnum, apow, fpow, opts)
-
Set the tuning parameters. The tuning parameters of the database should be set before the database is opened.
Parameters
- lmemb: the number of members in each leaf page. If it is not defined or not more than 0, the default value is specified. The default value is 128.
- nmemb: the number of members in each non-leaf page. If it is not defined or not more than 0, the default value is specified. The default value is 256.
- bnum: the number of elements of the bucket array. If it is not defined or not more than 0, the default value is specified. The default value is 32749. Suggested size of the bucket array is about from 1 to 4 times of the number of all pages to be stored.
- apow: the size of record alignment by power of 2. If it is not defined or negative, the default value is specified. The default value is 4 standing for 2^4=16.
- fpow: the maximum number of elements of the free block pool by power of 2. If it is not defined or negative, the default value is specified. The default value is 10 standing for 2^10=1024.
- opts: options by bitwise or: `bdb.TLARGE' specifies that the size of the database can be larger than 2GB by using 64-bit bucket array, `bdb.TDEFLATE' specifies that each record is compressed with Deflate encoding, `bdb.TBZIP' specifies that each record is compressed with BZIP2 encoding, `bdb.TTCBS' specifies that each record is compressed with TCBS encoding. If it is not defined, no option is specified.
Return value:
If successful, it is true, else, it is false. - bdb:vanish ()
-
Remove all records.
Return value:
If successful, it is true, else, it is false. - bdb:vnum (key)
-
Get the number of records corresponding a key.
Parameters
- key: the key.
Return value:
If successful, it is the number of the corresponding records, else, it is 0. - bdb:vsiz (key)
-
Get the size of the value of a record. If the key of duplicated records is specified, the first one is selected.
Parameters
- key: the key.
Return value:
If successful, it is the size of the value of the corresponding record, else, it is -1. - bdbcur:first ()
-
Move the cursor to the first record.
Return value:
If successful, it is true, else, it is false. False is returned if there is no record in the database. - bdbcur:jump (key)
-
Move the cursor to the front of records corresponding a key. The cursor is set to the first record corresponding the key or the next substitute if completely matching record does not exist.
Parameters
- key: the key.
Return value:
If successful, it is true, else, it is false. False is returned if there is no record corresponding the condition. - bdbcur:key ()
-
Get the key of the record where the cursor is.
Return value:
If successful, it is the key, else, it is `null'. 'null' is returned when the cursor is at invalid position. - bdbcur:last ()
-
Move the cursor to the last record.
Return value:
If successful, it is true, else, it is false. False is returned if there is no record in the database. - bdbcur:next ()
-
Move the cursor to the next record.
Return value:
If successful, it is true, else, it is false. False is returned if there is no next record. - bdbcur:out ()
-
Remove the record where the cursor is. After deletion, the cursor is moved to the next record if possible.
Return value:
If successful, it is true, else, it is false. False is returned when the cursor is at invalid position. - bdbcur:prev ()
-
Move the cursor to the previous record.
Return value:
If successful, it is true, else, it is false. False is returned if there is no previous record. - bdbcur:put (value, cpmode)
-
Insert a record around the cursor. After insertion, the cursor is moved to the inserted record.
Parameters
- value: the value.
- cpmode: detail adjustment: `bdbcur.CPCURRENT', which means that the value of the current record is overwritten, `bdbcur.CPBEFORE', which means that the new record is inserted before the current record, `bdbcur.CPAFTER', which means that the new record is inserted after the current record.
Return value:
If successful, it is true, else, it is false. False is returned when the cursor is at invalid position. - bdbcur:val ()
-
Get the value of the record where the cursor is.
Return value:
If successful, it is the value, else, it is `null'. 'null' is returned when the cursor is at invalid position. - fdb:adddouble (key, num)
-
Add a real number to a record. 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.
Parameters
- key: the key. It should be more than 0. If it is "min", the minimum ID number of existing records is specified. If it is "prev", the number less by one than the minimum ID number of existing records is specified. If it is "max", the maximum ID number of existing records is specified. If it is "next", the number greater by one than the maximum ID number of existing records is specified.
- num: the additional value.
Return value:
If successful, it is the summation value, else, it is `nil'. - fdb:addint (key, num)
-
Add an integer to a record. 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.
Parameters
- key: the key. It should be more than 0. If it is "min", the minimum ID number of existing records is specified. If it is "prev", the number less by one than the minimum ID number of existing records is specified. If it is "max", the maximum ID number of existing records is specified. If it is "next", the number greater by one than the maximum ID number of existing records is specified.
- num: the additional value.
Return value:
If successful, it is the summation value, else, it is `nil'. - fdb:close ()
-
Close the database file. 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.
Return value:
If successful, it is true, else, it is false. - fdb:copy (path)
-
Copy the database file. The database file is assured to be kept synchronized and not modified while the copying or executing operation is in progress. So, this method is useful to create a backup file of the database file.
Parameters
- path: the path of the destination file. If it begins with `@', the trailing substring is executed as a command line.
Return value:
If successful, it is true, else, it is false. False is returned if the executed command returns non-zero code. - fdb:ecode ()
-
Get the last happened error code.
Return value:
the last happened error code. The following error codes are defined: `fdb.ESUCCESS' for success, `fdb.ETHREAD' for threading error, `fdb.EINVALID' for invalid operation, `fdb.ENOFILE' for file not found, `fdb.ENOPERM' for no permission, `fdb.EMETA' for invalid meta data, `fdb.ERHEAD' for invalid record header, `fdb.EOPEN' for open error, `fdb.ECLOSE' for close error, `fdb.ETRUNC' for trunc error, `fdb.ESYNC' for sync error, `fdb.ESTAT' for stat error, `fdb.ESEEK' for seek error, `fdb.EREAD' for read error, `fdb.EWRITE' for write error, `fdb.EMMAP' for mmap error, `fdb.ELOCK' for lock error, `fdb.EUNLINK' for unlink error, `fdb.ERENAME' for rename error, `fdb.EMKDIR' for mkdir error, `fdb.ERMDIR' for rmdir error, `fdb.EKEEP' for existing record, `fdb.ENOREC' for no record found, and `fdb.EMISC' for miscellaneous error. - fdb:errmsg (ecode)
-
Get the message string corresponding to an error code.
Parameters
- ecode: the error code. If it is not defined or negative, the last happened error code is specified.
Return value:
The return value is the message string of the error code. - fdb:foreach (func)
-
Process each record atomically.
Parameters
- func: the iterator function called for each record. It receives two parameters of the key and the value, and returns true to continue iteration or false to stop iteration.
Return value:
If successful, it is true, else, it is false. - fdb:fsiz ()
-
Get the size of the database file.
Return value:
the size of the database file or 0 if the object does not connect to any database file. - fdb:get (key)
-
Retrieve a record.
Parameters
- key: the key. It should be more than 0. If it is "min", the minimum ID number of existing records is specified. If it is "max", the maximum ID number of existing records is specified.
Return value:
If successful, it is the value of the corresponding record. `nil' is returned if no record corresponds. - fdb:iterinit ()
-
Initialize the iterator. The iterator is used in order to access the key of every record stored in a database.
Return value:
If successful, it is true, else, it is false. - fdb:iternext ()
-
Get the next key of the iterator. 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. The order of this traversal access method is ascending of the ID number.
Return value:
If successful, it is the next key, else, it is `nil'. `nil' is returned when no record is to be get out of the iterator. - fdb:open (path, omode)
-
Open a database file.
Parameters
- path: the path of the database file.
- omode: the connection mode: `fdb.OWRITER' as a writer, `fdb.OREADER' as a reader. If the mode is `fdb.OWRITER', the following may be added by bitwise or: `fdb.OCREAT', which means it creates a new database if not exist, `fdb.OTRUNC', which means it creates a new database regardless if one exists. Both of `fdb.OREADER' and `fdb.OWRITER' can be added to by bitwise or: `fdb.ONOLCK', which means it opens the database file without file locking, or `fdb.OLCKNB', which means locking is performed without blocking. If it is not defined, `bdb.OREADER' is specified.
Return value:
If successful, it is true, else, it is false. - fdb:optimize (width, limsiz)
-
Optimize the database file.
Parameters
- width: the width of the value of each record. If it is not defined or not more than 0, the current setting is not changed.
- limsiz: the limit size of the database file. If it is not defined or not more than 0, the current setting is not changed.
Return value:
If successful, it is true, else, it is false. - fdb:out (key)
-
Remove a record.
Parameters
- key: the key. It should be more than 0. If it is "min", the minimum ID number of existing records is specified. If it is "max", the maximum ID number of existing records is specified.
Return value:
If successful, it is true, else, it is false. - fdb:pairs ()
-
Get the iterator for generic "for" loop.
Return value:
plural values; the iterator to retrieve the key and the value of the next record, the table itself, and nil. - fdb:path ()
-
Get the path of the database file.
Return value:
the path of the database file or `nil' if the object does not connect to any database file. - fdb:put (key, value)
-
Store a record. If a record with the same key exists in the database, it is overwritten.
Parameters
- key: the key. It should be more than 0. If it is "min", the minimum ID number of existing records is specified. If it is "prev", the number less by one than the minimum ID number of existing records is specified. If it is "max", the maximum ID number of existing records is specified. If it is "next", the number greater by one than the maximum ID number of existing records is specified.
- value: the value.
Return value:
If successful, it is true, else, it is false. - fdb:putcat (key, value)
-
Concatenate a value at the end of the existing record. If there is no corresponding record, a new record is created.
Parameters
- key: the key. It should be more than 0. If it is "min", the minimum ID number of existing records is specified. If it is "prev", the number less by one than the minimum ID number of existing records is specified. If it is "max", the maximum ID number of existing records is specified. If it is "next", the number greater by one than the maximum ID number of existing records is specified.
- value: the value.
Return value:
If successful, it is true, else, it is false. - fdb:putkeep (key, value)
-
Store a new record. If a record with the same key exists in the database, this method has no effect.
Parameters
- key: the key. It should be more than 0. If it is "min", the minimum ID number of existing records is specified. If it is "prev", the number less by one than the minimum ID number of existing records is specified. If it is "max", the maximum ID number of existing records is specified. If it is "next", the number greater by one than the maximum ID number of existing records is specified.
- value: the value.
Return value:
If successful, it is true, else, it is false. - fdb:range (interval, max)
-
Get keys with an interval notation.
Parameters
- interval: the interval notation.
- max: the maximum number of keys to be fetched. If it is not defined or negative, no limit is specified.
Return value:
a array of the keys of the corresponding records. This method does never fail and return an empty array even if no record corresponds. - fdb:rnum ()
-
Get the number of records.
Return value:
the number of records or 0 if the object does not connect to any database file. - fdb:sync ()
-
Synchronize updated contents with the file and the device. This method is useful when another process connects the same database file.
Return value:
If successful, it is true, else, it is false. - fdb:tune (width, limsiz)
-
Set the tuning parameters. The tuning parameters of the database should be set before the database is opened.
Parameters
- width: the width of the value of each record. If it is not defined or not more than 0, the default value is specified. The default value is 255.
- limsiz: the limit size of the database file. If it is not defined or not more than 0, the default value is specified. The default value is 268435456.
Return value:
If successful, it is true, else, it is false. - fdb:vanish ()
-
Remove all records.
Return value:
If successful, it is true, else, it is false. - fdb:vsiz (key)
-
Get the size of the value of a record.
Parameters
- key: the key. It should be more than 0. If it is "min", the minimum ID number of existing records is specified. If it is "max", the maximum ID number of existing records is specified.
Return value:
If successful, it is the size of the value of the corresponding record, else, it is -1. - hdb:adddouble (key, num)
-
Add a real number to a record. 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.
Parameters
- key: the key.
- num: the additional value.
Return value:
If successful, it is the summation value, else, it is `nil'. - hdb:addint (key, num)
-
Add an integer to a record. 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.
Parameters
- key: the key.
- num: the additional value.
Return value:
If successful, it is the summation value, else, it is `nil'. - hdb:close ()
-
Close the database file. 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.
Return value:
If successful, it is true, else, it is false. - hdb:copy (path)
-
Copy the database file. The database file is assured to be kept synchronized and not modified while the copying or executing operation is in progress. So, this method is useful to create a backup file of the database file.
Parameters
- path: the path of the destination file. If it begins with `@', the trailing substring is executed as a command line.
Return value:
If successful, it is true, else, it is false. False is returned if the executed command returns non-zero code. - hdb:ecode ()
-
Get the last happened error code.
Return value:
the last happened error code. The following error codes are defined: `hdb.ESUCCESS' for success, `hdb.ETHREAD' for threading error, `hdb.EINVALID' for invalid operation, `hdb.ENOFILE' for file not found, `hdb.ENOPERM' for no permission, `hdb.EMETA' for invalid meta data, `hdb.ERHEAD' for invalid record header, `hdb.EOPEN' for open error, `hdb.ECLOSE' for close error, `hdb.ETRUNC' for trunc error, `hdb.ESYNC' for sync error, `hdb.ESTAT' for stat error, `hdb.ESEEK' for seek error, `hdb.EREAD' for read error, `hdb.EWRITE' for write error, `hdb.EMMAP' for mmap error, `hdb.ELOCK' for lock error, `hdb.EUNLINK' for unlink error, `hdb.ERENAME' for rename error, `hdb.EMKDIR' for mkdir error, `hdb.ERMDIR' for rmdir error, `hdb.EKEEP' for existing record, `hdb.ENOREC' for no record found, and `hdb.EMISC' for miscellaneous error. - hdb:errmsg (ecode)
-
Get the message string corresponding to an error code.
Parameters
- ecode: the error code. If it is not defined or negative, the last happened error code is specified.
Return value:
The return value is the message string of the error code. - hdb:foreach (func)
-
Process each record atomically.
Parameters
- func: the iterator function called for each record. It receives two parameters of the key and the value, and returns true to continue iteration or false to stop iteration.
Return value:
If successful, it is true, else, it is false. - hdb:fsiz ()
-
Get the size of the database file.
Return value:
the size of the database file or 0 if the object does not connect to any database file. - hdb:fwmkeys (prefix, max)
-
Get forward matching keys. This function may be very slow because every key in the database is scanned.
Parameters
- prefix: the prefix of the corresponding keys.
- max: the maximum number of keys to be fetched. If it is negative, no limit is specified.
Return value:
an array of the keys of the corresponding records. This method does never fail and return an empty array even if no record corresponds. - hdb:get (key)
-
Retrieve a record.
Parameters
- key: the key.
Return value:
If successful, it is the value of the corresponding record. `nil' is returned if no record corresponds. - hdb:iterinit ()
-
Initialize the iterator. The iterator is used in order to access the key of every record stored in a database.
Return value:
If successful, it is true, else, it is false. - hdb:iternext ()
-
Get the next key of the iterator. It is possible to access every record by iteration of calling this method. 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.
Return value:
If successful, it is the next key, else, it is `nil'. `nil' is returned when no record is to be get out of the iterator. - hdb:open (path, omode)
-
Open a database file.
Parameters
- path: the path of the database file.
- omode: the connection mode: `hdb.OWRITER' as a writer, `hdb.OREADER' as a reader. If the mode is `hdb.OWRITER', the following may be added by bitwise or: `hdb.OCREAT', which means it creates a new database if not exist, `hdb.OTRUNC', which means it creates a new database regardless if one exists, `hdb.OTSYNC', which means every transaction synchronizes updated contents with the device. Both of `hdb.OREADER' and `hdb.OWRITER' can be added to by bitwise or: `hdb.ONOLCK', which means it opens the database file without file locking, or `hdb.OLCKNB', which means locking is performed without blocking. If it is not defined, `hdb.OREADER' is specified.
Return value:
If successful, it is true, else, it is false. - hdb:optimize (bnum, apow, fpow, opts)
-
Optimize the database file. This method is useful to reduce the size of the database file with data fragmentation by successive updating.
Parameters
- bnum: the number of elements of the bucket array. If it is not defined or not more than 0, the default value is specified. The default value is two times of the number of records.
- apow: the size of record alignment by power of 2. If it is not defined or negative, the current setting is not changed.
- fpow: the maximum number of elements of the free block pool by power of 2. If it is not defined or negative, the current setting is not changed.
- opts: options by bitwise or: `hdb.TLARGE' specifies that the size of the database can be larger than 2GB by using 64-bit bucket array, `hdb.TDEFLATE' specifies that each record is compressed with Deflate encoding, `hdb.TBZIP' specifies that each record is compressed with BZIP2 encoding, `hdb.TTCBS' specifies that each record is compressed with TCBS encoding. If it is not defined or 0xff, the current setting is not changed.
Return value:
If successful, it is true, else, it is false. - hdb:out (key)
-
Remove a record.
Parameters
- key: the key.
Return value:
If successful, it is true, else, it is false. - hdb:pairs ()
-
Get the iterator for generic "for" loop.
Return value:
plural values; the iterator to retrieve the key and the value of the next record, the table itself, and nil. - hdb:path ()
-
Get the path of the database file.
Return value:
the path of the database file or `nil' if the object does not connect to any database file. - hdb:put (key, value)
-
Store a record. If a record with the same key exists in the database, it is overwritten.
Parameters
- key: the key.
- value: the value.
Return value:
If successful, it is true, else, it is false. - hdb:putasync (key, value)
-
Store a record in asynchronous fashion. If a record with the same key exists in the database, it is overwritten. Records passed to this method are accumulated into the inner buffer and wrote into the file at a blast.
Parameters
- key: the key.
- value: the value.
Return value:
If successful, it is true, else, it is false. - hdb:putcat (key, value)
-
Concatenate a value at the end of the existing record. If there is no corresponding record, a new record is created.
Parameters
- key: the key.
- value: the value.
Return value:
If successful, it is true, else, it is false. - hdb:putkeep (key, value)
-
Store a new record. If a record with the same key exists in the database, this method has no effect.
Parameters
- key: the key.
- value: the value.
Return value:
If successful, it is true, else, it is false. - hdb:rnum ()
-
Get the number of records.
Return value:
the number of records or 0 if the object does not connect to any database file. - hdb:setcache (rcnum)
-
Set the caching parameters. The caching parameters of the database should be set before the database is opened.
Parameters
- rcnum: the maximum number of records to be cached. If it is not defined or not more than 0, the record cache is disabled. It is disabled by default.
Return value:
If successful, it is true, else, it is false. - hdb:setxmsiz (xmsiz)
-
Set the size of the extra mapped memory. The mapping parameters should be set before the database is opened.
Parameters
- xmsiz: the size of the extra mapped memory. If it is not defined or not more than 0, the extra mapped memory is disabled. The default size is 67108864.
Return value:
If successful, the return value is true, else, it is false. - hdb:sync ()
-
Synchronize updated contents with the file and the device. This method is useful when another process connects the same database file.
Return value:
If successful, it is true, else, it is false. - hdb:tranabort ()
-
Abort the transaction. Update in the transaction is discarded when it is aborted. The state of the database is rollbacked to before transaction.
Return value:
If successful, it is true, else, it is false. - hdb:tranbegin ()
-
Begin the transaction. 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.
Return value:
If successful, it is true, else, it is false. - hdb:trancommit ()
-
Commit the transaction. Update in the transaction is fixed when it is committed successfully.
Return value:
If successful, it is true, else, it is false. - hdb:tune (bnum, apow, fpow, opts)
-
Set the tuning parameters. The tuning parameters of the database should be set before the database is opened.
Parameters
- bnum: the number of elements of the bucket array. If it is not defined or not more than 0, the default value is specified. The default value is 131071. Suggested size of the bucket array is about from 0.5 to 4 times of the number of all records to be stored.
- apow: the size of record alignment by power of 2. If it is not defined or negative, the default value is specified. The default value is 4 standing for 2^4=16.
- fpow: the maximum number of elements of the free block pool by power of 2. If it is not defined or negative, the default value is specified. The default value is 10 standing for 2^10=1024.
- opts: options by bitwise or: `hdb.TLARGE' specifies that the size of the database can be larger than 2GB by using 64-bit bucket array, `hdb.TDEFLATE' specifies that each record is compressed with Deflate encoding, `hdb.TBZIP' specifies that each record is compressed with BZIP2 encoding, `hdb.TTCBS' specifies that each record is compressed with TCBS encoding. If it is not defined, no option is specified.
Return value:
If successful, it is true, else, it is false. - hdb:vanish ()
-
Remove all records.
Return value:
If successful, it is true, else, it is false. - hdb:vsiz (key)
-
Get the size of the value of a record.
Parameters
- key: the key.
Return value:
If successful, it is the size of the value of the corresponding record, else, it is -1. - tokyocabinet.bdbcurnew (bdb)
-
Create a cursor object of a B+ tree database object. Cursor is a mechanism to access each record of B+ tree database in ascending or descending order. The cursor is available only after initialization with the `cur:first' or the `cur:jump' methods and so on. Moreover, the position of the cursor will be indefinite when the database is updated after the initialization of the cursor.
Parameters
- bdb: the B+ tree database object.
- tokyocabinet.bdbnew ()
-
Create a B+ tree database object. B+ tree database is a file containing a B+ tree and is handled with the B+ tree database API. Before operations to store or retrieve records, it is necessary to open a database file and connect the B+ tree database object to it. To avoid data missing or corruption, it is important to close every database file when it is no longer in use.
Return value:
the new B+ tree database object. - tokyocabinet.chdir (path)
-
Change the current working directory.
Parameters
- path: the path of the directory.
Return value:
If successful, it is true, else, it is false. - tokyocabinet.codec (mode, str)
-
Encode or decode a string.
Parameters
- mode: the encoding method; "url" for URL encoding, "~url" for URL decoding, "base" for Base64 encoding, "~base" for Base64 decoding, "hex" for hexadecimal encoding, "~hex" for hexadecimal decoding, "pack" for PackBits encoding, "~pack" for PackBits decoding, "tcbs" for TCBS encoding, "~tcbs" for TCBS decoding, "deflate" for Deflate encoding, "~deflate" for Deflate decoding, "gzip" for GZIP encoding, "~gzip" for GZIP decoding, "bzip" for BZIP2 encoding, "~bzip" for BZIP2 decoding, "xml" for XML escaping, "~xml" for XML unescaping.
- str: the string.
Return value:
the encoded or decoded string. - tokyocabinet.dist (astr, bstr, isutf)
-
Calculate the edit distance of two UTF-8 strings.
Parameters
- astr: a string.
- bstr: the other string.
- isutf: whether to calculate cost by Unicode character. If it is not defined, false is specified and calculate cost by ASCII character.
Return value:
the edit distance which is known as the Levenshtein distance. - tokyocabinet.fdbnew ()
-
Create a fixed-length database object. Fixed-Length database is a file containing a fixed-length table and is handled with the fixed-length database API. Before operations to store or retrieve records, it is necessary to open a database file and connect the fixed-length database object to it. To avoid data missing or corruption, it is important to close every database file when it is no longer in use.
Return value:
the new fixed-length database object. - tokyocabinet.glob (pattern)
-
Find pathnames matching a pattern.
Parameters
- pattern: the matching pattern. "?" and "*" are meta characters.
Return value:
an array of matched paths. If no path is matched, an empty array is returned. - tokyocabinet.hash (mode, str)
-
Get the hash value of a string.
Parameters
- mode: the hash method; "md5" for MD5 in hexadecimal format, "md5raw" for MD5 in raw format, "crc32" for CRC32 checksum number.
- str: the string.
Return value:
the hash value. - tokyocabinet.hdbnew ()
-
Create a hash database object. Hash database is a file containing a hash table and is handled with the hash database API. Before operations to store or retrieve records, it is necessary to open a database file and connect the hash database object to it. To avoid data missing or corruption, it is important to close every database file when it is no longer in use.
Return value:
the new hash database object. - tokyocabinet.isect (ary, ...)
-
Calculate the intersection set of arrays.
Parameters
- ary: the arrays. Arbitrary number of arrays can be specified as the parameter list.
- ...:
Return value:
the array of the intersection set. - tokyocabinet.mkdir (path)
-
Create a directory.
Parameters
- path: the path of the directory.
Return value:
If successful, it is true, else, it is false. - tokyocabinet.pack (format, ary, ...)
-
Serialize an array of numbers into a string.
Parameters
- format: the format string. It should be composed of conversion characters; `c' for int8_t, `C' for uint8_t, `s' for int16_t, `S' for uint16_t, `i' for int32_t, `I' for uint32_t, `l' for int64_t, `L' for uint64_t, `f' for float, `d' for double, `n' for uint16_t in network byte order, `N' for uint32_t in network byte order, `M' for uint64_t in network byte order, and `w' for BER encoding. They can be trailed by a numeric expression standing for the iteration count or by `*' for the rest all iteration.
- ary: the array of numbers. It can be trailed optional arguments, which are treated as additional elements of the array.
- ...:
Return value:
the serialized string. - tokyocabinet.remove (path)
-
Remove a file or a directory and its sub ones recursively.
Parameters
- path: the path of the link.
Return value:
If successful, it is true, else, it is false. - tokyocabinet.sleep (sec)
-
Suspend execution for the specified interval.
Parameters
- sec: the interval in seconds.
- tokyocabinet.stat (path)
-
Get the status of a file.
Parameters
- path: the path of the file.
Return value:
If successful, the return value is a table containing status, else, it is `nil'. There are keys of status name; "dev", "ino", "mode", "nlink", "uid", "gid", "rdev", "size", "blksize", "blocks", "atime", "mtime", "ctime", which have same meanings of the POSIX "stat" call. Additionally, "_regular" for whether the file is a regular file, "_directory" for whether the file is a directory, "_readable" for whether the file is readable by the process, "_writable" for whether the file is writable by the process, "_executable" for whether the file is executable by the process, "_realpath" for the real path of the file, are supported. - tokyocabinet.tablenew (anum, rnum)
-
Create a table with specifying the number of array elements and the number of hash records.
Parameters
- anum: the expected number of array elements. If it is not defined, 0 is specified.
- rnum: the expected number of hash records. If it is not defined, 0 is specified.
Return value:
the created empty table. - tokyocabinet.time ()
-
Get the time of day in seconds.
Return value:
the time of day in seconds. The accuracy is in microseconds. - tokyocabinet.ucs (data)
-
Convert a UTF-8 string into a UCS-2 array or its inverse.
Parameters
- data: the target data. If it is a string, convert it into a UCS-array. If it is an array, convert it into a UTF-8 string.
Return value:
the result data. - tokyocabinet.union (ary, ...)
-
Calculate the union set of arrays.
Parameters
- ary: the arrays. Arbitrary number of arrays can be specified as the parameter list.
- ...:
Return value:
the array of the union set. - tokyocabinet.unpack (format, str)
-
Deserialize a binary string into an array of numbers.
Parameters
- format: the format string. It should be composed of conversion characters as with `tokyocabinet.pack'.
- str: the binary string.
Return value:
the deserialized array.