dynamic_array.h v0.3.1
Reference-counted dynamic arrays for C
Loading...
Searching...
No Matches
Functions
Builder Modification

Functions for adding elements to builders. More...

Functions

DA_DEF void da_builder_append (da_builder builder, const void *element)
 Appends an element to the builder.
 
DA_DEF void da_builder_reserve (da_builder builder, int new_capacity)
 Ensures the builder has at least the specified capacity.
 
DA_DEF void da_builder_append_array (da_builder builder, da_array arr)
 Appends all elements from an array to the builder.
 

Detailed Description

Functions for adding elements to builders.

Function Documentation

◆ da_builder_append()

DA_DEF void da_builder_append ( da_builder  builder,
const void *  element 
)

Appends an element to the builder.

Parameters
builderBuilder to modify (must not be NULL)
elementPointer to element data to copy (must not be NULL)
Note
Always uses doubling growth strategy for fast construction
Asserts on allocation failure or NULL parameters
Much faster than da_push() for bulk construction
int value = 42;
da_builder_append(builder, &value);
#define DA_BUILDER_CREATE(T)
Type-safe builder creation.
Definition dynamic_array.h:1423
DA_DEF void da_builder_append(da_builder builder, const void *element)
Appends an element to the builder.
Definition dynamic_array.h:1859
ArrayBuffer-style builder for efficient array construction.
Definition dynamic_array.h:208

◆ da_builder_append_array()

DA_DEF void da_builder_append_array ( da_builder  builder,
da_array  arr 
)

Appends all elements from an array to the builder.

Parameters
builderBuilder to modify (must not be NULL)
arrSource array to append from (must not be NULL)
Note
Automatically grows builder capacity if needed
Source array is unchanged
Arrays must have the same element_size
More efficient than multiple da_builder_append() calls
Asserts on allocation failure or mismatched element sizes
da_array source = DA_CREATE(int, 3); // [10, 20, 30]
da_builder_append_array(builder, source); // Builder now contains [10, 20, 30]
#define DA_CREATE(T, cap, retain_fn, release_fn)
Type-safe array creation.
Definition dynamic_array.h:1245
DA_DEF void da_builder_append_array(da_builder builder, da_array arr)
Appends all elements from an array to the builder.
Definition dynamic_array.h:1886
Reference-counted dynamic array structure.
Definition dynamic_array.h:192

◆ da_builder_reserve()

DA_DEF void da_builder_reserve ( da_builder  builder,
int  new_capacity 
)

Ensures the builder has at least the specified capacity.

Parameters
builderBuilder to modify (must not be NULL)
new_capacityMinimum capacity required (must be >= 0)
Note
Only increases capacity, never decreases
Asserts on allocation failure
Useful for avoiding multiple reallocations when size is known
Builders always use doubling growth strategy
da_builder_reserve(builder, 1000); // Ensure space for 1000 elements
for (int i = 0; i < 1000; i++) {
DA_BUILDER_APPEND(builder, i); // No reallocations needed
}
#define DA_BUILDER_APPEND(builder, val, T)
Type-safe element append to builder (adaptive macro)
Definition dynamic_array.h:1439
DA_DEF void da_builder_reserve(da_builder builder, int new_capacity)
Ensures the builder has at least the specified capacity.
Definition dynamic_array.h:1875