Defines | |
#define | HAM_WRITE_THROUGH 0x00000001 |
#define | HAM_READ_ONLY 0x00000004 |
#define | HAM_USE_BTREE 0x00000010 |
#define | HAM_DISABLE_VAR_KEYLEN 0x00000040 |
#define | HAM_IN_MEMORY_DB 0x00000080 |
#define | HAM_DISABLE_MMAP 0x00000200 |
#define | HAM_CACHE_STRICT 0x00000400 |
#define | HAM_DISABLE_FREELIST_FLUSH 0x00000800 |
#define | HAM_LOCK_EXCLUSIVE 0x00001000 |
#define | HAM_RECORD_NUMBER 0x00002000 |
#define | HAM_ENABLE_DUPLICATES 0x00004000 |
#define | HAM_ENABLE_RECOVERY 0x00008000 |
#define | HAM_AUTO_RECOVERY 0x00010000 |
#define | HAM_ENABLE_TRANSACTIONS 0x00020000 |
#define | HAM_CACHE_UNLIMITED 0x00040000 |
#define | HAM_SORT_DUPLICATES 0x00100000 |
#define | HAM_OVERWRITE 0x0001 |
#define | HAM_DUPLICATE 0x0002 |
#define | HAM_DUPLICATE_INSERT_BEFORE 0x0004 |
#define | HAM_DUPLICATE_INSERT_AFTER 0x0008 |
#define | HAM_DUPLICATE_INSERT_FIRST 0x0010 |
#define | HAM_DUPLICATE_INSERT_LAST 0x0020 |
#define | HAM_DIRECT_ACCESS 0x0040 |
#define | HAM_PARTIAL 0x0080 |
#define | HAM_HINT_APPEND 0x00080000 |
#define | HAM_HINT_PREPEND 0x00100000 |
#define | HAM_HINTS_MASK 0x00FF0000 |
#define | HAM_FAST_ESTIMATE 0x0001 |
#define | HAM_PARAM_CACHESIZE 0x00000100 |
#define | HAM_PARAM_PAGESIZE 0x00000101 |
#define | HAM_PARAM_KEYSIZE 0x00000102 |
#define | HAM_PARAM_MAX_ENV_DATABASES 0x00000103 |
#define | HAM_PARAM_DATA_ACCESS_MODE 0x00000104 |
#define | HAM_PARAM_GET_FLAGS 0x00000200 |
#define | HAM_PARAM_GET_FILEMODE 0x00000201 |
#define | HAM_PARAM_GET_FILENAME 0x00000202 |
#define | HAM_PARAM_GET_DATABASE_NAME 0x00000203 |
#define | HAM_PARAM_DBNAME HAM_PARAM_GET_DATABASE_NAME |
#define | HAM_PARAM_GET_KEYS_PER_PAGE 0x00000204 |
#define | HAM_PARAM_GET_DATA_ACCESS_MODE 0x00000205 |
#define | HAM_PARAM_GET_DAM HAM_PARAM_GET_DATA_ACCESS_MODE |
#define | HAM_AUTO_CLEANUP 1 |
#define | HAM_DONT_CLEAR_LOG 2 |
#define | HAM_TXN_AUTO_ABORT 4 |
#define | HAM_TXN_AUTO_COMMIT 8 |
Typedefs | |
typedef int HAM_CALLCONV(* | ham_prefix_compare_func_t )(ham_db_t *db, const ham_u8_t *lhs, ham_size_t lhs_length, ham_size_t lhs_real_length, const ham_u8_t *rhs, ham_size_t rhs_length, ham_size_t rhs_real_length) |
typedef int HAM_CALLCONV(* | ham_compare_func_t )(ham_db_t *db, const ham_u8_t *lhs, ham_size_t lhs_length, const ham_u8_t *rhs, ham_size_t rhs_length) |
typedef int HAM_CALLCONV(* | ham_duplicate_compare_func_t )(ham_db_t *db, const ham_u8_t *lhs, ham_size_t lhs_length, const ham_u8_t *rhs, ham_size_t rhs_length) |
Functions | |
HAM_EXPORT ham_status_t HAM_CALLCONV | ham_new (ham_db_t **db) |
HAM_EXPORT ham_status_t HAM_CALLCONV | ham_delete (ham_db_t *db) |
HAM_EXPORT ham_status_t HAM_CALLCONV | ham_create (ham_db_t *db, const char *filename, ham_u32_t flags, ham_u32_t mode) |
HAM_EXPORT ham_status_t HAM_CALLCONV | ham_create_ex (ham_db_t *db, const char *filename, ham_u32_t flags, ham_u32_t mode, const ham_parameter_t *param) |
HAM_EXPORT ham_status_t HAM_CALLCONV | ham_open (ham_db_t *db, const char *filename, ham_u32_t flags) |
HAM_EXPORT ham_status_t HAM_CALLCONV | ham_open_ex (ham_db_t *db, const char *filename, ham_u32_t flags, const ham_parameter_t *param) |
HAM_EXPORT ham_status_t HAM_CALLCONV | ham_get_error (ham_db_t *db) |
HAM_EXPORT ham_status_t HAM_CALLCONV | ham_set_prefix_compare_func (ham_db_t *db, ham_prefix_compare_func_t foo) |
HAM_EXPORT ham_status_t HAM_CALLCONV | ham_set_compare_func (ham_db_t *db, ham_compare_func_t foo) |
HAM_EXPORT ham_status_t HAM_CALLCONV | ham_set_duplicate_compare_func (ham_db_t *db, ham_duplicate_compare_func_t foo) |
HAM_EXPORT ham_status_t HAM_CALLCONV | ham_enable_compression (ham_db_t *db, ham_u32_t level, ham_u32_t flags) |
HAM_EXPORT ham_status_t HAM_CALLCONV | ham_find (ham_db_t *db, ham_txn_t *txn, ham_key_t *key, ham_record_t *record, ham_u32_t flags) |
HAM_EXPORT ham_status_t HAM_CALLCONV | ham_insert (ham_db_t *db, ham_txn_t *txn, ham_key_t *key, ham_record_t *record, ham_u32_t flags) |
HAM_EXPORT ham_status_t HAM_CALLCONV | ham_erase (ham_db_t *db, ham_txn_t *txn, ham_key_t *key, ham_u32_t flags) |
HAM_EXPORT ham_status_t HAM_CALLCONV | ham_flush (ham_db_t *db, ham_u32_t flags) |
HAM_EXPORT ham_status_t HAM_CALLCONV | ham_get_key_count (ham_db_t *db, ham_txn_t *txn, ham_u32_t flags, ham_offset_t *keycount) |
HAM_EXPORT ham_status_t HAM_CALLCONV | ham_get_parameters (ham_db_t *db, ham_parameter_t *param) |
HAM_EXPORT ham_u32_t HAM_CALLCONV | ham_get_flags (ham_db_t *db) |
HAM_EXPORT ham_env_t *HAM_CALLCONV | ham_get_env (ham_db_t *db) |
HAM_EXPORT int HAM_CALLCONV | ham_key_get_approximate_match_type (ham_key_t *key) |
HAM_EXPORT ham_status_t HAM_CALLCONV | ham_close (ham_db_t *db, ham_u32_t flags) |
#define HAM_AUTO_CLEANUP 1 |
Flag for ham_close, ham_env_close
Definition at line 2152 of file hamsterdb.h.
Referenced by main().
#define HAM_AUTO_RECOVERY 0x00010000 |
Flag for ham_open_ex, ham_env_open_ex. This flag is non persistent.
Definition at line 1431 of file hamsterdb.h.
#define HAM_CACHE_STRICT 0x00000400 |
Flag for ham_open, ham_open_ex, ham_create, ham_create_ex. This flag is non persistent.
Definition at line 1405 of file hamsterdb.h.
#define HAM_CACHE_UNLIMITED 0x00040000 |
Flag for ham_open, ham_open_ex, ham_create, ham_create_ex. This flag is non persistent.
Definition at line 1441 of file hamsterdb.h.
#define HAM_DIRECT_ACCESS 0x0040 |
Flag for ham_find, ham_cursor_find_ex, ham_cursor_move
Definition at line 1836 of file hamsterdb.h.
#define HAM_DISABLE_FREELIST_FLUSH 0x00000800 |
Definition at line 1410 of file hamsterdb.h.
#define HAM_DISABLE_MMAP 0x00000200 |
Flag for ham_open, ham_open_ex, ham_create, ham_create_ex. This flag is non persistent.
Definition at line 1400 of file hamsterdb.h.
#define HAM_DISABLE_VAR_KEYLEN 0x00000040 |
Flag for ham_create, ham_create_ex. This flag is non persistent.
Definition at line 1389 of file hamsterdb.h.
#define HAM_DONT_CLEAR_LOG 2 |
Definition at line 2155 of file hamsterdb.h.
#define HAM_DUPLICATE 0x0002 |
Flag for ham_insert and ham_cursor_insert
Definition at line 1821 of file hamsterdb.h.
Referenced by copy_db(), main(), and run_demo().
#define HAM_DUPLICATE_INSERT_AFTER 0x0008 |
Flag for ham_cursor_insert
Definition at line 1827 of file hamsterdb.h.
#define HAM_DUPLICATE_INSERT_BEFORE 0x0004 |
Flag for ham_cursor_insert
Definition at line 1824 of file hamsterdb.h.
#define HAM_DUPLICATE_INSERT_FIRST 0x0010 |
Flag for ham_cursor_insert
Definition at line 1830 of file hamsterdb.h.
#define HAM_DUPLICATE_INSERT_LAST 0x0020 |
Flag for ham_cursor_insert
Definition at line 1833 of file hamsterdb.h.
#define HAM_ENABLE_DUPLICATES 0x00004000 |
Flag for ham_create, ham_create_ex. This flag is persisted in the Database.
Definition at line 1422 of file hamsterdb.h.
Referenced by main(), and run_demo().
#define HAM_ENABLE_RECOVERY 0x00008000 |
Flag for ham_create_ex, ham_open_ex, ham_env_create_ex, ham_env_open_ex. This flag is non persistent.
Definition at line 1427 of file hamsterdb.h.
#define HAM_ENABLE_TRANSACTIONS 0x00020000 |
Flag for ham_create_ex, ham_open_ex, ham_env_create_ex, ham_env_open_ex. This flag is non persistent.
Definition at line 1436 of file hamsterdb.h.
Referenced by main().
#define HAM_FAST_ESTIMATE 0x0001 |
Flag for ham_get_key_count
Definition at line 1948 of file hamsterdb.h.
#define HAM_HINT_APPEND 0x00080000 |
Flag for ham_cursor_insert
Mutually exclusive with flag HAM_HINT_PREPEND.
Hints the hamsterdb engine that the current key will compare as larger than any key already existing in the Database. The hamsterdb engine will verify this postulation and when found not to be true, will revert to a regular insert operation as if this flag was not specified. The incurred cost then is only one additional key comparison.
Definition at line 1854 of file hamsterdb.h.
#define HAM_HINT_PREPEND 0x00100000 |
Flag for ham_cursor_insert
Mutually exclusive with flag HAM_HINT_APPEND.
Hints the hamsterdb engine that the current key will compare as smaller than any key already existing in the Database. The hamsterdb engine will verify this postulation and when found not to be true, will revert to a regular insert operation as if this flag was not specified. The incurred cost then is only one additional key comparison.
Definition at line 1868 of file hamsterdb.h.
#define HAM_HINTS_MASK 0x00FF0000 |
Flag mask to extract the common hint flags from a find/move/insert/erase flag value.
Definition at line 1874 of file hamsterdb.h.
#define HAM_IN_MEMORY_DB 0x00000080 |
Flag for ham_create, ham_create_ex. This flag is non persistent.
Definition at line 1393 of file hamsterdb.h.
#define HAM_LOCK_EXCLUSIVE 0x00001000 |
Flag for ham_open, ham_open_ex, ham_create, ham_create_ex
Definition at line 1414 of file hamsterdb.h.
#define HAM_OVERWRITE 0x0001 |
Flag for ham_insert and ham_cursor_insert
When specified with ham_insert and in case a key is specified which stores duplicates in the Database, the first duplicate record will be overwritten.
When used with ham_cursor_insert and assuming the same conditions, the duplicate currently referenced by the Cursor will be overwritten.
Definition at line 1818 of file hamsterdb.h.
#define HAM_PARAM_CACHESIZE 0x00000100 |
Parameter name for ham_open_ex, ham_create_ex; sets the cache size
Definition at line 1987 of file hamsterdb.h.
#define HAM_PARAM_DATA_ACCESS_MODE 0x00000104 |
Parameter name for ham_create_ex, ham_open_ex; set the expected access mode.
Definition at line 2003 of file hamsterdb.h.
#define HAM_PARAM_DBNAME HAM_PARAM_GET_DATABASE_NAME |
Definition at line 2036 of file hamsterdb.h.
#define HAM_PARAM_GET_DAM HAM_PARAM_GET_DATA_ACCESS_MODE |
Definition at line 2052 of file hamsterdb.h.
#define HAM_PARAM_GET_DATA_ACCESS_MODE 0x00000205 |
Retrieve the Data Access mode for the Database
Definition at line 2051 of file hamsterdb.h.
#define HAM_PARAM_GET_DATABASE_NAME 0x00000203 |
Retrieve the Database 'name' number of this ham_db_t Database within the current ham_env_t Environment.
When the Database is not related to an Environment, the reserved 'name' 0xf001 is used for this Database.
Definition at line 2035 of file hamsterdb.h.
#define HAM_PARAM_GET_FILEMODE 0x00000201 |
Retrieve the filesystem file access mode as was specified at the time of ham_create/ham_env_create/ham_open/ham_env_open invocation.
Definition at line 2017 of file hamsterdb.h.
#define HAM_PARAM_GET_FILENAME 0x00000202 |
Return a const char *
pointer to the current Environment/Database file name in the ham_offset_t value member, when the Database is actually stored on disc.
In-memory Databases will return a NULL (0) pointer instead.
Definition at line 2026 of file hamsterdb.h.
#define HAM_PARAM_GET_FLAGS 0x00000200 |
Retrieve the Database/Environment flags as were specified at the time of ham_create/ham_env_create/ham_open/ham_env_open invocation.
Definition at line 2010 of file hamsterdb.h.
#define HAM_PARAM_GET_KEYS_PER_PAGE 0x00000204 |
Retrieve the maximum number of keys per page; this number depends on the currently active page and key sizes.
When no Database or Environment is specified with the request, the default settings for all of these will be assumed in order to produce a viable ball park value for this one.
Definition at line 2046 of file hamsterdb.h.
#define HAM_PARAM_KEYSIZE 0x00000102 |
Parameter name for ham_create_ex; sets the key size
Definition at line 1994 of file hamsterdb.h.
#define HAM_PARAM_MAX_ENV_DATABASES 0x00000103 |
Parameter name for ham_env_create_ex; sets the number of maximum Databases
Definition at line 1998 of file hamsterdb.h.
#define HAM_PARAM_PAGESIZE 0x00000101 |
Parameter name for ham_open_ex, ham_create_ex; sets the page size
Definition at line 1991 of file hamsterdb.h.
#define HAM_PARTIAL 0x0080 |
Flag for ham_insert, ham_cursor_insert, ham_find, ham_cursor_find_ex, ham_cursor_move
Definition at line 1840 of file hamsterdb.h.
#define HAM_READ_ONLY 0x00000004 |
Flag for ham_open, ham_open_ex. This flag is non persistent.
Definition at line 1377 of file hamsterdb.h.
#define HAM_RECORD_NUMBER 0x00002000 |
Flag for ham_create, ham_create_ex, ham_env_create_db. This flag is persisted in the Database.
Definition at line 1418 of file hamsterdb.h.
Referenced by main().
#define HAM_SORT_DUPLICATES 0x00100000 |
Flag for ham_create, ham_create_ex, ham_env_create_db, ham_open, ham_open_ex, ham_env_open_db This flag is non persistent.
Definition at line 1448 of file hamsterdb.h.
#define HAM_TXN_AUTO_ABORT 4 |
Automatically abort all open Transactions (the default)
Definition at line 2158 of file hamsterdb.h.
#define HAM_TXN_AUTO_COMMIT 8 |
Automatically commit all open Transactions
Definition at line 2161 of file hamsterdb.h.
#define HAM_USE_BTREE 0x00000010 |
Flag for ham_create, ham_create_ex. This flag is persisted in the Database.
Definition at line 1383 of file hamsterdb.h.
#define HAM_WRITE_THROUGH 0x00000001 |
Flag for ham_open, ham_open_ex, ham_create, ham_create_ex. This flag is non persistent.
Definition at line 1371 of file hamsterdb.h.
typedef int HAM_CALLCONV(* ham_compare_func_t)(ham_db_t *db, const ham_u8_t *lhs, ham_size_t lhs_length, const ham_u8_t *rhs, ham_size_t rhs_length) |
Typedef for a key comparison function
Definition at line 1509 of file hamsterdb.h.
typedef int HAM_CALLCONV(* ham_duplicate_compare_func_t)(ham_db_t *db, const ham_u8_t *lhs, ham_size_t lhs_length, const ham_u8_t *rhs, ham_size_t rhs_length) |
Typedef for a record comparison function
Definition at line 1550 of file hamsterdb.h.
typedef int HAM_CALLCONV(* ham_prefix_compare_func_t)(ham_db_t *db, const ham_u8_t *lhs, ham_size_t lhs_length, ham_size_t lhs_real_length, const ham_u8_t *rhs, ham_size_t rhs_length, ham_size_t rhs_real_length) |
Typedef for a prefix comparison function
Definition at line 1477 of file hamsterdb.h.
HAM_EXPORT ham_status_t HAM_CALLCONV ham_close | ( | ham_db_t * | db, | |
ham_u32_t | flags | |||
) |
Closes the Database
This function flushes the Database and then closes the file handle. It does not free the memory resources allocated in the db handle - use ham_delete to free db.
If the flag HAM_AUTO_CLEANUP is specified, hamsterdb automatically calls ham_cursor_close on all open Cursors. This invalidates the ham_cursor_t handle!
If the flag is not specified, the application must close all Database Cursors with ham_cursor_close to prevent memory leaks.
This function removes all record-level filters installed with ham_add_record_filter (and hence also, implicitly, the filter installed by ham_enable_compression).
This function also aborts all Transactions which were not yet committed, and therefore renders all Transaction handles invalid. If the flag HAM_TXN_AUTO_COMMIT is specified, all Transactions will be committed.
db | A valid Database handle | |
flags | Optional flags for closing the Database. Possible values are:
|
Referenced by ham::db::close(), and main().
HAM_EXPORT ham_status_t HAM_CALLCONV ham_create | ( | ham_db_t * | db, | |
const char * | filename, | |||
ham_u32_t | flags, | |||
ham_u32_t | mode | |||
) |
Creates a Database
This function is a simplified version of
Referenced by main().
HAM_EXPORT ham_status_t HAM_CALLCONV ham_create_ex | ( | ham_db_t * | db, | |
const char * | filename, | |||
ham_u32_t | flags, | |||
ham_u32_t | mode, | |||
const ham_parameter_t * | param | |||
) |
Creates a Database - extended version
This function is a shortcut for a sequence of ham_env_create_ex followed by ham_env_create_db.
It creates an (internal, hidden) Environment and in this Environment it creates a Database with a reserved identifier - HAM_DEFAULT_DATABASE_NAME.
As a consequence, it is no problem to create a Database with ham_create_ex, and later open it with ham_env_open_ex.
The internal Environment handle can be retrieved with ham_get_env.
db | A valid Database handle | |
filename | The filename of the Database file. If the file already exists, it will be overwritten. Can be NULL if you create an In-Memory Database | |
flags | Optional flags for opening the Database, combined with bitwise OR. Possible flags are:
| |
mode | File access rights for the new file. This is the mode parameter for creat(2). Ignored on Microsoft Windows. | |
param | An array of ham_parameter_t structures. The following parameters are available:
|
Referenced by ham::db::create(), and main().
HAM_EXPORT ham_status_t HAM_CALLCONV ham_delete | ( | ham_db_t * | db | ) |
Frees a ham_db_t handle
Frees the memory and resources of a ham_db_t structure, but does not close the Database. Call this function AFTER you have closed the Database using ham_close, or you will lose your data!
db | A valid Database handle |
Referenced by ham::db::close(), ham::env::create_db(), main(), and ham::env::open_db().
HAM_EXPORT ham_status_t HAM_CALLCONV ham_enable_compression | ( | ham_db_t * | db, | |
ham_u32_t | level, | |||
ham_u32_t | flags | |||
) |
Enables zlib compression for all inserted records
This function enables zlib compression for all inserted Database records.
The compression will be active till ham_close is called. If the Database handle is reused after calling ham_close, the compression is no longer active. ham_enable_compression should be called immediately after ham_create[_ex] or ham_open[_ex]. When opening the Database, the compression has to be enabled again.
Note that zlib usually has an overhead and often is not effective if the records are small (i.e. < 128byte), but this highly depends on the data that is inserted.
The zlib compression filter does not allow queries (i.e. with ham_find) with user-allocated records and the flag HAM_RECORD_USER_ALLOC. In this case, the query-function will return HAM_INV_PARAMETER.
db | A valid Database handle | |
level | The compression level. 0 for the zlib default, 1 for best speed and 9 for minimum size | |
flags | Optional flags for the compression; unused, set to 0 |
Referenced by ham::db::enable_compression().
HAM_EXPORT ham_status_t HAM_CALLCONV ham_erase | ( | ham_db_t * | db, | |
ham_txn_t * | txn, | |||
ham_key_t * | key, | |||
ham_u32_t | flags | |||
) |
Erases a Database item
This function erases a Database item. If the item key does not exist, HAM_KEY_NOT_FOUND is returned.
Note that ham_erase can not erase a single duplicate key. If the key has multiple duplicates, all duplicates of this key will be erased. Use ham_cursor_erase to erase a specific duplicate key.
db | A valid Database handle | |
txn | A Transaction handle, or NULL | |
key | The key to delete | |
flags | Optional flags for erasing; unused, set to 0 |
Referenced by ham::db::erase(), and main().
HAM_EXPORT ham_status_t HAM_CALLCONV ham_find | ( | ham_db_t * | db, | |
ham_txn_t * | txn, | |||
ham_key_t * | key, | |||
ham_record_t * | record, | |||
ham_u32_t | flags | |||
) |
Searches an item in the Database
This function searches the Database for key. If the key is found, record will receive the record of this item and HAM_SUCCESS is returned. If the key is not found, the function returns HAM_KEY_NOT_FOUND.
A ham_record_t structure should be initialized with zeroes before it is being used. This can be done with the C library routines memset(3) or bzero(2).
If the function completes successfully, the record pointer is initialized with the size of the record (in record.size) and the actual record data (in record.data). If the record is empty, size is 0 and data points to NULL.
The data pointer is a temporary pointer and will be overwritten by subsequent hamsterdb API calls. You can alter this behaviour by allocating the data pointer in the application and setting record.flags to HAM_RECORD_USER_ALLOC. Make sure that the allocated buffer is large enough.
When specifying HAM_DIRECT_ACCESS, the data pointer will point directly to the record that is stored in hamsterdb; the data can be modified, but the pointer must not be reallocated of freed. The flag HAM_DIRECT_ACCESS is only allowed in In-Memory Databases.
ham_find can not search for duplicate keys. If key has multiple duplicates, only the first duplicate is returned.
You can read only portions of the record by specifying the flag HAM_PARTIAL. In this case, hamsterdb will read record->partial_size bytes of the record data at offset record->partial_offset. If necessary, the record data will be limited to the original record size. The number of actually read bytes is returned in record->size.
db | A valid Database handle | |
txn | A Transaction handle, or NULL | |
key | The key of the item | |
record | The record of the item | |
flags | Optional flags for searching, which can be combined with bitwise OR. Possible flags are:
|
Referenced by ham::db::find(), and main().
HAM_EXPORT ham_status_t HAM_CALLCONV ham_flush | ( | ham_db_t * | db, | |
ham_u32_t | flags | |||
) |
Flushes the Database
This function is deprecated. Use ham_env_flush instead. Use ham_get_env to retrieve an Environment handle for your Database, in case the handle is not available because the Database was opened or created with ham_create_ex or ham_open_ex.
Referenced by ham::db::flush().
Retrieve the Environment handle of a Database
Every Database belongs to an Environment, even if it was created with ham_create[_ex] or ham_open[_ex].
Therefore this function always returns a valid handle, if the Database handle was also valid and initialized (otherwise it returns NULL).
db | A valid Database handle |
HAM_EXPORT ham_status_t HAM_CALLCONV ham_get_error | ( | ham_db_t * | db | ) |
Returns the last error code
db | A valid Database handle |
Referenced by ham::db::get_error().
Retrieve the flags which were specified when the Database was created or opened
db | A valid Database handle |
HAM_EXPORT ham_status_t HAM_CALLCONV ham_get_key_count | ( | ham_db_t * | db, | |
ham_txn_t * | txn, | |||
ham_u32_t | flags, | |||
ham_offset_t * | keycount | |||
) |
Calculates the number of keys stored in the Database
You can specify the HAM_SKIP_DUPLICATES if you do now want to include any duplicates in the count; if all you're after is a quick estimate, you can specify the flag HAM_FAST_ESTIMATE (which implies HAM_SKIP_DUPLICATES), which will improve the execution speed of this operation significantly.
db | A valid Database handle | |
txn | A Transaction handle, or NULL | |
flags | Optional flags:
| |
keycount | A reference to a variable which will receive the calculated key count per page |
Referenced by ham::db::get_key_count().
HAM_EXPORT ham_status_t HAM_CALLCONV ham_get_parameters | ( | ham_db_t * | db, | |
ham_parameter_t * | param | |||
) |
Retrieve the current value for a given Database setting
Only those values requested by the parameter array will be stored.
The following parameters are supported:
db | A valid Database handle | |
param | An array of ham_parameter_t structures |
Referenced by ham::db::get_parameters().
HAM_EXPORT ham_status_t HAM_CALLCONV ham_insert | ( | ham_db_t * | db, | |
ham_txn_t * | txn, | |||
ham_key_t * | key, | |||
ham_record_t * | record, | |||
ham_u32_t | flags | |||
) |
Inserts a Database item
This function inserts a key/record pair as a new Database item.
If the key already exists in the Database, error HAM_DUPLICATE_KEY is returned.
If you wish to overwrite an existing entry specify the flag HAM_OVERWRITE.
You can write only portions of the record by specifying the flag HAM_PARTIAL. In this case, hamsterdb will write partial_size bytes of the record data at offset partial_offset. The full record size will always be given in record->size! If partial_size+partial_offset exceed record->size then partial_size will be limited. To shrink or grow the record, adjust record->size. HAM_PARTIAL automatically overwrites existing records. Gaps will be filled with null-bytes if the record did not yet exist. Using HAM_PARTIAL is not allowed in combination with sorted duplicates (HAM_SORT_DUPLICATES).
If you wish to insert a duplicate key specify the flag HAM_DUPLICATE. (Note that the Database has to be created with HAM_ENABLE_DUPLICATES in order to use duplicate keys.) If no duplicate sorting is enabled (see HAM_SORT_DUPLICATES), the duplicate key is inserted after all other duplicate keys (see HAM_DUPLICATE_INSERT_LAST). Otherwise it is inserted in sorted order.
Record Number Databases (created with HAM_RECORD_NUMBER) expect either an empty key (with a size of 0 and data pointing to NULL), or a user-supplied key (with key.flag HAM_KEY_USER_ALLOC, a size of 8 and a valid data pointer). If key.size is 0 and key.data is NULL, hamsterdb will temporarily allocate memory for key->data, which will then point to an 8-byte unsigned integer in host-endian.
db | A valid Database handle | |
txn | A Transaction handle, or NULL | |
key | The key of the new item | |
record | The record of the new item | |
flags | Optional flags for inserting. Possible flags are:
|
Referenced by copy_db(), ham::db::insert(), and main().
HAM_EXPORT int HAM_CALLCONV ham_key_get_approximate_match_type | ( | ham_key_t * | key | ) |
Returns the kind of key match which produced this key as it was returned by one of the ham_find(), ham_cursor_find() or ham_cursor_find_ex() functions
This routine assumes the key was passed back by one of the ham_find, ham_cursor_find or ham_cursor_find_ex functions and not used by any other hamsterdb functions after that.
As such, this function produces an answer akin to the 'sign' of the specified key as it was returned by the find operation.
key | A valid key |
Referenced by ham::key::get_approximate_match_type().
HAM_EXPORT ham_status_t HAM_CALLCONV ham_new | ( | ham_db_t ** | db | ) |
Allocates a ham_db_t handle
db | Pointer to the pointer which is allocated |
Referenced by ham::db::create(), ham::env::create_db(), main(), ham::db::open(), and ham::env::open_db().
HAM_EXPORT ham_status_t HAM_CALLCONV ham_open | ( | ham_db_t * | db, | |
const char * | filename, | |||
ham_u32_t | flags | |||
) |
Opens an existing Database
This function is a simplified version of
Referenced by main().
HAM_EXPORT ham_status_t HAM_CALLCONV ham_open_ex | ( | ham_db_t * | db, | |
const char * | filename, | |||
ham_u32_t | flags, | |||
const ham_parameter_t * | param | |||
) |
Opens an existing Database - extended version
This function is a shortcut for a sequence of ham_env_open_ex followed by ham_env_open_db.
It opens an (internal, hidden) Environment and in this Environment it opens the first Database that was created.
As a consequence, it is no problem to open a Database with ham_open_ex, even if it was created with ham_env_create_ex.
The internal Environment handle can be retrieved with ham_get_env.
db | A valid Database handle | |
filename | The filename of the Database file | |
flags | Optional flags for opening the Database, combined with bitwise OR. Possible flags are:
| |
param | An array of ham_parameter_t structures. The following parameters are available:
|
Referenced by main(), and ham::db::open().
HAM_EXPORT ham_status_t HAM_CALLCONV ham_set_compare_func | ( | ham_db_t * | db, | |
ham_compare_func_t | foo | |||
) |
Sets the comparison function
The comparison function compares two index keys. It returns -1 if the first key is smaller, +1 if the second key is smaller or 0 if both keys are equal.
If foo is NULL, hamsterdb will use the default compare function (which is based on memcmp(3)).
Note that if you use a custom comparison routine in combination with extended keys, it might be useful to disable the prefix comparison, which is based on memcmp(3). See ham_set_prefix_compare_func for details.
db | A valid Database handle | |
foo | A pointer to the compare function |
Referenced by main(), and ham::db::set_compare_func().
HAM_EXPORT ham_status_t HAM_CALLCONV ham_set_duplicate_compare_func | ( | ham_db_t * | db, | |
ham_duplicate_compare_func_t | foo | |||
) |
Sets the duplicate comparison function
The comparison function compares two records which share the same key. It returns -1 if the first record is smaller, +1 if the second record is smaller or 0 if both records are equal.
If foo is NULL, hamsterdb will use the default compare function (which is based on memcmp(3)).
To enable this function, the flag HAM_SORT_DUPLICATES has to be specified when creating or opening a Database.
Sorting duplicate keys comes with a small performance penalty compared to unsorted duplicates, since the records of other duplicates have to be fetched for the comparison.
Warning If duplicate sorting is enabled, and records are retrieved with HAM_DIRECT_ACCESS, the records must not be modified or the sort order might get lost.
db | A valid Database handle | |
foo | A pointer to the compare function |
HAM_EXPORT ham_status_t HAM_CALLCONV ham_set_prefix_compare_func | ( | ham_db_t * | db, | |
ham_prefix_compare_func_t | foo | |||
) |
Sets the prefix comparison function
The prefix comparison function is called when an index uses keys with variable length and at least one of the two keys is loaded only partially.
If foo is NULL, hamsterdb will not use any prefix comparison.
db | A valid Database handle | |
foo | A pointer to the prefix compare function |
Referenced by ham::db::set_prefix_compare_func().