The memory-passing interface has several advantages. Firstly, one can choose an efficient way for their application to load a database image to a memory block, e.g., to read the whole image from a file, to use the Memory Mapped File (mmap) API, etc. Secondaly, one can design the file format freely only if the memory block for a database is extracted from the file.
The most fundamental operation on the CQDB reader API is forward lookup through the use of cqdb_to_id() function, which retrieves integer identifiers from strings. Reverse lookup (retrieving strings from integer identifiers) with cqdb_to_string() function is not supported if the database has been created with CQDB_ONEWAY flag.
Typedefs | |
typedef tag_cqdb | cqdb_t |
Typedef of a CQDB reader. | |
Functions | |
cqdb_t * | cqdb_reader (void *buffer, size_t size) |
Open a new CQDB reader on a memory block. | |
void | cqdb_delete (cqdb_t *db) |
Delete the CQDB reader. | |
int | cqdb_to_id (cqdb_t *db, const char *str) |
Retrieve the identifier associated with a string. | |
const char * | cqdb_to_string (cqdb_t *db, int id) |
Retrieve the string associated with an identifier. | |
int | cqdb_num (cqdb_t *db) |
Get the number of associations in the database. |
void cqdb_delete | ( | cqdb_t * | db | ) |
Delete the CQDB reader.
This function frees the work area allocated by cqdb_reader() function.
db | The pointer to the cqdb_t instance. |
int cqdb_num | ( | cqdb_t * | db | ) |
Get the number of associations in the database.
This function returns the number of associations in the database.
db | The pointer to the cqdb_t instance. |
int | The number of string/identifier associations. |
cqdb_t* cqdb_reader | ( | void * | buffer, | |
size_t | size | |||
) |
Open a new CQDB reader on a memory block.
This function initializes a database on a memory block and returns the pointer to a cqdb_t instance to access the database.
buffer | The pointer to the memory block. | |
size | The size of the memory block. |
cqdb_t* | The pointer to the cqdb_t instance. |
int cqdb_to_id | ( | cqdb_t * | db, | |
const char * | str | |||
) |
Retrieve the identifier associated with a string.
This function returns the identifier associated with a string.
db | The pointer to the cqdb_t instance. | |
str | The pointer to a string. |
int | The non-negative identifier if successful, negative status code otherwise. |
const char* cqdb_to_string | ( | cqdb_t * | db, | |
int | id | |||
) |
Retrieve the string associated with an identifier.
This function returns the string associated with an identifier.
db | The pointer to the cqdb_t instance. | |
id | The id. |
const | char* The pointer to the string associated with the identifier if successful; otherwise NULL . |