This file contains various definitions and interface for management of in-memory, through mmaped file, growable hash table, that stores sample files. More...
#include <stddef.h>#include <stdint.h>#include "op_list.h"

Go to the source code of this file.
Classes | |
| struct | odb_node_t |
| a db hash node More... | |
| struct | odb_descr_t |
| the minimal information which must be stored in the file to reload properly the data base, following this header is the node array then the hash table (when growing we avoid to copy node array) More... | |
| struct | odb_data |
| a "database". More... | |
| struct | odb_t |
Defines | |
| #define | BUCKET_FACTOR 1 |
| #define | ODB_NODE_NR_INVALID ((odb_node_nr_t)-1) |
| "immpossible" node number to indicate an error from odb_hash_add_node() | |
Typedefs | |
| typedef uint64_t | odb_key_t |
| the type of key. | |
| typedef unsigned int | odb_value_t |
| the type of an information in the database | |
| typedef unsigned int | odb_index_t |
| the type of index (node number), list are implemented through index | |
| typedef odb_index_t | odb_node_nr_t |
| the type store node number | |
| typedef odb_index_t | odb_hash_mask_t |
| store the hash mask, hash table size are always power of two | |
| typedef struct odb_data | odb_data_t |
| a "database". | |
| typedef struct odb_hash_stat_t | odb_hash_stat_t |
Enumerations | |
| enum | odb_rw { ODB_RDONLY = 0, ODB_RDWR = 1 } |
how to open the DB file More... | |
Functions | |
| void | odb_init (odb_t *odb) |
| odb_init - initialize a DB file | |
| int | odb_open (odb_t *odb, char const *filename, enum odb_rw rw, size_t sizeof_header) |
| void | odb_close (odb_t *odb) |
| Close the given ODB file. | |
| int | odb_open_count (odb_t const *odb) |
| return the number of times this sample file is open | |
| void * | odb_get_data (odb_t *odb) |
| return the start of the mapped data | |
| void | odb_sync (odb_t const *odb) |
| issue a msync on the used size of the mmaped file | |
| int | odb_grow_hashtable (odb_data_t *data) |
| grow the hashtable in such way current_size is the index of the first free node. | |
| int | odb_check_hash (odb_t const *odb) |
| check that the hash is well built | |
| odb_hash_stat_t * | odb_hash_stat (odb_t const *odb) |
| void | odb_hash_display_stat (odb_hash_stat_t const *stats) |
| void | odb_hash_free_stat (odb_hash_stat_t *stats) |
| int | odb_update_node (odb_t *odb, odb_key_t key) |
| update info at key by incrementing its associated value by one, if the key does not exist a new node is created and the value associated is set to one. | |
| int | odb_update_node_with_offset (odb_t *odb, odb_key_t key, unsigned long int offset) |
| odb_update_node_with_offset | |
| int | odb_add_node (odb_t *odb, odb_key_t key, odb_value_t value) |
| Add a new node w/o regarding if a node with the same key already exists. | |
| odb_node_t * | odb_get_iterator (odb_t const *odb, odb_node_nr_t *nr) |
| return a base pointer to the node array and number of node in this array caller then will iterate through: | |
This file contains various definitions and interface for management of in-memory, through mmaped file, growable hash table, that stores sample files.
| #define BUCKET_FACTOR 1 |
Referenced by odb_check_hash(), odb_grow_hashtable(), odb_hash_stat(), and odb_open().
| #define ODB_NODE_NR_INVALID ((odb_node_nr_t)-1) |
"immpossible" node number to indicate an error from odb_hash_add_node()
| typedef struct odb_data odb_data_t |
a "database".
this is an in memory only description.
We allow to manage a database inside a mapped file with an "header" of unknown size so odb_open get a parameter to specify the size of this header. A typical use is:
struct header { int etc; ... }; odb_open(&hash, filename, ODB_RW, sizeof(header)); so on this library have no dependency on the header type.
the internal memory layout from base_memory is: the unknown header (sizeof_header) odb_descr_t the node array: (descr->size * sizeof(odb_node_t) entries the hash table: array of odb_index_t indexing the node array (descr->size * BUCKET_FACTOR) entries
| typedef odb_index_t odb_hash_mask_t |
store the hash mask, hash table size are always power of two
| typedef struct odb_hash_stat_t odb_hash_stat_t |
| typedef unsigned int odb_index_t |
the type of index (node number), list are implemented through index
| typedef uint64_t odb_key_t |
the type of key.
64-bit because CG needs 32-bit pair {from,to}
| typedef odb_index_t odb_node_nr_t |
the type store node number
| typedef unsigned int odb_value_t |
the type of an information in the database
| enum odb_rw |
| int odb_add_node | ( | odb_t * | odb, | |
| odb_key_t | key, | |||
| odb_value_t | value | |||
| ) |
Add a new node w/o regarding if a node with the same key already exists.
returns EXIT_SUCCESS on success, EXIT_FAILURE on failure
References odb_t::data.
Referenced by import_from_abi(), and main().
| int odb_check_hash | ( | odb_t const * | odb | ) |
check that the hash is well built
References BUCKET_FACTOR, odb_descr_t::current_size, odb_t::data, odb_data::descr, odb_data::hash_base, odb_node_t::key, odb_node_t::next, odb_data::node_base, and odb_descr_t::size.
| void odb_close | ( | odb_t * | odb | ) |
Close the given ODB file.
References odb_data::base_memory, odb_t::data, odb_data::descr, odb_data::fd, odb_data::filename, odb_data::list, odb_data::ref_count, and odb_descr_t::size.
Referenced by main(), and opd_close_image_samples_files().
| void* odb_get_data | ( | odb_t * | odb | ) |
return the start of the mapped data
References odb_data::base_memory, and odb_t::data.
Referenced by import_from_abi(), main(), opd_open_24_sample_file(), opd_open_sample_file(), and operf_open_sample_file().
| odb_node_t* odb_get_iterator | ( | odb_t const * | odb, | |
| odb_node_nr_t * | nr | |||
| ) |
return a base pointer to the node array and number of node in this array caller then will iterate through:
odb_node_nr_t node_nr, pos; odb_node_t * node = odb_get_iterator(odb, &node_nr); for ( pos = 0 ; pos < node_nr ; ++pos) // do something
note than caller does not need to filter nil key as it's a valid key, The returned range is all valid (i.e. should never contain zero value).
References odb_descr_t::current_size, odb_t::data, odb_data::descr, and odb_data::node_base.
| int odb_grow_hashtable | ( | odb_data_t * | data | ) |
grow the hashtable in such way current_size is the index of the first free node.
Take care all node pointer can be invalidated by this call.
Node allocation is done in a two step way 1st) ensure a free node exist eventually, caller can setup it, 2nd) commit the node allocation with odb_commit_reservation(). This is done in this way to ensure node setup is visible from another process like pp tools in an atomic way.
returns 0 on success, non zero on failure in this case this function do nothing and errno is set by the first libc call failure allowing to retry after cleanup some program resource.
References odb_data::base_memory, BUCKET_FACTOR, odb_descr_t::current_size, odb_data::descr, odb_data::fd, odb_data::hash_base, odb_data::hash_mask, odb_node_t::key, odb_node_t::next, odb_data::node_base, and odb_descr_t::size.
| void odb_hash_display_stat | ( | odb_hash_stat_t const * | stats | ) |
| void odb_hash_free_stat | ( | odb_hash_stat_t * | stats | ) |
| odb_hash_stat_t* odb_hash_stat | ( | odb_t const * | odb | ) |
References odb_hash_stat_t::average_list_length, BUCKET_FACTOR, odb_descr_t::current_size, odb_t::data, odb_data::descr, odb_data::hash_base, odb_hash_stat_t::hash_table_size, odb_hash_stat_t::max_list_length, odb_node_t::next, odb_data::node_base, odb_hash_stat_t::node_nr, odb_descr_t::size, odb_hash_stat_t::total_count, odb_hash_stat_t::used_node_nr, and odb_node_t::value.
| void odb_init | ( | odb_t * | odb | ) |
odb_init - initialize a DB file
| odb | the DB file to init |
References odb_t::data.
Referenced by opd_open_24_sample_file(), operf_sfile_dup(), and sfile_dup().
References odb_data::base_memory, BUCKET_FACTOR, odb_descr_t::current_size, odb_t::data, DEFAULT_NODE_NR, odb_data::descr, odb_data::fd, odb_data::filename, odb_data::hash_base, odb_data::hash_mask, odb_data::list, odb_data::node_base, ODB_RDONLY, ODB_RDWR, odb_data::offset_node, op_hash_string(), odb_data::ref_count, odb_descr_t::size, and odb_data::sizeof_header.
Referenced by main(), opd_open_24_sample_file(), opd_open_sample_file(), and operf_open_sample_file().
| int odb_open_count | ( | odb_t const * | odb | ) |
return the number of times this sample file is open
References odb_t::data, and odb_data::ref_count.
Referenced by opd_put_image_sample().
| void odb_sync | ( | odb_t const * | odb | ) |
issue a msync on the used size of the mmaped file
References odb_data::base_memory, odb_t::data, odb_data::descr, and odb_descr_t::size.
Referenced by opd_sync_samples_files().
update info at key by incrementing its associated value by one, if the key does not exist a new node is created and the value associated is set to one.
returns EXIT_SUCCESS on success, EXIT_FAILURE on failure
References odb_update_node_with_offset().
Referenced by opd_put_image_sample(), and operf_sfile_log_arc().
odb_update_node_with_offset
| odb | the data base object to setup | |
| key | the hash key | |
| offset | the offset to be added |
update info at key by adding the specified offset to its associated value, if the key does not exist a new node is created and the value associated is set to offset.
returns EXIT_SUCCESS on success, EXIT_FAILURE on failure
References odb_t::data, odb_data::hash_base, odb_node_t::key, odb_node_t::next, odb_data::node_base, and odb_node_t::value.
Referenced by odb_update_node(), operf_sfile_log_sample_count(), and sfile_log_sample_count().
1.6.1