15#ifndef TOMMY_ARRAYBLK_H
16#define TOMMY_ARRAYBLK_H
28#define TOMMY_ARRAYBLK_BIT 6
33#define TOMMY_ARRAYBLK_SIZE (4 * 1024)
75 if (size > array->
count) {
121 assert(pos < array->count);
160 assert(array->
count != 0);
189 assert(array->
count != 0);
193 void* element = *ptr;
209 return array->
count == 0;
Array container type.
Definition: tommyarrayblk.h:39
tommy_size_t block_count
Number of allocated blocks.
Definition: tommyarrayblk.h:41
tommy_size_t count
Number of initialized elements in the array.
Definition: tommyarrayblk.h:43
tommy_size_t block_capacity
Number of directory entries allocated.
Definition: tommyarrayblk.h:42
void *** block
Directory of blocks.
Definition: tommyarrayblk.h:40
void * tommy_arrayblk_remove_tail(tommy_arrayblk *array)
Removes and returns the last element.
Definition: tommyarrayblk.h:187
tommy_size_t tommy_arrayblk_size(const tommy_arrayblk *array)
Gets the initialized size of the array.
Definition: tommyarrayblk.h:217
void tommy_arrayblk_grow(tommy_arrayblk *array, tommy_size_t size)
Grows the size up to the specified value.
Definition: tommyarrayblk.h:73
tommy_bool_t tommy_arrayblk_empty(const tommy_arrayblk *array)
Checks whether the array is empty.
Definition: tommyarrayblk.h:207
TOMMY_API void tommy_arrayblk_done(tommy_arrayblk *array)
Deinitializes the array.
struct tommy_arrayblk_struct tommy_arrayblk
Array container type.
void tommy_arrayblk_insert_tail(tommy_arrayblk *array, void *element)
Grows and inserts a new element at the end of the array.
Definition: tommyarrayblk.h:169
void ** tommy_arrayblk_ref(tommy_arrayblk *array, tommy_size_t pos)
Gets a reference to the element at the specified position.
Definition: tommyarrayblk.h:119
TOMMY_API void tommy_arrayblk_foreach(tommy_arrayblk *array, tommy_foreach_func *func)
Calls the specified function for each element in the array.
TOMMY_API tommy_size_t tommy_arrayblk_memory_usage(const tommy_arrayblk *array)
Gets the size of allocated memory.
void * tommy_arrayblk_get(tommy_arrayblk *array, tommy_size_t pos)
Gets the element at the specified position.
Definition: tommyarrayblk.h:147
TOMMY_API void tommy_arrayblk_shrink(tommy_arrayblk *array)
Releases unused allocated memory.
TOMMY_API void tommy_arrayblk_resize(tommy_arrayblk *array, tommy_size_t size)
Changes the initialized size, preserving the common prefix.
void tommy_arrayblk_swap(tommy_arrayblk *first, tommy_arrayblk *second)
Exchanges two initialized arrays without copying their elements.
Definition: tommyarrayblk.h:240
void tommy_arrayblk_clear(tommy_arrayblk *array)
Removes all elements, preserving the allocated capacity.
Definition: tommyarrayblk.h:99
tommy_size_t tommy_arrayblk_capacity(const tommy_arrayblk *array)
Gets the number of elements that fit without further allocation.
Definition: tommyarrayblk.h:227
TOMMY_API void tommy_arrayblk_init(tommy_arrayblk *array)
Initializes the array.
void tommy_arrayblk_set(tommy_arrayblk *array, tommy_size_t pos, void *element)
Sets the element at the specified position.
Definition: tommyarrayblk.h:134
TOMMY_API void tommy_arrayblk_foreach_arg(tommy_arrayblk *array, tommy_foreach_arg_func *func, void *arg)
Calls the specified function with an argument for each element in the array.
TOMMY_API void tommy_arrayblk_reserve(tommy_arrayblk *array, tommy_size_t size)
Allocates space for at least the specified number of elements.
#define TOMMY_ARRAYBLK_SIZE
Elements for each block.
Definition: tommyarrayblk.h:33
void * tommy_arrayblk_tail(tommy_arrayblk *array)
Gets the last element.
Definition: tommyarrayblk.h:158
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