26#ifndef TOMMY_ARRAYBLKOF_H
27#define TOMMY_ARRAYBLKOF_H
40#define TOMMY_ARRAYBLKOF_BIT 6
45#define TOMMY_ARRAYBLKOF_SIZE (4 * 1024)
89 if (size > array->
count) {
134 assert(pos < array->count);
147 assert(array->
count != 0);
174 assert(array->
count != 0);
191 return array->
count == 0;
Array container type.
Definition: tommyarrayblkof.h:51
unsigned char ** block
Directory of blocks.
Definition: tommyarrayblkof.h:52
tommy_size_t element_size
Size of the stored element in bytes.
Definition: tommyarrayblkof.h:55
tommy_size_t count
Number of initialized elements in the array.
Definition: tommyarrayblkof.h:56
tommy_size_t block_count
Number of allocated blocks.
Definition: tommyarrayblkof.h:53
tommy_size_t block_capacity
Number of directory entries allocated.
Definition: tommyarrayblkof.h:54
TOMMY_API tommy_size_t tommy_arrayblkof_memory_usage(const tommy_arrayblkof *array)
Gets the size of allocated memory.
#define TOMMY_ARRAYBLKOF_SIZE
Elements for each block.
Definition: tommyarrayblkof.h:45
TOMMY_API void tommy_arrayblkof_shrink(tommy_arrayblkof *array)
Releases unused allocated memory.
TOMMY_API void tommy_arrayblkof_foreach_arg(tommy_arrayblkof *array, tommy_foreach_arg_func *func, void *arg)
Calls the specified function with an argument for each element in the array.
void tommy_arrayblkof_remove_tail(tommy_arrayblkof *array)
Removes the last element without copying it.
Definition: tommyarrayblkof.h:172
void * tommy_arrayblkof_ref(tommy_arrayblkof *array, tommy_size_t pos)
Gets a reference to the element at the specified position.
Definition: tommyarrayblkof.h:132
TOMMY_API void tommy_arrayblkof_foreach(tommy_arrayblkof *array, tommy_foreach_func *func)
Calls the specified function for each element in the array.
tommy_size_t tommy_arrayblkof_capacity(const tommy_arrayblkof *array)
Gets the number of elements that fit without further allocation.
Definition: tommyarrayblkof.h:209
TOMMY_API void tommy_arrayblkof_done(tommy_arrayblkof *array)
Deinitializes the array.
void * tommy_arrayblkof_tail(tommy_arrayblkof *array)
Gets a reference to the last element.
Definition: tommyarrayblkof.h:145
tommy_bool_t tommy_arrayblkof_empty(const tommy_arrayblkof *array)
Checks whether the array is empty.
Definition: tommyarrayblkof.h:189
void * tommy_arrayblkof_insert_tail(tommy_arrayblkof *array)
Adds a zero-initialized element and returns its reference.
Definition: tommyarrayblkof.h:156
void tommy_arrayblkof_clear(tommy_arrayblkof *array)
Removes all elements, preserving the allocated capacity.
Definition: tommyarrayblkof.h:112
TOMMY_API void tommy_arrayblkof_reserve(tommy_arrayblkof *array, tommy_size_t size)
Allocates space for at least the specified number of elements.
void tommy_arrayblkof_swap(tommy_arrayblkof *first, tommy_arrayblkof *second)
Exchanges two initialized arrays without copying their elements.
Definition: tommyarrayblkof.h:222
void tommy_arrayblkof_grow(tommy_arrayblkof *array, tommy_size_t size)
Grows the size up to the specified value.
Definition: tommyarrayblkof.h:87
tommy_size_t tommy_arrayblkof_size(const tommy_arrayblkof *array)
Gets the initialized size of the array.
Definition: tommyarrayblkof.h:199
TOMMY_API void tommy_arrayblkof_init(tommy_arrayblkof *array, tommy_size_t element_size)
Initializes the array.
struct tommy_arrayblkof_struct tommy_arrayblkof
Array container type.
TOMMY_API void tommy_arrayblkof_resize(tommy_arrayblkof *array, tommy_size_t size)
Changes the initialized size, preserving the common prefix.
void tommy_foreach_func(void *elem)
Foreach function.
Definition: tommytypes.h:346
uint64_t tommy_size_t
Generic size_t type.
Definition: tommytypes.h:40
void tommy_foreach_arg_func(void *arg, void *elem)
Foreach function with an argument.
Definition: tommytypes.h:353
int tommy_bool_t
Generic boolean type.
Definition: tommytypes.h:53