2.6 Creation and Destruction |
This section describes the functions that create and destroy tables.
8. <Table creation function prototypes 8> = /* Table functions. */ struct tbl_table *tbl_create (tbl_comparison_func *, void *,
struct libavl_allocator *); struct tbl_table *tbl_copy (const struct tbl_table *, tbl_copy_func *, tbl_item_func *, struct libavl_allocator *); void tbl_destroy (struct tbl_table *, tbl_item_func *);
This code is included in 15.
If a tbl_copy_func is provided, then it is used to make a copy of each table item as it is inserted into the new table, in no particular order (a deep copy (see deep copy)). Otherwise, the void * table items are copied verbatim (a shallow copy (see shallow copy)).
If the table copy fails, either due to memory allocation failure or a null pointer returned by the tbl_copy_func, tbl_copy() returns a null pointer. In this case, any provided tbl_item_func is called once for each new item already copied, in no particular order.
By default, the new table uses the same memory allocator as the existing one. If non-null, the struct libavl_allocator * given is used instead as the new memory allocator. To use the tbl_allocator_default allocator, specify &tbl_allocator_default explicitly.