The idtable provides a automatically growing table which can resolve ids to values very fast. The ids are issues by the table and internally refer to an array row in the table. The table starts with an initial size and if full is extended by a definable number of rows. Initial size and extend size are internally rounded up to a multiple of 32. There is no limitation to the value and is can be queried whether a given id is in use.
You can also request special id/value combinations, but you need to keep in mind that the ids are row numbers. The table is then automatically grown to contain the requested id, but you can't shrink it later, because that would mean that the row numbers change and the ids already issued would become invalid.
If the application needs to shrink a table, I suggest creating a new table and request the needed number of ids from that. Of course all ids currently in use by the application must be updated. Once that is done, flush and destroy the old table.
#include "common.h"
Go to the source code of this file.
Typedefs | |
| typedef idtable | idtable_t |
Functions | |
| idtable_t * | idtable_new (void) |
| Allocate new id table. | |
| void | idtable_destroy (idtable_t *table) |
| Free all memory occupied by this table. | |
| guint | idtable_ids (idtable_t *tbl) |
| guint32 | idtable_new_id (idtable_t *tbl, gpointer value) |
| Get a id for the given value. | |
| void | idtable_free_id (idtable_t *tbl, guint32 id) |
| Mark this id as unused. | |
| gboolean | idtable_is_id_used (const idtable_t *tbl, guint32 id) |
| void | idtable_set_value (idtable_t *tbl, guint32 id, gpointer value) |
| Replace the value of a give id. | |
| gpointer | idtable_get_value (const idtable_t *tbl, guint32 id) |
| Fetch the value associated with the given id. | |
|
|
|
|
|
Free all memory occupied by this table. The table must not be used again after idtable_destroy call called on it. |
|
||||||||||||
|
Mark this id as unused. It will eventually be reissued. |
|
||||||||||||
|
Fetch the value associated with the given id. The id must have been requested with idtable_request_id before and must not be accessed after it has been dropped by idtable_drop_id. |
|
|
|
|
||||||||||||
|
|
|
|
Allocate new id table.
|
|
||||||||||||
|
Get a id for the given value. The id can be used to look up the value later. |
|
||||||||||||||||
|
Replace the value of a give id. The id must already be in use. |
1.3.9.1