Tkrzw
|
C language binding of Tkrzw. More...
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
Classes | |
struct | TkrzwStatus |
Pair of a status code and a message. More... | |
struct | TkrzwFuture |
Future interface, just for type check. More... | |
struct | TkrzwDBM |
DBM interface, just for type check. More... | |
struct | TkrzwDBMIter |
Iterator interface, just for type check. More... | |
struct | TkrzwAsyncDBM |
Asynchronous DBM interface, just for type check. More... | |
struct | TkrzwFile |
File interface, just for type check. More... | |
struct | TkrzwIndex |
Index interface, just for type check. More... | |
struct | TkrzwIndexIter |
Index iterator interface, just for type check. More... | |
struct | TkrzwStr |
String pointer and its size. More... | |
struct | TkrzwKeyValuePair |
Pair of a key and its value. More... | |
struct | TkrzwKeyProcPair |
Pair of a key and its processor. More... | |
Typedefs | |
typedef const char *(* | tkrzw_record_processor) (void *, const char *, int32_t, const char *, int32_t, int32_t *) |
Type of the record processor function. More... | |
typedef void(* | tkrzw_file_processor) (void *arg, const char *) |
Type of the file processor function. More... | |
Enumerations | |
enum | { TKRZW_STATUS_SUCCESS = 0 , TKRZW_STATUS_UNKNOWN_ERROR = 1 , TKRZW_STATUS_SYSTEM_ERROR = 2 , TKRZW_STATUS_NOT_IMPLEMENTED_ERROR = 3 , TKRZW_STATUS_PRECONDITION_ERROR = 4 , TKRZW_STATUS_INVALID_ARGUMENT_ERROR = 5 , TKRZW_STATUS_CANCELED_ERROR = 6 , TKRZW_STATUS_NOT_FOUND_ERROR = 7 , TKRZW_STATUS_PERMISSION_ERROR = 8 , TKRZW_STATUS_INFEASIBLE_ERROR = 9 , TKRZW_STATUS_DUPLICATION_ERROR = 10 , TKRZW_STATUS_BROKEN_DATA_ERROR = 11 , TKRZW_STATUS_NETWORK_ERROR = 12 , TKRZW_STATUS_APPLICATION_ERROR = 13 } |
Enumeration for status codes. More... | |
Functions | |
void | tkrzw_set_last_status (int32_t code, const char *message) |
Sets the status code and the message as if it is from the last system operation. More... | |
TkrzwStatus | tkrzw_get_last_status () |
Gets the status code and the message of the last system operation. More... | |
int32_t | tkrzw_get_last_status_code () |
Gets the status code of the last system operation. More... | |
const char * | tkrzw_get_last_status_message () |
Gets the status message of the last system operation. More... | |
const char * | tkrzw_status_code_name (int32_t code) |
Gets the string name of a status code. More... | |
double | tkrzw_get_wall_time () |
Gets the number of seconds since the UNIX epoch. More... | |
int64_t | tkrzw_get_memory_capacity () |
Gets the memory capacity of the platform. More... | |
int64_t | tkrzw_get_memory_usage () |
Gets the current memory usage of the process. More... | |
uint64_t | tkrzw_primary_hash (const char *data_ptr, int32_t data_size, uint64_t num_buckets) |
Primary hash function for the hash database. More... | |
uint64_t | tkrzw_secondary_hash (const char *data_ptr, int32_t data_size, uint64_t num_shards) |
Secondary hash function for sharding. More... | |
void | tkrzw_free_str_array (TkrzwStr *array, int32_t size) |
Releases an allocated array and its elements of allocated strings. More... | |
void | tkrzw_free_str_map (TkrzwKeyValuePair *array, int32_t size) |
Releases an allocated array and its elements of allocated key-value pairs. More... | |
TkrzwKeyValuePair * | tkrzw_search_str_map (TkrzwKeyValuePair *array, int32_t size, const char *key_ptr, int32_t key_size) |
Searches an array of key-value pairs for a record with the given key. More... | |
int32_t | tkrzw_str_search_regex (const char *text, const char *pattern) |
Searches a string for a pattern matching a regular expression. More... | |
char * | tkrzw_str_replace_regex (const char *text, const char *pattern, const char *replace) |
Replaces substrings matching a pattern of regular expression. More... | |
int32_t | tkrzw_str_edit_distance_lev (const char *a, const char *b, bool utf) |
Gets the Levenshtein edit distance of two strings. More... | |
uint64_t | tkrzw_str_to_int_be (const void *ptr, size_t size) |
Converts a big-endian binary string to an integer. More... | |
long double | tkrzw_str_to_float_be (const void *ptr, size_t size) |
Converts a big-endian binary string to a floating-point number. More... | |
char * | tkrzw_int_to_str_be (uint64_t data, size_t size) |
Converts an integer into a big-endian binary string. More... | |
char * | tkrzw_float_to_str_be (long double data, size_t size) |
Converts a floating-point number into a big-endian binary string. More... | |
char * | tkrzw_str_escape_c (const char *ptr, int32_t size, bool esc_nonasc, int32_t *res_size) |
Escapes C-style meta characters in a string. More... | |
char * | tkrzw_str_unescape_c (const char *ptr, int32_t size, int32_t *res_size) |
Unescapes C-style escape sequences in a string. More... | |
char * | tkrzw_str_append (char *modified, const char *appended) |
Appends a string at the end of another allocated string. More... | |
void | tkrzw_future_free (TkrzwFuture *future) |
Releases the future object. More... | |
bool | tkrzw_future_wait (TkrzwFuture *future, double timeout) |
Waits for the operation of the future object to be done. More... | |
void | tkrzw_future_get (TkrzwFuture *future) |
Gets the status of the operation of the future object. More... | |
char * | tkrzw_future_get_str (TkrzwFuture *future, int32_t *size) |
Gets the status and the extra string data of the operation of the future object. More... | |
TkrzwKeyValuePair * | tkrzw_future_get_str_pair (TkrzwFuture *future) |
Gets the status and the extra string pair of the operation of the future object. More... | |
TkrzwStr * | tkrzw_future_get_str_array (TkrzwFuture *future, int32_t *num_elems) |
Gets the status and the extra string array of the operation of the future object. More... | |
TkrzwKeyValuePair * | tkrzw_future_get_str_map (TkrzwFuture *future, int32_t *num_elems) |
Gets the status and the extra string map of the operation of the future object. More... | |
int64_t | tkrzw_future_get_int (TkrzwFuture *future) |
Gets the status and the extra integer data of the operation of the future object. More... | |
TkrzwDBM * | tkrzw_dbm_open (const char *path, bool writable, const char *params) |
Opens a database file and makes a database object. More... | |
bool | tkrzw_dbm_close (TkrzwDBM *dbm) |
Closes the database file and releases the database object. More... | |
bool | tkrzw_dbm_process (TkrzwDBM *dbm, const char *key_ptr, int32_t key_size, tkrzw_record_processor proc, void *proc_arg, bool writable) |
Processes a record with callback functions. More... | |
bool | tkrzw_dbm_check (TkrzwDBM *dbm, const char *key_ptr, int32_t key_size) |
Checks if a record exists or not. More... | |
char * | tkrzw_dbm_get (TkrzwDBM *dbm, const char *key_ptr, int32_t key_size, int32_t *value_size) |
Gets the value of a record of a key. More... | |
TkrzwKeyValuePair * | tkrzw_dbm_get_multi (TkrzwDBM *dbm, const TkrzwStr *keys, int32_t num_keys, int32_t *num_matched) |
Gets the values of multiple records of keys. More... | |
bool | tkrzw_dbm_set (TkrzwDBM *dbm, const char *key_ptr, int32_t key_size, const char *value_ptr, int32_t value_size, bool overwrite) |
Sets a record of a key and a value. More... | |
char * | tkrzw_dbm_set_and_get (TkrzwDBM *dbm, const char *key_ptr, int32_t key_size, const char *value_ptr, int32_t value_size, bool overwrite, int32_t *old_value_size) |
Sets a record and get the old value. More... | |
bool | tkrzw_dbm_set_multi (TkrzwDBM *dbm, const TkrzwKeyValuePair *records, int32_t num_records, bool overwrite) |
Sets multiple records. More... | |
bool | tkrzw_dbm_remove (TkrzwDBM *dbm, const char *key_ptr, int32_t key_size) |
Removes a record of a key. More... | |
char * | tkrzw_dbm_remove_and_get (TkrzwDBM *dbm, const char *key_ptr, int32_t key_size, int32_t *value_size) |
Removes a record and get the value. More... | |
bool | tkrzw_dbm_remove_multi (TkrzwDBM *dbm, const TkrzwStr *keys, int32_t num_keys) |
Removes records of keys. More... | |
bool | tkrzw_dbm_append (TkrzwDBM *dbm, const char *key_ptr, int32_t key_size, const char *value_ptr, int32_t value_size, const char *delim_ptr, int32_t delim_size) |
Appends data at the end of a record of a key. More... | |
bool | tkrzw_dbm_append_multi (TkrzwDBM *dbm, const TkrzwKeyValuePair *records, int32_t num_records, const char *delim_ptr, int32_t delim_size) |
Appends data to multiple records. More... | |
bool | tkrzw_dbm_compare_exchange (TkrzwDBM *dbm, const char *key_ptr, int32_t key_size, const char *expected_ptr, int32_t expected_size, const char *desired_ptr, int32_t desired_size) |
Compares the value of a record and exchanges if the condition meets. More... | |
char * | tkrzw_dbm_compare_exchange_and_get (TkrzwDBM *dbm, const char *key_ptr, int32_t key_size, const char *expected_ptr, int32_t expected_size, const char *desired_ptr, int32_t desired_size, int32_t *actual_size) |
Does compare-and-exchange and/or gets the old value of the record. More... | |
int64_t | tkrzw_dbm_increment (TkrzwDBM *dbm, const char *key_ptr, int32_t key_size, int64_t increment, int64_t initial) |
Increments the numeric value of a record. More... | |
bool | tkrzw_dbm_process_multi (TkrzwDBM *dbm, TkrzwKeyProcPair *key_proc_pairs, int32_t num_pairs, bool writable) |
Processes multiple records with processors. More... | |
bool | tkrzw_dbm_compare_exchange_multi (TkrzwDBM *dbm, const TkrzwKeyValuePair *expected, int32_t num_expected, const TkrzwKeyValuePair *desired, int32_t num_desired) |
Compares the values of records and exchanges if the condition meets. More... | |
bool | tkrzw_dbm_rekey (TkrzwDBM *dbm, const char *old_key_ptr, int32_t old_key_size, const char *new_key_ptr, int32_t new_key_size, bool overwrite, bool copying) |
Changes the key of a record. More... | |
bool | tkrzw_dbm_process_first (TkrzwDBM *dbm, tkrzw_record_processor proc, void *proc_arg, bool writable) |
Processes the first record with a processor. More... | |
bool | tkrzw_dbm_pop_first (TkrzwDBM *dbm, char **key_ptr, int32_t *key_size, char **value_ptr, int32_t *value_size) |
Gets the first record and removes it. More... | |
bool | tkrzw_dbm_push_last (TkrzwDBM *dbm, const char *value_ptr, int32_t value_size, double wtime) |
Adds a record with a key of the current timestamp. More... | |
bool | tkrzw_dbm_process_each (TkrzwDBM *dbm, tkrzw_record_processor proc, void *proc_arg, bool writable) |
Processes each and every record in the database with a processor. More... | |
int64_t | tkrzw_dbm_count (TkrzwDBM *dbm) |
Gets the number of records. More... | |
int64_t | tkrzw_dbm_get_file_size (TkrzwDBM *dbm) |
Gets the current file size of the database. More... | |
char * | tkrzw_dbm_get_file_path (TkrzwDBM *dbm) |
Gets the path of the database file. More... | |
double | tkrzw_dbm_get_timestamp (TkrzwDBM *dbm) |
Gets the timestamp in seconds of the last modified time. More... | |
bool | tkrzw_dbm_clear (TkrzwDBM *dbm) |
Removes all records. More... | |
bool | tkrzw_dbm_rebuild (TkrzwDBM *dbm, const char *params) |
Rebuilds the entire database. More... | |
bool | tkrzw_dbm_should_be_rebuilt (TkrzwDBM *dbm) |
Checks whether the database should be rebuilt. More... | |
bool | tkrzw_dbm_synchronize (TkrzwDBM *dbm, bool hard, tkrzw_file_processor proc, void *proc_arg, const char *params) |
Synchronizes the content of the database to the file system. More... | |
bool | tkrzw_dbm_copy_file_data (TkrzwDBM *dbm, const char *dest_path, bool sync_hard) |
Copies the content of the database files to other files. More... | |
bool | tkrzw_dbm_export (TkrzwDBM *dbm, TkrzwDBM *dest_dbm) |
Exports all records to another database. More... | |
bool | tkrzw_dbm_export_to_flat_records (TkrzwDBM *dbm, TkrzwFile *dest_file) |
Exports all records of a database to a flat record file. More... | |
bool | tkrzw_dbm_import_from_flat_records (TkrzwDBM *dbm, TkrzwFile *src_file) |
Imports records to a database from a flat record file. More... | |
bool | tkrzw_dbm_export_keys_as_lines (TkrzwDBM *dbm, TkrzwFile *dest_file) |
Exports the keys of all records of a database as lines to a text file. More... | |
TkrzwKeyValuePair * | tkrzw_dbm_inspect (TkrzwDBM *dbm, int32_t *num_records) |
Inspects the database. More... | |
bool | tkrzw_dbm_is_writable (TkrzwDBM *dbm) |
Checks whether the database is writable. More... | |
bool | tkrzw_dbm_is_healthy (TkrzwDBM *dbm) |
Checks whether the database condition is healthy. More... | |
bool | tkrzw_dbm_is_ordered (TkrzwDBM *dbm) |
Checks whether ordered operations are supported. More... | |
TkrzwStr * | tkrzw_dbm_search (TkrzwDBM *dbm, const char *mode, const char *pattern_ptr, int32_t pattern_size, int32_t capacity, int32_t *num_matched) |
Searches a database and get keys which match a pattern, according to a mode expression. More... | |
TkrzwDBMIter * | tkrzw_dbm_make_iterator (TkrzwDBM *dbm) |
Makes an iterator for each record. More... | |
void | tkrzw_dbm_iter_free (TkrzwDBMIter *iter) |
Releases the iterator object. More... | |
bool | tkrzw_dbm_iter_first (TkrzwDBMIter *iter) |
Initializes the iterator to indicate the first record. More... | |
bool | tkrzw_dbm_iter_last (TkrzwDBMIter *iter) |
Initializes the iterator to indicate the last record. More... | |
bool | tkrzw_dbm_iter_jump (TkrzwDBMIter *iter, const char *key_ptr, int32_t key_size) |
Initializes the iterator to indicate a specific record. More... | |
bool | tkrzw_dbm_iter_jump_lower (TkrzwDBMIter *iter, const char *key_ptr, int32_t key_size, bool inclusive) |
Initializes the iterator to indicate the last record whose key is lower than a given key. More... | |
bool | tkrzw_dbm_iter_jump_upper (TkrzwDBMIter *iter, const char *key_ptr, int32_t key_size, bool inclusive) |
Initializes the iterator to indicate the first record whose key is upper than a given key. More... | |
bool | tkrzw_dbm_iter_next (TkrzwDBMIter *iter) |
Moves the iterator to the next record. More... | |
bool | tkrzw_dbm_iter_previous (TkrzwDBMIter *iter) |
Moves the iterator to the previous record. More... | |
bool | tkrzw_dbm_iter_process (TkrzwDBMIter *iter, tkrzw_record_processor proc, void *proc_arg, bool writable) |
Processes the current record with a processor. More... | |
bool | tkrzw_dbm_iter_get (TkrzwDBMIter *iter, char **key_ptr, int32_t *key_size, char **value_ptr, int32_t *value_size) |
Gets the key and the value of the current record of the iterator. More... | |
char * | tkrzw_dbm_iter_get_key (TkrzwDBMIter *iter, int32_t *key_size) |
Gets the key of the current record, in a simple way. More... | |
char * | tkrzw_dbm_iter_get_value (TkrzwDBMIter *iter, int32_t *value_size) |
Gets the key of the current record, in a simple way. More... | |
bool | tkrzw_dbm_iter_set (TkrzwDBMIter *iter, const char *value_ptr, int32_t value_size) |
Sets the value of the current record. More... | |
bool | tkrzw_dbm_iter_remove (TkrzwDBMIter *iter) |
Removes the current record. More... | |
bool | tkrzw_dbm_iter_step (TkrzwDBMIter *iter, char **key_ptr, int32_t *key_size, char **value_ptr, int32_t *value_size) |
Gets the current record and moves the iterator to the next record. More... | |
bool | tkrzw_dbm_restore_database (const char *old_file_path, const char *new_file_path, const char *class_name, int64_t end_offset, const char *cipher_key) |
Restores a broken database as a new healthy database. More... | |
TkrzwAsyncDBM * | tkrzw_async_dbm_new (TkrzwDBM *dbm, int32_t num_worker_threads) |
Creates an asynchronous database adapter. More... | |
void | tkrzw_async_dbm_free (TkrzwAsyncDBM *async) |
Releases the asynchronous database adapter. More... | |
TkrzwFuture * | tkrzw_async_dbm_get (TkrzwAsyncDBM *async, const char *key_ptr, int32_t key_size) |
Gets the value of a record of a key asynchronously. More... | |
TkrzwFuture * | tkrzw_async_dbm_get_multi (TkrzwAsyncDBM *async, const TkrzwStr *keys, int32_t num_keys) |
Gets the values of multiple records of keys asynchronously. More... | |
TkrzwFuture * | tkrzw_async_dbm_set (TkrzwAsyncDBM *async, const char *key_ptr, int32_t key_size, const char *value_ptr, int32_t value_size, bool overwrite) |
Sets a record of a key and a value asynchronously. More... | |
TkrzwFuture * | tkrzw_async_dbm_set_multi (TkrzwAsyncDBM *async, const TkrzwKeyValuePair *records, int32_t num_records, bool overwrite) |
Sets multiple records asynchronously. More... | |
TkrzwFuture * | tkrzw_async_dbm_remove (TkrzwAsyncDBM *async, const char *key_ptr, int32_t key_size) |
Removes a record of a key asynchronously. More... | |
TkrzwFuture * | tkrzw_async_dbm_remove_multi (TkrzwAsyncDBM *async, const TkrzwStr *keys, int32_t num_keys) |
Removes records of keys asynchronously. More... | |
TkrzwFuture * | tkrzw_async_dbm_append (TkrzwAsyncDBM *async, const char *key_ptr, int32_t key_size, const char *value_ptr, int32_t value_size, const char *delim_ptr, int32_t delim_size) |
Appends data at the end of a record of a key asynchronously. More... | |
TkrzwFuture * | tkrzw_async_dbm_append_multi (TkrzwAsyncDBM *async, const TkrzwKeyValuePair *records, int32_t num_records, const char *delim_ptr, int32_t delim_size) |
Appends data to multiple records asynchronously. More... | |
TkrzwFuture * | tkrzw_async_dbm_compare_exchange (TkrzwAsyncDBM *async, const char *key_ptr, int32_t key_size, const char *expected_ptr, int32_t expected_size, const char *desired_ptr, int32_t desired_size) |
Compares the value of a record and exchanges if the condition meets asynchronously. More... | |
TkrzwFuture * | tkrzw_async_dbm_increment (TkrzwAsyncDBM *async, const char *key_ptr, int32_t key_size, int64_t increment, int64_t initial) |
Increments the numeric value of a record asynchronously. More... | |
TkrzwFuture * | tkrzw_async_dbm_compare_exchange_multi (TkrzwAsyncDBM *async, const TkrzwKeyValuePair *expected, int32_t num_expected, const TkrzwKeyValuePair *desired, int32_t num_desired) |
Compares the values of records and exchanges if the condition meets asynchronously. More... | |
TkrzwFuture * | tkrzw_async_dbm_rekey (TkrzwAsyncDBM *async, const char *old_key_ptr, int32_t old_key_size, const char *new_key_ptr, int32_t new_key_size, bool overwrite, bool copying) |
Changes the key of a record asynchronously. More... | |
TkrzwFuture * | tkrzw_async_dbm_pop_first (TkrzwAsyncDBM *async) |
Gets the first record and removes it asynchronously. More... | |
TkrzwFuture * | tkrzw_async_dbm_push_last (TkrzwAsyncDBM *async, const char *value_ptr, int32_t value_size, double wtime) |
Adds a record with a key of the current timestamp. More... | |
TkrzwFuture * | tkrzw_async_dbm_clear (TkrzwAsyncDBM *async) |
Removes all records asynchronously. More... | |
TkrzwFuture * | tkrzw_async_dbm_rebuild (TkrzwAsyncDBM *async, const char *params) |
Rebuilds the entire database asynchronously. More... | |
TkrzwFuture * | tkrzw_async_dbm_synchronize (TkrzwAsyncDBM *async, bool hard, const char *params) |
Synchronizes the content of the database to the file system asynchronously. More... | |
TkrzwFuture * | tkrzw_async_dbm_copy_file_data (TkrzwAsyncDBM *async, const char *dest_path, bool sync_hard) |
Copies the content of the database files to other files. More... | |
TkrzwFuture * | tkrzw_async_dbm_export (TkrzwAsyncDBM *async, TkrzwDBM *dest_dbm) |
Exports all records to another database. More... | |
TkrzwFuture * | tkrzw_async_dbm_export_to_flat_records (TkrzwAsyncDBM *async, TkrzwFile *dest_file) |
Exports all records of a database to a flat record file. More... | |
TkrzwFuture * | tkrzw_async_dbm_import_from_flat_records (TkrzwAsyncDBM *async, TkrzwFile *src_file) |
Imports records to a database from a flat record file. More... | |
TkrzwFuture * | tkrzw_async_dbm_search (TkrzwAsyncDBM *async, const char *mode, const char *pattern_ptr, int32_t pattern_size, int32_t capacity) |
Searches a database and get keys asynchronously. More... | |
TkrzwFile * | tkrzw_file_open (const char *path, bool writable, const char *params) |
Opens a file. More... | |
bool | tkrzw_file_close (TkrzwFile *file) |
Closes the file. More... | |
bool | tkrzw_file_read (TkrzwFile *file, int64_t off, void *buf, size_t size) |
Reads data. More... | |
bool | tkrzw_file_write (TkrzwFile *file, int64_t off, const void *buf, size_t size) |
Writes data. More... | |
bool | tkrzw_file_append (TkrzwFile *file, const void *buf, size_t size, int64_t *off) |
Appends data at the end of the file. More... | |
bool | tkrzw_file_truncate (TkrzwFile *file, int64_t size) |
Truncates the file. More... | |
bool | tkrzw_file_synchronize (TkrzwFile *file, bool hard, int64_t off, int64_t size) |
Synchronizes the content of the file to the file system. More... | |
int64_t | tkrzw_file_get_size (TkrzwFile *file) |
Gets the size of the file. More... | |
char * | tkrzw_file_get_path (TkrzwFile *file) |
Gets the path of the file. More... | |
TkrzwStr * | tkrzw_file_search (TkrzwFile *file, const char *mode, const char *pattern_ptr, int32_t pattern_size, int32_t capacity, int32_t *num_matched) |
Searches the file and get lines which match a pattern, according to a mode expression. More... | |
TkrzwIndex * | tkrzw_index_open (const char *path, bool writable, const char *params) |
Opens an index file and makes an index object. More... | |
bool | tkrzw_index_close (TkrzwIndex *index) |
Closes the index file and releases the index object. More... | |
bool | tkrzw_index_check (TkrzwIndex *index, const char *key_ptr, int32_t key_size, const char *value_ptr, int32_t value_size) |
Checks whether a record exists in the index. More... | |
TkrzwStr * | tkrzw_index_get_values (TkrzwIndex *index, const char *key_ptr, int32_t key_size, int32_t max, int32_t *num_elems) |
Gets all values of records of a key. More... | |
bool | tkrzw_index_add (TkrzwIndex *index, const char *key_ptr, int32_t key_size, const char *value_ptr, int32_t value_size) |
Adds a record. More... | |
bool | tkrzw_index_remove (TkrzwIndex *index, const char *key_ptr, int32_t key_size, const char *value_ptr, int32_t value_size) |
Remove a record. More... | |
int32_t | tkrzw_index_count (TkrzwIndex *index) |
Gets the number of records. More... | |
char * | tkrzw_index_get_file_path (TkrzwIndex *index) |
Gets the path of the index file. More... | |
bool | tkrzw_index_clear (TkrzwIndex *index) |
Removes all records. More... | |
bool | tkrzw_index_rebuild (TkrzwIndex *index) |
Rebuilds the entire database. More... | |
bool | tkrzw_index_synchronize (TkrzwIndex *index, bool hard) |
Synchronizes the content of the database to the file system. More... | |
bool | tkrzw_index_is_writable (TkrzwIndex *index) |
Checks whether the database is writable. More... | |
TkrzwIndexIter * | tkrzw_index_make_iterator (TkrzwIndex *index) |
Makes an iterator for each record. More... | |
void | tkrzw_index_iter_free (TkrzwIndexIter *iter) |
Releases the iterator object. More... | |
void | tkrzw_index_iter_first (TkrzwIndexIter *iter) |
Initializes the iterator to indicate the first record. More... | |
void | tkrzw_index_iter_last (TkrzwIndexIter *iter) |
Initializes the iterator to indicate the last record. More... | |
void | tkrzw_index_iter_jump (TkrzwIndexIter *iter, const char *key_ptr, int32_t key_size, const char *value_ptr, int32_t value_size) |
Initializes the iterator to indicate a specific range. More... | |
void | tkrzw_index_iter_next (TkrzwIndexIter *iter) |
Moves the iterator to the next record. More... | |
void | tkrzw_index_iter_previous (TkrzwIndexIter *iter) |
Moves the iterator to the previous record. More... | |
bool | tkrzw_index_iter_get (TkrzwIndexIter *iter, char **key_ptr, int32_t *key_size, char **value_ptr, int32_t *value_size) |
Gets the key and the value of the current record of the iterator. More... | |
Variables | |
const char *const | TKRZW_PACKAGE_VERSION |
The string expression of the package version. More... | |
const char *const | TKRZW_LIBRARY_VERSION |
The string expression of the library version. More... | |
const char *const | TKRZW_OS_NAME |
The recognized OS name. More... | |
const int32_t | TKRZW_PAGE_SIZE |
The size of a memory page on the OS. More... | |
const int64_t | TKRZW_INT64MIN |
The minimum value of int64_t. More... | |
const int64_t | TKRZW_INT64MAX |
The maximum value of int64_t. More... | |
const char *const | TKRZW_ANY_DATA |
The special string_view value to represent any data. More... | |
const char *const | TKRZW_REC_PROC_NOOP |
The special string indicating no operation. More... | |
const char *const | TKRZW_REC_PROC_REMOVE |
The special string indicating removing operation. More... | |
C language binding of Tkrzw.
typedef const char*(* tkrzw_record_processor) (void *, const char *, int32_t, const char *, int32_t, int32_t *) |
Type of the record processor function.
The first parameter is an opaque argument set by the caller. The second parameter is the key pointer. The third parameter is the key size. The fourth parameter is the value pointer or NULL if there's no existing record. The fifth parameter is the value size or -1 if there's no existing record. The sixth parameter is the pointer where the size of the region of the return value is to be stored.
typedef void(* tkrzw_file_processor) (void *arg, const char *) |
Type of the file processor function.
The first parameter is an opaque argument set by the caller. The second parameter is the path of file.
anonymous enum |
Enumeration for status codes.
void tkrzw_set_last_status | ( | int32_t | code, |
const char * | message | ||
) |
Sets the status code and the message as if it is from the last system operation.
code | The status code. |
message | The status message. If it is NULL, no message is set. |
TkrzwStatus tkrzw_get_last_status | ( | ) |
Gets the status code and the message of the last system operation.
The region of the message string is available until the this function or tkrzw_get_last_status_message function is called next time.
int32_t tkrzw_get_last_status_code | ( | ) |
Gets the status code of the last system operation.
const char* tkrzw_get_last_status_message | ( | ) |
Gets the status message of the last system operation.
The region of the message string is available until the this function or tkrzw_get_last_status function is called next time.
const char* tkrzw_status_code_name | ( | int32_t | code | ) |
Gets the string name of a status code.
code | The status code. |
double tkrzw_get_wall_time | ( | ) |
Gets the number of seconds since the UNIX epoch.
int64_t tkrzw_get_memory_capacity | ( | ) |
Gets the memory capacity of the platform.
int64_t tkrzw_get_memory_usage | ( | ) |
Gets the current memory usage of the process.
uint64_t tkrzw_primary_hash | ( | const char * | data_ptr, |
int32_t | data_size, | ||
uint64_t | num_buckets | ||
) |
Primary hash function for the hash database.
data_ptr | The pointer to the data to calculate the hash value for. |
data_size | The size of the data. If it is negative, strlen(data_ptr) is used. |
num_buckets | The number of buckets of the hash table. |
uint64_t tkrzw_secondary_hash | ( | const char * | data_ptr, |
int32_t | data_size, | ||
uint64_t | num_shards | ||
) |
Secondary hash function for sharding.
data_ptr | The pointer to the data to calculate the hash value for. |
data_size | The size of the data. If it is negative, strlen(data_ptr) is used. |
num_shards | The number of shards. |
void tkrzw_free_str_array | ( | TkrzwStr * | array, |
int32_t | size | ||
) |
Releases an allocated array and its elements of allocated strings.
array | The pointer to the array to release. |
size | The number of the elements of the array. |
void tkrzw_free_str_map | ( | TkrzwKeyValuePair * | array, |
int32_t | size | ||
) |
Releases an allocated array and its elements of allocated key-value pairs.
array | The pointer to the array to release. |
size | The number of the elements of the array. |
TkrzwKeyValuePair* tkrzw_search_str_map | ( | TkrzwKeyValuePair * | array, |
int32_t | size, | ||
const char * | key_ptr, | ||
int32_t | key_size | ||
) |
Searches an array of key-value pairs for a record with the given key.
array | The pointer to the array to search. |
size | The number of the elements of the array. |
key_ptr | The key pointer to search for. |
key_size | The key size. If it is negative, strlen(key_ptr) is used. |
int32_t tkrzw_str_search_regex | ( | const char * | text, |
const char * | pattern | ||
) |
Searches a string for a pattern matching a regular expression.
text | The text to search. |
pattern | The regular expression pattern to search for. |
char* tkrzw_str_replace_regex | ( | const char * | text, |
const char * | pattern, | ||
const char * | replace | ||
) |
Replaces substrings matching a pattern of regular expression.
text | The text to process. |
pattern | The regular expression pattern to search for. |
replace | The replacing expression. "$&" means the entire matched pattern. "$1", "$2", and etc represent n-th bracketed patterns. |
int32_t tkrzw_str_edit_distance_lev | ( | const char * | a, |
const char * | b, | ||
bool | utf | ||
) |
Gets the Levenshtein edit distance of two strings.
a | A string. |
b | The other string. |
utf | If true, text is treated as UTF-8. If false, it is treated as raw bytes. |
uint64_t tkrzw_str_to_int_be | ( | const void * | ptr, |
size_t | size | ||
) |
Converts a big-endian binary string to an integer.
ptr | The pointer to the string to convert. |
size | The size of the string to convert. |
long double tkrzw_str_to_float_be | ( | const void * | ptr, |
size_t | size | ||
) |
Converts a big-endian binary string to a floating-point number.
ptr | The pointer to the string to convert. |
size | The size of the string to convert. |
char* tkrzw_int_to_str_be | ( | uint64_t | data, |
size_t | size | ||
) |
Converts an integer into a big-endian binary string.
data | The integer to convert. |
size | The size of the converted string. |
char* tkrzw_float_to_str_be | ( | long double | data, |
size_t | size | ||
) |
Converts a floating-point number into a big-endian binary string.
data | The floating-point number to convert. |
size | The size of the converted string. |
char* tkrzw_str_escape_c | ( | const char * | ptr, |
int32_t | size, | ||
bool | esc_nonasc, | ||
int32_t * | res_size | ||
) |
Escapes C-style meta characters in a string.
ptr | The pointer to the string to convert. |
size | The size of the string to convert. If it is negative, strlen(ptr) is used. |
esc_nonasc | If true, non-ASCII characters are excaped. |
res_size | The pointer to the variable to store the result string size. If it is NULL, it is not used. |
char* tkrzw_str_unescape_c | ( | const char * | ptr, |
int32_t | size, | ||
int32_t * | res_size | ||
) |
Unescapes C-style escape sequences in a string.
ptr | The pointer to the string to convert. |
size | The size of the string to convert. If it is negative, strlen(ptr) is used. |
res_size | The pointer to the variable to store the result string size. If it is NULL, it is not used. |
char* tkrzw_str_append | ( | char * | modified, |
const char * | appended | ||
) |
Appends a string at the end of another allocated string.
modified | The string to be modified. It must be allocated by malloc. The ownership is taken. If it is NULL, a new string is allocated. |
appended | The string to be appended at the end. |
void tkrzw_future_free | ( | TkrzwFuture * | future | ) |
Releases the future object.
future | The future object. |
bool tkrzw_future_wait | ( | TkrzwFuture * | future, |
double | timeout | ||
) |
Waits for the operation of the future object to be done.
future | The future object. |
timeout | The waiting time in seconds. If it is negative, no timeout is set. |
void tkrzw_future_get | ( | TkrzwFuture * | future | ) |
Gets the status of the operation of the future object.
future | the future object. |
The status is set as the last system operation status so the data can be accessed by the tkrzw_get_last_status and so on. This can be called with the future which is associated to the single status without any extra data. This can be called only once for each future. object.
char* tkrzw_future_get_str | ( | TkrzwFuture * | future, |
int32_t * | size | ||
) |
Gets the status and the extra string data of the operation of the future object.
future | the future object. |
size | The pointer to the variable to store the extra string size. If it is NULL, it is not used. |
The status is set as the last system operation status so the data can be accessed by the tkrzw_get_last_status and so on. This can be called with the future which is associated to the status with an extra string data. This can be called only once for each future. object.
TkrzwKeyValuePair* tkrzw_future_get_str_pair | ( | TkrzwFuture * | future | ) |
Gets the status and the extra string pair of the operation of the future object.
future | the future object. |
The status is set as the last system operation status so the data can be accessed by the tkrzw_get_last_status and so on. This can be called with the future which is associated to the status with an extra string pair. This can be called only once for each future. object.
TkrzwStr* tkrzw_future_get_str_array | ( | TkrzwFuture * | future, |
int32_t * | num_elems | ||
) |
Gets the status and the extra string array of the operation of the future object.
future | the future object. |
num_elems | The pointer to the variable to store the number of elements of the extra string array. |
The status is set as the last system operation status so the data can be accessed by the tkrzw_get_last_status and so on. This can be called with the future which is associated to the status with an extra string array. This can be called only once for each future. object.
TkrzwKeyValuePair* tkrzw_future_get_str_map | ( | TkrzwFuture * | future, |
int32_t * | num_elems | ||
) |
Gets the status and the extra string map of the operation of the future object.
future | the future object. |
num_elems | The pointer to the variable to store the number of elements of the extra string map. |
The status is set as the last system operation status so the data can be accessed by the tkrzw_get_last_status and so on. This can be called with the future which is associated to the status with an extra string map. This can be called only once for each future. object.
int64_t tkrzw_future_get_int | ( | TkrzwFuture * | future | ) |
Gets the status and the extra integer data of the operation of the future object.
future | the future object. |
The status is set as the last system operation status so the data can be accessed by the tkrzw_get_last_status and so on. This can be called with the future which is associated to the status with an extra integer data. This can be called only once for each future. object.
TkrzwDBM* tkrzw_dbm_open | ( | const char * | path, |
bool | writable, | ||
const char * | params | ||
) |
Opens a database file and makes a database object.
path | A path of the file. |
writable | If true, the file is writable. If false, it is read-only. |
params | Optional parameters in "key=value,key=value" format. The options for the file opening operation are set by "truncate", "no_create", "no_wait", "no_lock", and "sync_hard". The option for the number of shards is set by "num_shards". Other options are the same as PolyDBM::OpenAdvanced. |
bool tkrzw_dbm_close | ( | TkrzwDBM * | dbm | ) |
Closes the database file and releases the database object.
dbm | The database object. |
bool tkrzw_dbm_process | ( | TkrzwDBM * | dbm, |
const char * | key_ptr, | ||
int32_t | key_size, | ||
tkrzw_record_processor | proc, | ||
void * | proc_arg, | ||
bool | writable | ||
) |
Processes a record with callback functions.
dbm | The database object. |
key_ptr | The key pointer. |
key_size | The key size. If it is negative, strlen(key_ptr) is used. |
proc | The callback function to process the record. |
proc_arg | An arbitrary data which is given to the callback function. |
writable | True if the processor can edit the record. |
If the specified record exists, the value is given to the callback function. If it doesn't exist, NULL is given instead. The callback function returns TKRZW_REC_PROC_NOOP to keep the current value, TKRZW_REC_PROC_REMOVE to remove the record, or a string pointer to a new value to set. The ownership of the return value is not taken.
bool tkrzw_dbm_check | ( | TkrzwDBM * | dbm, |
const char * | key_ptr, | ||
int32_t | key_size | ||
) |
Checks if a record exists or not.
dbm | The database object. |
key_ptr | The key pointer. |
key_size | The key size. If it is negative, strlen(key_ptr) is used. |
char* tkrzw_dbm_get | ( | TkrzwDBM * | dbm, |
const char * | key_ptr, | ||
int32_t | key_size, | ||
int32_t * | value_size | ||
) |
Gets the value of a record of a key.
dbm | The database object. |
key_ptr | The key pointer. |
key_size | The key size. If it is negative, strlen(key_ptr) is used. |
value_size | The pointer to the variable to store the value size. If it is NULL, it is not used. |
If there's no matching record, NOT_FOUND_ERROR status code is set.
TkrzwKeyValuePair* tkrzw_dbm_get_multi | ( | TkrzwDBM * | dbm, |
const TkrzwStr * | keys, | ||
int32_t | num_keys, | ||
int32_t * | num_matched | ||
) |
Gets the values of multiple records of keys.
dbm | The database object. |
keys | An array of the keys of records to retrieve. |
num_keys | The number of elements of the key array. |
num_matched | The pointer to the variable to store the number of the elements of the return value. |
bool tkrzw_dbm_set | ( | TkrzwDBM * | dbm, |
const char * | key_ptr, | ||
int32_t | key_size, | ||
const char * | value_ptr, | ||
int32_t | value_size, | ||
bool | overwrite | ||
) |
Sets a record of a key and a value.
dbm | The database object. |
key_ptr | The key pointer. |
key_size | The key size. If it is negative, strlen(key_ptr) is used. |
value_ptr | The value pointer. |
value_size | The value size. If it is negative, strlen(value_ptr) is used. |
overwrite | Whether to overwrite the existing value if there's a record with the same key. If true, the existing value is overwritten by the new value. If false, the operation is given up and an error status is set. |
If overwriting is abandoned, DUPLICATION_ERROR status code is set.
char* tkrzw_dbm_set_and_get | ( | TkrzwDBM * | dbm, |
const char * | key_ptr, | ||
int32_t | key_size, | ||
const char * | value_ptr, | ||
int32_t | value_size, | ||
bool | overwrite, | ||
int32_t * | old_value_size | ||
) |
Sets a record and get the old value.
dbm | The database object. |
key_ptr | The key pointer. |
key_size | The key size. If it is negative, strlen(key_ptr) is used. |
value_ptr | The new value pointer. |
value_size | The new value size. If it is negative, strlen(value_ptr) is used. |
overwrite | Whether to overwrite the existing value if there's a record with the same key. If true, the existing value is overwritten by the new value. If false, the operation is given up and an error status is set. |
old_value_size | The pointer to the variable to store the value size. If it is NULL, it is not used. |
If overwriting is abandoned, DUPLICATION_ERROR status code is set.
bool tkrzw_dbm_set_multi | ( | TkrzwDBM * | dbm, |
const TkrzwKeyValuePair * | records, | ||
int32_t | num_records, | ||
bool | overwrite | ||
) |
Sets multiple records.
dbm | The database object. |
records | An array of the key-value pairs of records to store. |
num_records | The number of elements of the record array. |
overwrite | Whether to overwrite the existing value if there's a record with the same key. If true, the existing value is overwritten by the new value. If false, the operation is given up and an error status is set. |
bool tkrzw_dbm_remove | ( | TkrzwDBM * | dbm, |
const char * | key_ptr, | ||
int32_t | key_size | ||
) |
Removes a record of a key.
dbm | The database object. |
key_ptr | The key pointer. |
key_size | The key size. If it is negative, strlen(key_ptr) is used. |
If there's no matching record, NOT_FOUND_ERROR status code is set.
char* tkrzw_dbm_remove_and_get | ( | TkrzwDBM * | dbm, |
const char * | key_ptr, | ||
int32_t | key_size, | ||
int32_t * | value_size | ||
) |
Removes a record and get the value.
dbm | The database object. |
key_ptr | The key pointer. |
key_size | The key size. If it is negative, strlen(key_ptr) is used. |
value_size | The pointer to the variable to store the value size. If it is NULL, it is not used. |
If there's no matching record, NOT_FOUND_ERROR status code is set.
Removes records of keys.
dbm | The database object. |
keys | An array of the keys of records to retrieve. |
num_keys | The number of elements of the key array. |
bool tkrzw_dbm_append | ( | TkrzwDBM * | dbm, |
const char * | key_ptr, | ||
int32_t | key_size, | ||
const char * | value_ptr, | ||
int32_t | value_size, | ||
const char * | delim_ptr, | ||
int32_t | delim_size | ||
) |
Appends data at the end of a record of a key.
dbm | The database object. |
key_ptr | The key pointer. |
key_size | The key size. If it is negative, strlen(key_ptr) is used. |
value_ptr | The value pointer. |
value_size | The value size. If it is negative, strlen(value_ptr) is used. |
delim_ptr | The delimiter pointer. |
delim_size | The delimiter size. If it is negative, strlen(delim_ptr) is used. |
If there's no existing record, the value is set without the delimiter.
bool tkrzw_dbm_append_multi | ( | TkrzwDBM * | dbm, |
const TkrzwKeyValuePair * | records, | ||
int32_t | num_records, | ||
const char * | delim_ptr, | ||
int32_t | delim_size | ||
) |
Appends data to multiple records.
dbm | The database object. |
records | An array of the key-value pairs of records to append. |
num_records | The number of elements of the record array. |
delim_ptr | The delimiter pointer. |
delim_size | The delimiter size. If it is negative, strlen(delim_ptr) is used. |
If there's no existing record, the value is set without the delimiter.
bool tkrzw_dbm_compare_exchange | ( | TkrzwDBM * | dbm, |
const char * | key_ptr, | ||
int32_t | key_size, | ||
const char * | expected_ptr, | ||
int32_t | expected_size, | ||
const char * | desired_ptr, | ||
int32_t | desired_size | ||
) |
Compares the value of a record and exchanges if the condition meets.
dbm | The database object. |
key_ptr | The key pointer. |
key_size | The key size. If it is negative, strlen(key_ptr) is used. |
expected_ptr | The expected value pointer. If it is NULL, no existing record is expected. If it is TKRZW_ANY_DATA, an existing record with any value is expacted. |
expected_size | The expected value size. If it is negative, strlen(expected_ptr) is used. |
desired_ptr | The desired value pointer. If it is NULL, the record is to be removed. expected. If it is TKRZW_ANY_DATA, no update is done. |
desired_size | The desired value size. If it is negative, strlen(desired_ptr) is used. |
If the condition doesn't meet, INFEASIBLE_ERROR status code is set.
char* tkrzw_dbm_compare_exchange_and_get | ( | TkrzwDBM * | dbm, |
const char * | key_ptr, | ||
int32_t | key_size, | ||
const char * | expected_ptr, | ||
int32_t | expected_size, | ||
const char * | desired_ptr, | ||
int32_t | desired_size, | ||
int32_t * | actual_size | ||
) |
Does compare-and-exchange and/or gets the old value of the record.
dbm | The database object. |
key_ptr | The key pointer. |
key_size | The key size. If it is negative, strlen(key_ptr) is used. |
expected_ptr | The expected value pointer. If it is NULL, no existing record is expected. If it is TKRZW_ANY_DATA, an existing record with any value is expacted. |
expected_size | The expected value size. If it is negative, strlen(expected_ptr) is used. |
desired_ptr | The desired value pointer. If it is NULL, the record is to be removed. expected. If it is TKRZW_ANY_DATA, no update is done. |
desired_size | The desired value size. If it is negative, strlen(desired_ptr) is used. |
actual_size | The pointer to the variable to store the value size. If it is NULL, it is not used. |
If the condition doesn't meet, INFEASIBLE_ERROR status code is set.
int64_t tkrzw_dbm_increment | ( | TkrzwDBM * | dbm, |
const char * | key_ptr, | ||
int32_t | key_size, | ||
int64_t | increment, | ||
int64_t | initial | ||
) |
Increments the numeric value of a record.
dbm | The database object. |
key_ptr | The key pointer. |
key_size | The key size. If it is negative, strlen(key_ptr) is used. |
increment | The incremental value. If it is TKRZW_INT64MIN, the current value is not changed and a new record is not created. |
initial | The initial value. |
The record value is stored as an 8-byte big-endian integer. Negative is also supported.
bool tkrzw_dbm_process_multi | ( | TkrzwDBM * | dbm, |
TkrzwKeyProcPair * | key_proc_pairs, | ||
int32_t | num_pairs, | ||
bool | writable | ||
) |
Processes multiple records with processors.
dbm | The database object. |
key_proc_pairs | An array of pairs of the keys and their processor functions. |
num_pairs | The number of the array. |
writable | True if the processors can edit the records. |
If the specified record exists, the value is given to the callback function. If it doesn't exist, NULL is given instead. The callback function returns TKRZW_REC_PROC_NOOP to keep the current value, TKRZW_REC_PROC_REMOVE to remove the record, or a string pointer to a new value to set. The ownership of the return value is not taken.
bool tkrzw_dbm_compare_exchange_multi | ( | TkrzwDBM * | dbm, |
const TkrzwKeyValuePair * | expected, | ||
int32_t | num_expected, | ||
const TkrzwKeyValuePair * | desired, | ||
int32_t | num_desired | ||
) |
Compares the values of records and exchanges if the condition meets.
dbm | The database object. |
expected | An array of the record keys and their expected values. If the value is NULL, no existing record is expected. If the value is TKRZW_ANY_DATA, an existing record with any value is expacted. |
num_expected | The number of the expected array. |
desired | An array of the record keys and their desired values. If the value is NULL, the record is to be removed. |
num_desired | The number of the desired array. |
If the condition doesn't meet, INFEASIBLE_ERROR is returned.
bool tkrzw_dbm_rekey | ( | TkrzwDBM * | dbm, |
const char * | old_key_ptr, | ||
int32_t | old_key_size, | ||
const char * | new_key_ptr, | ||
int32_t | new_key_size, | ||
bool | overwrite, | ||
bool | copying | ||
) |
Changes the key of a record.
dbm | The database object. |
old_key_ptr | The old key pointer. |
old_key_size | The old key size. If it is negative, strlen(old_key_ptr) is used. |
new_key_ptr | The new key pointer. |
new_key_size | The new key size. If it is negative, strlen(new_key_ptr) is used. |
overwrite | Whether to overwrite the existing record of the new key. |
copying | Whether to retain the record of the old key. |
If there's no matching record to the old key, NOT_FOUND_ERROR is set. If the overwrite flag is false and there is an existing record of the new key, DUPLICATION ERROR is set. This method is done atomically by ProcessMulti. The other threads observe that the record has either the old key or the new key. No intermediate states are observed.
bool tkrzw_dbm_process_first | ( | TkrzwDBM * | dbm, |
tkrzw_record_processor | proc, | ||
void * | proc_arg, | ||
bool | writable | ||
) |
Processes the first record with a processor.
dbm | The database object. |
proc | The callback function to process the record. |
proc_arg | An arbitrary data which is given to the callback function. |
writable | True if the processor can edit the record. |
If the first record exists, the callback function is called. Otherwise, this method fails and the callback is not called. If the callback function returns TKRZW_REC_PROC_NOOP, TKRZW_REC_PROC_REMOVE, or a string pointer to a new value, whose ownership is not taken.
bool tkrzw_dbm_pop_first | ( | TkrzwDBM * | dbm, |
char ** | key_ptr, | ||
int32_t * | key_size, | ||
char ** | value_ptr, | ||
int32_t * | value_size | ||
) |
Gets the first record and removes it.
dbm | The database object. |
key_ptr | The pointer to a variable which points to the region containing the record key. If this function returns true, the region should be released by the free function. If it is NULL, it is not used. |
key_size | The pointer to a variable which stores the size of the region containing the record key. If it is NULL, it is not used. |
value_ptr | The pointer to a variable which points to the region containing the record value. If this function returns true, the region should be released by the free function. If it is NULL, it is not used. |
value_size | The pointer to a variable which stores the size of the region containing the record value. If it is NULL, it is not used. |
bool tkrzw_dbm_push_last | ( | TkrzwDBM * | dbm, |
const char * | value_ptr, | ||
int32_t | value_size, | ||
double | wtime | ||
) |
Adds a record with a key of the current timestamp.
dbm | The database object. |
value_ptr | The value pointer. |
value_size | The value size. If it is negative, strlen(value_ptr) is used. |
wtime | The current wall time used to generate the key. If it is negative, the system clock is used. |
The key is generated as an 8-bite big-endian binary string of the timestamp. If there is an existing record matching the generated key, the key is regenerated and the attempt is repeated until it succeeds.
bool tkrzw_dbm_process_each | ( | TkrzwDBM * | dbm, |
tkrzw_record_processor | proc, | ||
void * | proc_arg, | ||
bool | writable | ||
) |
Processes each and every record in the database with a processor.
dbm | The database object. |
proc | The callback function to process the record. |
proc_arg | An arbitrary data which is given to the callback function. |
writable | True if the processor can edit the record. |
If the specified record exists, the value is given to the callback function. If it doesn't exist, NULL is given instead. The callback function returns TKRZW_REC_PROC_NOOP to keep the current value, TKRZW_REC_PROC_REMOVE to remove the record, or a string pointer to a new value to set. The ownership of the return value is not taken. It is also called once before the iteration and once after the iteration with both the key and the value being NULL.
int64_t tkrzw_dbm_count | ( | TkrzwDBM * | dbm | ) |
Gets the number of records.
dbm | The database object. |
int64_t tkrzw_dbm_get_file_size | ( | TkrzwDBM * | dbm | ) |
Gets the current file size of the database.
dbm | The database object. |
char* tkrzw_dbm_get_file_path | ( | TkrzwDBM * | dbm | ) |
Gets the path of the database file.
dbm | The database object. |
double tkrzw_dbm_get_timestamp | ( | TkrzwDBM * | dbm | ) |
Gets the timestamp in seconds of the last modified time.
dbm | The database object. |
bool tkrzw_dbm_clear | ( | TkrzwDBM * | dbm | ) |
Removes all records.
dbm | The database object. |
bool tkrzw_dbm_rebuild | ( | TkrzwDBM * | dbm, |
const char * | params | ||
) |
Rebuilds the entire database.
dbm | The database object. |
params | Optional parameters in "key=value,key=value" format. The parameters work in the same way as with PolyDBM::RebuildAdvanced. |
bool tkrzw_dbm_should_be_rebuilt | ( | TkrzwDBM * | dbm | ) |
Checks whether the database should be rebuilt.
bool tkrzw_dbm_synchronize | ( | TkrzwDBM * | dbm, |
bool | hard, | ||
tkrzw_file_processor | proc, | ||
void * | proc_arg, | ||
const char * | params | ||
) |
Synchronizes the content of the database to the file system.
dbm | The database object. |
hard | True to do physical synchronization with the hardware or false to do only logical synchronization with the file system. |
proc | The callback function to process the file, which is called while the content of the file is synchronized. If it is NULL, it is ignored. |
proc_arg | An arbitrary data which is given to the callback function. |
params | Optional parameters in "key=value,key=value" format. The parameters work in the same way as with PolyDBM::OpenAdvanced. |
bool tkrzw_dbm_copy_file_data | ( | TkrzwDBM * | dbm, |
const char * | dest_path, | ||
bool | sync_hard | ||
) |
Copies the content of the database files to other files.
dbm | The database object. |
dest_path | The path prefix to the destination files. |
sync_hard | True to do physical synchronization with the hardware. |
Copying is done while the content is synchronized and stable. So, this method is suitable for making a backup file while running a database service.
Exports all records to another database.
dbm | The database object. |
dest_dbm | The destination database object. |
Exports all records of a database to a flat record file.
dbm | The database object. |
dest_file | The file object to write records in. |
Imports records to a database from a flat record file.
dbm | The database object. |
src_file | The file object to read records from. |
Exports the keys of all records of a database as lines to a text file.
dbm | The database object of the database. |
dest_file | The file object to write keys in. |
TkrzwKeyValuePair* tkrzw_dbm_inspect | ( | TkrzwDBM * | dbm, |
int32_t * | num_records | ||
) |
Inspects the database.
dbm | The database object. |
num_records | The pointer to the variable to store the number of the elements of the return value. |
bool tkrzw_dbm_is_writable | ( | TkrzwDBM * | dbm | ) |
Checks whether the database is writable.
dbm | The database object. |
bool tkrzw_dbm_is_healthy | ( | TkrzwDBM * | dbm | ) |
Checks whether the database condition is healthy.
dbm | The database object. |
bool tkrzw_dbm_is_ordered | ( | TkrzwDBM * | dbm | ) |
Checks whether ordered operations are supported.
dbm | The database object. |
TkrzwStr* tkrzw_dbm_search | ( | TkrzwDBM * | dbm, |
const char * | mode, | ||
const char * | pattern_ptr, | ||
int32_t | pattern_size, | ||
int32_t | capacity, | ||
int32_t * | num_matched | ||
) |
Searches a database and get keys which match a pattern, according to a mode expression.
dbm | The database object. |
mode | The search mode. "contain" extracts keys containing the pattern. "begin" extracts keys beginning with the pattern. "end" extracts keys ending with the pattern. "regex" extracts keys partially matches the pattern of a regular expression. "edit" extracts keys whose edit distance to the pattern is the least. "editbin" extracts keys whose edit distance to the binary pattern is the least. "containcase", "containword", and "containcaseword" extract keys considering case and word boundary. "contain*", "containcase*", "containword*", and "containcaseword*" take a null-code-separatable pattern and do batch operations for each element. Ordered databases support "upper" and "lower" which extract keys whose positions are equal to or upper/lower than the pattern. "upperex" and "lowerex" are their exclusive versions. |
pattern_ptr | The pattern pointer. |
pattern_size | The pattern size. If it is negative, strlen(pattern_ptr) is used. |
capacity | The maximum records to obtain. 0 means unlimited. |
num_matched | The pointer to the variable to store the number of the element of the return value. |
TkrzwDBMIter* tkrzw_dbm_make_iterator | ( | TkrzwDBM * | dbm | ) |
Makes an iterator for each record.
dbm | The database object. |
void tkrzw_dbm_iter_free | ( | TkrzwDBMIter * | iter | ) |
Releases the iterator object.
iter | The iterator object. |
bool tkrzw_dbm_iter_first | ( | TkrzwDBMIter * | iter | ) |
Initializes the iterator to indicate the first record.
iter | The iterator object. |
Even if there's no record, the operation doesn't fail.
bool tkrzw_dbm_iter_last | ( | TkrzwDBMIter * | iter | ) |
Initializes the iterator to indicate the last record.
iter | The iterator object. |
Even if there's no record, the operation doesn't fail. This method is suppoerted only by ordered databases.
bool tkrzw_dbm_iter_jump | ( | TkrzwDBMIter * | iter, |
const char * | key_ptr, | ||
int32_t | key_size | ||
) |
Initializes the iterator to indicate a specific record.
iter | The iterator object. |
key_ptr | The key pointer. |
key_size | The key size. If it is negative, strlen(key_ptr) is used. |
Ordered databases can support "lower bound" jump; If there's no record with the same key, the iterator refers to the first record whose key is greater than the given key. The operation fails with unordered databases if there's no record with the same key.
bool tkrzw_dbm_iter_jump_lower | ( | TkrzwDBMIter * | iter, |
const char * | key_ptr, | ||
int32_t | key_size, | ||
bool | inclusive | ||
) |
Initializes the iterator to indicate the last record whose key is lower than a given key.
iter | The iterator object. |
key_ptr | The key pointer. |
key_size | The key size. If it is negative, strlen(key_ptr) is used. |
inclusive | If true, the condition is inclusive: equal to or lower than the key. |
Even if there's no matching record, the operation doesn't fail. This method is suppoerted only by ordered databases.
bool tkrzw_dbm_iter_jump_upper | ( | TkrzwDBMIter * | iter, |
const char * | key_ptr, | ||
int32_t | key_size, | ||
bool | inclusive | ||
) |
Initializes the iterator to indicate the first record whose key is upper than a given key.
iter | The iterator object. |
key_ptr | The key pointer. |
key_size | The key size. If it is negative, strlen(key_ptr) is used. |
inclusive | If true, the condition is inclusive: equal to or upper than the key. |
Even if there's no matching record, the operation doesn't fail. This method is suppoerted only by ordered databases.
bool tkrzw_dbm_iter_next | ( | TkrzwDBMIter * | iter | ) |
Moves the iterator to the next record.
iter | The iterator object. |
If the current record is missing, the operation fails. Even if there's no next record, the operation doesn't fail.
bool tkrzw_dbm_iter_previous | ( | TkrzwDBMIter * | iter | ) |
Moves the iterator to the previous record.
iter | The iterator object. |
If the current record is missing, the operation fails. Even if there's no previous record, the operation doesn't fail. This method is suppoerted only by ordered databases.
bool tkrzw_dbm_iter_process | ( | TkrzwDBMIter * | iter, |
tkrzw_record_processor | proc, | ||
void * | proc_arg, | ||
bool | writable | ||
) |
Processes the current record with a processor.
iter | The iterator object. |
proc | The callback function to process the record. |
proc_arg | An arbitrary data which is given to the callback function. |
writable | True if the processor can edit the record. |
If the current record exists, the callback function is called. Otherwise, this method fails and the callback is not called. The callback function returns TKRZW_REC_PROC_NOOP to keep the current value, TKRZW_REC_PROC_REMOVE to remove the record, or a string pointer to a new value to set. The ownership of the return value is not taken. If the current record is removed, the iterator is moved to the next record.
bool tkrzw_dbm_iter_get | ( | TkrzwDBMIter * | iter, |
char ** | key_ptr, | ||
int32_t * | key_size, | ||
char ** | value_ptr, | ||
int32_t * | value_size | ||
) |
Gets the key and the value of the current record of the iterator.
iter | The iterator object. |
key_ptr | The pointer to a variable which points to the region containing the record key. If this function returns true, the region should be released by the free function. If it is NULL, it is not used. |
key_size | The pointer to a variable which stores the size of the region containing the record key. If it is NULL, it is not used. |
value_ptr | The pointer to a variable which points to the region containing the record value. If this function returns true, the region should be released by the free function. If it is NULL, it is not used. |
value_size | The pointer to a variable which stores the size of the region containing the record value. If it is NULL, it is not used. |
char* tkrzw_dbm_iter_get_key | ( | TkrzwDBMIter * | iter, |
int32_t * | key_size | ||
) |
Gets the key of the current record, in a simple way.
iter | The iterator object. |
key_size | The pointer to the variable to store the key size. If it is NULL, it is not used. |
char* tkrzw_dbm_iter_get_value | ( | TkrzwDBMIter * | iter, |
int32_t * | value_size | ||
) |
Gets the key of the current record, in a simple way.
iter | The iterator object. |
value_size | The pointer to the variable to store the value size. If it is NULL, it is not used. |
bool tkrzw_dbm_iter_set | ( | TkrzwDBMIter * | iter, |
const char * | value_ptr, | ||
int32_t | value_size | ||
) |
Sets the value of the current record.
iter | The iterator object. |
value_ptr | The value pointer. |
value_size | The value size. If it is negative, strlen(value_ptr) is used. |
bool tkrzw_dbm_iter_remove | ( | TkrzwDBMIter * | iter | ) |
Removes the current record.
If possible, the iterator moves to the next record.
bool tkrzw_dbm_iter_step | ( | TkrzwDBMIter * | iter, |
char ** | key_ptr, | ||
int32_t * | key_size, | ||
char ** | value_ptr, | ||
int32_t * | value_size | ||
) |
Gets the current record and moves the iterator to the next record.
iter | The iterator object. |
key_ptr | The pointer to a variable which points to the region containing the record key. If this function returns true, the region should be released by the free function. If it is NULL, it is not used. |
key_size | The pointer to a variable which stores the size of the region containing the record key. If it is NULL, it is not used. |
value_ptr | The pointer to a variable which points to the region containing the record value. If this function returns true, the region should be released by the free function. If it is NULL, it is not used. |
value_size | The pointer to a variable which stores the size of the region containing the record value. If it is NULL, it is not used. |
bool tkrzw_dbm_restore_database | ( | const char * | old_file_path, |
const char * | new_file_path, | ||
const char * | class_name, | ||
int64_t | end_offset, | ||
const char * | cipher_key | ||
) |
Restores a broken database as a new healthy database.
old_file_path | The path of the broken database. |
new_file_path | The path of the new database to be created. |
class_name | The name of the database class. If it is NULL or empty, the class is guessed from the file extension. |
end_offset | The exclusive end offset of records to read. Negative means unlimited. 0 means the size when the database is synched or closed properly. Using a positive value is not meaningful if the number of shards is more than one. |
cipher_key | The encryption key for cipher compressors. If it is NULL, an empty key is used. |
TkrzwAsyncDBM* tkrzw_async_dbm_new | ( | TkrzwDBM * | dbm, |
int32_t | num_worker_threads | ||
) |
Creates an asynchronous database adapter.
dbm | A database object which has been opened. The ownership is not taken. |
num_worker_threads | The number of threads in the internal thread pool. |
This class is a wrapper of DBM for asynchronous operations. A task queue with a thread pool is used inside. Every methods except for the constructor and the destructor are run by a thread in the thread pool and the result is set in the future oject of the return value. While the caller should release the returned future object, it can omit evaluation of the result status if it is not interesting. The destructor of this asynchronous database manager waits for all tasks to be done. Therefore, the destructor should be called before the database is closed. Asynchronous functions which take pointers to C-strings copies the regions of them so the caller doesn't have to expand the lifetime of them.
void tkrzw_async_dbm_free | ( | TkrzwAsyncDBM * | async | ) |
Releases the asynchronous database adapter.
async | the asynchronous database adapter. |
TkrzwFuture* tkrzw_async_dbm_get | ( | TkrzwAsyncDBM * | async, |
const char * | key_ptr, | ||
int32_t | key_size | ||
) |
Gets the value of a record of a key asynchronously.
async | the asynchronous database adapter. |
key_ptr | The key pointer. |
key_size | The key size. If it is negative, strlen(key_ptr) is used. |
If there's no matching record, NOT_FOUND_ERROR status code is set.
TkrzwFuture* tkrzw_async_dbm_get_multi | ( | TkrzwAsyncDBM * | async, |
const TkrzwStr * | keys, | ||
int32_t | num_keys | ||
) |
Gets the values of multiple records of keys asynchronously.
async | the asynchronous database adapter. |
keys | An array of the keys of records to retrieve. |
num_keys | The number of elements of the key array. |
TkrzwFuture* tkrzw_async_dbm_set | ( | TkrzwAsyncDBM * | async, |
const char * | key_ptr, | ||
int32_t | key_size, | ||
const char * | value_ptr, | ||
int32_t | value_size, | ||
bool | overwrite | ||
) |
Sets a record of a key and a value asynchronously.
async | the asynchronous database adapter. |
key_ptr | The key pointer. |
key_size | The key size. If it is negative, strlen(key_ptr) is used. |
value_ptr | The value pointer. |
value_size | The value size. If it is negative, strlen(value_ptr) is used. |
overwrite | Whether to overwrite the existing value if there's a record with the same key. If true, the existing value is overwritten by the new value. If false, the operation is given up and an error status is set. |
If overwriting is abandoned, DUPLICATION_ERROR status code is set.
TkrzwFuture* tkrzw_async_dbm_set_multi | ( | TkrzwAsyncDBM * | async, |
const TkrzwKeyValuePair * | records, | ||
int32_t | num_records, | ||
bool | overwrite | ||
) |
Sets multiple records asynchronously.
async | the asynchronous database adapter. |
records | An array of the key-value pairs of records to store. |
num_records | The number of elements of the record array. |
overwrite | Whether to overwrite the existing value if there's a record with the same key. If true, the existing value is overwritten by the new value. If false, the operation is given up and an error status is set. |
If overwriting is abandoned, DUPLICATION_ERROR status code is set.
TkrzwFuture* tkrzw_async_dbm_remove | ( | TkrzwAsyncDBM * | async, |
const char * | key_ptr, | ||
int32_t | key_size | ||
) |
Removes a record of a key asynchronously.
async | the asynchronous database adapter. |
key_ptr | The key pointer. |
key_size | The key size. If it is negative, strlen(key_ptr) is used. |
If there's no matching record, NOT_FOUND_ERROR status code is set.
TkrzwFuture* tkrzw_async_dbm_remove_multi | ( | TkrzwAsyncDBM * | async, |
const TkrzwStr * | keys, | ||
int32_t | num_keys | ||
) |
Removes records of keys asynchronously.
async | the asynchronous database adapter. |
keys | An array of the keys of records to retrieve. |
num_keys | The number of elements of the key array. |
If there are missing records, NOT_FOUND_ERROR status code is set.
TkrzwFuture* tkrzw_async_dbm_append | ( | TkrzwAsyncDBM * | async, |
const char * | key_ptr, | ||
int32_t | key_size, | ||
const char * | value_ptr, | ||
int32_t | value_size, | ||
const char * | delim_ptr, | ||
int32_t | delim_size | ||
) |
Appends data at the end of a record of a key asynchronously.
async | the asynchronous database adapter. |
key_ptr | The key pointer. |
key_size | The key size. If it is negative, strlen(key_ptr) is used. |
value_ptr | The value pointer. |
value_size | The value size. If it is negative, strlen(value_ptr) is used. |
delim_ptr | The delimiter pointer. |
delim_size | The delimiter size. If it is negative, strlen(delim_ptr) is used. |
If there's no existing record, the value is set without the delimiter.
TkrzwFuture* tkrzw_async_dbm_append_multi | ( | TkrzwAsyncDBM * | async, |
const TkrzwKeyValuePair * | records, | ||
int32_t | num_records, | ||
const char * | delim_ptr, | ||
int32_t | delim_size | ||
) |
Appends data to multiple records asynchronously.
async | the asynchronous database adapter. |
records | An array of the key-value pairs of records to append. |
num_records | The number of elements of the record array. |
delim_ptr | The delimiter pointer. |
delim_size | The delimiter size. If it is negative, strlen(delim_ptr) is used. |
If there's no existing record, the value is set without the delimiter.
TkrzwFuture* tkrzw_async_dbm_compare_exchange | ( | TkrzwAsyncDBM * | async, |
const char * | key_ptr, | ||
int32_t | key_size, | ||
const char * | expected_ptr, | ||
int32_t | expected_size, | ||
const char * | desired_ptr, | ||
int32_t | desired_size | ||
) |
Compares the value of a record and exchanges if the condition meets asynchronously.
async | the asynchronous database adapter. |
key_ptr | The key pointer. |
key_size | The key size. If it is negative, strlen(key_ptr) is used. |
expected_ptr | The expected value pointer. If it is NULL, no existing record is expected. If it is TKRZW_ANY_DATA, an existing record with any value is expacted. |
expected_size | The expected value size. If it is negative, strlen(expected_ptr) is used. |
desired_ptr | The desired value pointer. If it is NULL, the record is to be removed. expected. If it is TKRZW_ANY_DATA, no update is done. |
desired_size | The desired value size. If it is negative, strlen(desired_ptr) is used. |
If the condition doesn't meet, INFEASIBLE_ERROR status code is set.
TkrzwFuture* tkrzw_async_dbm_increment | ( | TkrzwAsyncDBM * | async, |
const char * | key_ptr, | ||
int32_t | key_size, | ||
int64_t | increment, | ||
int64_t | initial | ||
) |
Increments the numeric value of a record asynchronously.
async | the asynchronous database adapter. |
key_ptr | The key pointer. |
key_size | The key size. If it is negative, strlen(key_ptr) is used. |
increment | The incremental value. If it is TKRZW_INT64MIN, the current value is not changed and a new record is not created. |
initial | The initial value. |
The record value is stored as an 8-byte big-endian integer. Negative is also supported.
TkrzwFuture* tkrzw_async_dbm_compare_exchange_multi | ( | TkrzwAsyncDBM * | async, |
const TkrzwKeyValuePair * | expected, | ||
int32_t | num_expected, | ||
const TkrzwKeyValuePair * | desired, | ||
int32_t | num_desired | ||
) |
Compares the values of records and exchanges if the condition meets asynchronously.
async | the asynchronous database adapter. |
expected | An array of the record keys and their expected values. If the value is NULL, no existing record is expected. If the value is TKRZW_ANY_DATA, an existing record with any value is expacted. |
num_expected | The number of the expected array. |
desired | An array of the record keys and their desired values. If the value is NULL, the record is to be removed. |
num_desired | The number of the desired array. |
If the condition doesn't meet, INFEASIBLE_ERROR is returned.
TkrzwFuture* tkrzw_async_dbm_rekey | ( | TkrzwAsyncDBM * | async, |
const char * | old_key_ptr, | ||
int32_t | old_key_size, | ||
const char * | new_key_ptr, | ||
int32_t | new_key_size, | ||
bool | overwrite, | ||
bool | copying | ||
) |
Changes the key of a record asynchronously.
async | the asynchronous database adapter. |
old_key_ptr | The old key pointer. |
old_key_size | The old key size. If it is negative, strlen(old_key_ptr) is used. |
new_key_ptr | The new key pointer. |
new_key_size | The new key size. If it is negative, strlen(new_key_ptr) is used. |
overwrite | Whether to overwrite the existing record of the new key. |
copying | Whether to retain the record of the old key. |
If there's no matching record to the old key, NOT_FOUND_ERROR is set. If the overwrite flag is false and there is an existing record of the new key, DUPLICATION ERROR is set. This method is done atomically by ProcessMulti. The other threads observe that the record has either the old key or the new key. No intermediate states are observed.
TkrzwFuture* tkrzw_async_dbm_pop_first | ( | TkrzwAsyncDBM * | async | ) |
Gets the first record and removes it asynchronously.
async | the asynchronous database adapter. |
TkrzwFuture* tkrzw_async_dbm_push_last | ( | TkrzwAsyncDBM * | async, |
const char * | value_ptr, | ||
int32_t | value_size, | ||
double | wtime | ||
) |
Adds a record with a key of the current timestamp.
async | the asynchronous database adapter. |
value_ptr | The value pointer. |
value_size | The value size. If it is negative, strlen(value_ptr) is used. |
wtime | The current wall time used to generate the key. If it is negative, the system clock is used. |
The key is generated as an 8-bite big-endian binary string of the timestamp. If there is an existing record matching the generated key, the key is regenerated and the attempt is repeated until it succeeds.
TkrzwFuture* tkrzw_async_dbm_clear | ( | TkrzwAsyncDBM * | async | ) |
Removes all records asynchronously.
async | the asynchronous database adapter. |
TkrzwFuture* tkrzw_async_dbm_rebuild | ( | TkrzwAsyncDBM * | async, |
const char * | params | ||
) |
Rebuilds the entire database asynchronously.
async | the asynchronous database adapter. |
params | Optional parameters in "key=value,key=value" format. The parameters work in the same way as with PolyDBM::RebuildAdvanced. |
TkrzwFuture* tkrzw_async_dbm_synchronize | ( | TkrzwAsyncDBM * | async, |
bool | hard, | ||
const char * | params | ||
) |
Synchronizes the content of the database to the file system asynchronously.
async | the asynchronous database adapter. |
hard | True to do physical synchronization with the hardware or false to do only logical synchronization with the file system. |
params | Optional parameters in "key=value,key=value" format. The parameters work in the same way as with PolyDBM::OpenAdvanced. |
TkrzwFuture* tkrzw_async_dbm_copy_file_data | ( | TkrzwAsyncDBM * | async, |
const char * | dest_path, | ||
bool | sync_hard | ||
) |
Copies the content of the database files to other files.
async | the asynchronous database adapter. |
dest_path | The path prefix to the destination files. |
sync_hard | True to do physical synchronization with the hardware. |
Copying is done while the content is synchronized and stable. So, this method is suitable for making a backup file while running a database service.
TkrzwFuture* tkrzw_async_dbm_export | ( | TkrzwAsyncDBM * | async, |
TkrzwDBM * | dest_dbm | ||
) |
Exports all records to another database.
async | the asynchronous database adapter. |
dest_dbm | The destination database object. The lefetime of the database object must last until the task finishes. |
TkrzwFuture* tkrzw_async_dbm_export_to_flat_records | ( | TkrzwAsyncDBM * | async, |
TkrzwFile * | dest_file | ||
) |
Exports all records of a database to a flat record file.
async | the asynchronous database adapter. |
dest_file | The file object to write records in. The lefetime of the file object must last until the task finishes. |
TkrzwFuture* tkrzw_async_dbm_import_from_flat_records | ( | TkrzwAsyncDBM * | async, |
TkrzwFile * | src_file | ||
) |
Imports records to a database from a flat record file.
async | the asynchronous database adapter. |
src_file | The file object to read records from. The lefetime of the file object must last until the task finishes. |
TkrzwFuture* tkrzw_async_dbm_search | ( | TkrzwAsyncDBM * | async, |
const char * | mode, | ||
const char * | pattern_ptr, | ||
int32_t | pattern_size, | ||
int32_t | capacity | ||
) |
Searches a database and get keys asynchronously.
async | the asynchronous database adapter. |
mode | The search mode. "contain" extracts keys containing the pattern. "begin" extracts keys beginning with the pattern. "end" extracts keys ending with the pattern. "regex" extracts keys partially matches the pattern of a regular expression. "edit" extracts keys whose edit distance to the pattern is the least. Ordered databases support "upper" and "lower" which extract keys whose positions are equal to or upper/lower than the pattern. "upperex" and "lowerex" are their exclusive versions. |
pattern_ptr | The pattern pointer. |
pattern_size | The pattern size. If it is negative, strlen(pattern_ptr) is used. |
capacity | The maximum records to obtain. 0 means unlimited. |
TkrzwFile* tkrzw_file_open | ( | const char * | path, |
bool | writable, | ||
const char * | params | ||
) |
Opens a file.
path | A path of the file. |
writable | If true, the file is writable. If false, it is read-only. |
params | Optional parameters in "key=value,key=value" format. |
The optional parameters can include options for the file opening operation.
sync_hard (bool): True to do physical synchronization when closing.
The optional parameter "file" specifies the internal file implementation class. The default file class is "MemoryMapAtomicFile". The other supported classes are "StdFile", "MemoryMapAtomicFile", "PositionalParallelFile", and "PositionalAtomicFile".
For the file "PositionalParallelFile" and "PositionalAtomicFile", these optional parameters are supported.
bool tkrzw_file_close | ( | TkrzwFile * | file | ) |
Closes the file.
file | The file object. |
bool tkrzw_file_read | ( | TkrzwFile * | file, |
int64_t | off, | ||
void * | buf, | ||
size_t | size | ||
) |
Reads data.
file | The file object. |
off | The offset of a source region. |
buf | The pointer to the destination buffer. |
size | The size of the data to be read. |
bool tkrzw_file_write | ( | TkrzwFile * | file, |
int64_t | off, | ||
const void * | buf, | ||
size_t | size | ||
) |
Writes data.
file | The file object. |
off | The offset of the destination region. |
buf | The pointer to the source buffer. |
size | The size of the data to be written. |
bool tkrzw_file_append | ( | TkrzwFile * | file, |
const void * | buf, | ||
size_t | size, | ||
int64_t * | off | ||
) |
Appends data at the end of the file.
file | The file object. |
buf | The pointer to the source buffer. |
size | The size of the data to be written. |
off | The pointer to an integer object to contain the offset at which the data has been put. If it is nullptr, it is ignored. |
bool tkrzw_file_truncate | ( | TkrzwFile * | file, |
int64_t | size | ||
) |
Truncates the file.
file | The file object. |
size | The new size of the file. |
If the file is shrunk, data after the new file end is discarded. If the file is expanded, null codes are filled after the old file end.
bool tkrzw_file_synchronize | ( | TkrzwFile * | file, |
bool | hard, | ||
int64_t | off, | ||
int64_t | size | ||
) |
Synchronizes the content of the file to the file system.
file | The file object. |
hard | True to do physical synchronization with the hardware or false to do only logical synchronization with the file system. |
off | The offset of the region to be synchronized. |
size | The size of the region to be synchronized. If it is zero, the length to the end of file is specified. |
The pysical file size can be larger than the logical size in order to improve performance by reducing frequency of allocation. Thus, you should call this function before accessing the file with external tools.
int64_t tkrzw_file_get_size | ( | TkrzwFile * | file | ) |
Gets the size of the file.
file | The file object. |
char* tkrzw_file_get_path | ( | TkrzwFile * | file | ) |
Gets the path of the file.
file | The file object. |
TkrzwStr* tkrzw_file_search | ( | TkrzwFile * | file, |
const char * | mode, | ||
const char * | pattern_ptr, | ||
int32_t | pattern_size, | ||
int32_t | capacity, | ||
int32_t * | num_matched | ||
) |
Searches the file and get lines which match a pattern, according to a mode expression.
file | The file object. |
mode | The search mode. "contain" extracts keys containing the pattern. "begin" extracts keys beginning with the pattern. "end" extracts keys ending with the pattern. "regex" extracts keys partially matches the pattern of a regular expression. "edit" extracts keys whose edit distance to the UTF-8 pattern is the least. "editbin" extracts keys whose edit distance to the binary pattern is the least. |
pattern_ptr | The key pointer. |
pattern_size | The key size. If it is negative, strlen(pattern_ptr) is used. |
capacity | The maximum records to obtain. 0 means unlimited. |
num_matched | The pointer to the variable to store the number of the element of the return value. |
TkrzwIndex* tkrzw_index_open | ( | const char * | path, |
bool | writable, | ||
const char * | params | ||
) |
Opens an index file and makes an index object.
path | A path of the file. |
writable | If true, the file is writable. If false, it is read-only. |
params | Optional parameters in "key=value,key=value" format. The options for the file opening operation are set by "truncate", "no_create", "no_wait", "no_lock", and "sync_hard". Other options are the same as PolyIndex::Open. |
If the path is empty, BabyDBM is used internally, which is equivalent to using the MemIndex class. If the path ends with ".tkt", TreeDBM is used internally, which is equivalent to using the FileIndex class. If the key comparator of the tuning parameter is not set, PairLexicalKeyComparator is set implicitly. Other compatible key comparators are PairLexicalCaseKeyComparator, PairDecimalKeyComparator, PairHexadecimalKeyComparator, PairRealNumberKeyComparator, PairSignedBigEndianKeyComparator, and PairFloatBigEndianKeyComparator.
bool tkrzw_index_close | ( | TkrzwIndex * | index | ) |
Closes the index file and releases the index object.
index | The index object. |
bool tkrzw_index_check | ( | TkrzwIndex * | index, |
const char * | key_ptr, | ||
int32_t | key_size, | ||
const char * | value_ptr, | ||
int32_t | value_size | ||
) |
Checks whether a record exists in the index.
index | The index object. |
key_ptr | The key pointer. |
key_size | The key size. If it is negative, strlen(key_ptr) is used. |
value_ptr | The value pointer. |
value_size | The value size. If it is negative, strlen(value_ptr) is used. |
TkrzwStr* tkrzw_index_get_values | ( | TkrzwIndex * | index, |
const char * | key_ptr, | ||
int32_t | key_size, | ||
int32_t | max, | ||
int32_t * | num_elems | ||
) |
Gets all values of records of a key.
index | The index object. |
key_ptr | The key pointer. |
key_size | The key size. If it is negative, strlen(key_ptr) is used. |
max | The maximum number of values to get. 0 means unlimited. |
num_elems | The pointer to the variable to store the number of elements of the extra string array. |
bool tkrzw_index_add | ( | TkrzwIndex * | index, |
const char * | key_ptr, | ||
int32_t | key_size, | ||
const char * | value_ptr, | ||
int32_t | value_size | ||
) |
Adds a record.
index | The index object. |
key_ptr | The key pointer. This can be an arbitrary expression to search the index. |
key_size | The key size. If it is negative, strlen(key_ptr) is used. |
value_ptr | The value pointer. This should be a primary value of another database. |
value_size | The value size. If it is negative, strlen(value_ptr) is used. |
bool tkrzw_index_remove | ( | TkrzwIndex * | index, |
const char * | key_ptr, | ||
int32_t | key_size, | ||
const char * | value_ptr, | ||
int32_t | value_size | ||
) |
Remove a record.
index | The index object. |
key_ptr | The key pointer. This can be an arbitrary expression to search the index. |
key_size | The key size. If it is negative, strlen(key_ptr) is used. |
value_ptr | The value pointer. This should be a primary value of another database. |
value_size | The value size. If it is negative, strlen(value_ptr) is used. |
int32_t tkrzw_index_count | ( | TkrzwIndex * | index | ) |
Gets the number of records.
index | The index object. |
char* tkrzw_index_get_file_path | ( | TkrzwIndex * | index | ) |
Gets the path of the index file.
index | The index object. |
bool tkrzw_index_clear | ( | TkrzwIndex * | index | ) |
Removes all records.
index | The index object. |
bool tkrzw_index_rebuild | ( | TkrzwIndex * | index | ) |
Rebuilds the entire database.
index | The index object. |
bool tkrzw_index_synchronize | ( | TkrzwIndex * | index, |
bool | hard | ||
) |
Synchronizes the content of the database to the file system.
index | The index object. |
hard | True to do physical synchronization with the hardware or false to do only logical synchronization with the file system. |
bool tkrzw_index_is_writable | ( | TkrzwIndex * | index | ) |
Checks whether the database is writable.
index | The index object. |
TkrzwIndexIter* tkrzw_index_make_iterator | ( | TkrzwIndex * | index | ) |
Makes an iterator for each record.
index | The index object. |
void tkrzw_index_iter_free | ( | TkrzwIndexIter * | iter | ) |
Releases the iterator object.
iter | The iterator object. |
void tkrzw_index_iter_first | ( | TkrzwIndexIter * | iter | ) |
Initializes the iterator to indicate the first record.
iter | The iterator object. |
void tkrzw_index_iter_last | ( | TkrzwIndexIter * | iter | ) |
Initializes the iterator to indicate the last record.
iter | The iterator object. |
void tkrzw_index_iter_jump | ( | TkrzwIndexIter * | iter, |
const char * | key_ptr, | ||
int32_t | key_size, | ||
const char * | value_ptr, | ||
int32_t | value_size | ||
) |
Initializes the iterator to indicate a specific range.
iter | The iterator object. |
key_ptr | The key pointer of the lower bound. |
key_size | The key size. If it is negative, strlen(key_ptr) is used. |
value_ptr | The value pointer of the lower bound. |
value_size | The value size. If it is negative, strlen(value_ptr) is used. |
void tkrzw_index_iter_next | ( | TkrzwIndexIter * | iter | ) |
Moves the iterator to the next record.
iter | The iterator object. |
void tkrzw_index_iter_previous | ( | TkrzwIndexIter * | iter | ) |
Moves the iterator to the previous record.
iter | The iterator object. |
bool tkrzw_index_iter_get | ( | TkrzwIndexIter * | iter, |
char ** | key_ptr, | ||
int32_t * | key_size, | ||
char ** | value_ptr, | ||
int32_t * | value_size | ||
) |
Gets the key and the value of the current record of the iterator.
iter | The iterator object. |
key_ptr | The pointer to a variable which points to the region containing the record key. If this function returns true, the region should be released by the free function. If it is NULL, it is not used. |
key_size | The pointer to a variable which stores the size of the region containing the record key. If it is NULL, it is not used. |
value_ptr | The pointer to a variable which points to the region containing the record value. If this function returns true, the region should be released by the free function. If it is NULL, it is not used. |
value_size | The pointer to a variable which stores the size of the region containing the record value. If it is NULL, it is not used. |
|
extern |
The string expression of the package version.
|
extern |
The string expression of the library version.
|
extern |
The recognized OS name.
|
extern |
The size of a memory page on the OS.
|
extern |
The minimum value of int64_t.
|
extern |
The maximum value of int64_t.
|
extern |
The special string_view value to represent any data.
|
extern |
The special string indicating no operation.
|
extern |
The special string indicating removing operation.