maug
Quick and dirty C mini-augmentation library.
|
Structure for storing a linear and compact array of values. More...
Data Structures | |
struct | MDATA_VECTOR |
A vector of uniformly-sized objects, stored contiguously. More... | |
Macros | |
#define | MDATA_VECTOR_FLAG_REFCOUNT 0x01 |
Flag for MDATA_VECTOR::flags indicating that vector may uses reference counting for locking. | |
#define | MDATA_VECTOR_FLAG_IS_LOCKED 0x02 |
#define | MDATA_VECTOR_INIT_STEP_SZ 10 |
Default initial value for MDATA_VECTOR::ct_step. | |
#define | mdata_vector_lock(v) |
Lock the vector. This should be done when items from the vector are actively being referenced, so the system is not allowed to move the vector's data allocation block. | |
#define | mdata_vector_unlock(v) |
Unlock the vector so items may be added and removed. | |
#define | mdata_vector_get(v, idx, type) |
#define | mdata_vector_get_last(v, type) |
#define | mdata_vector_remove_last(v) |
#define | mdata_vector_set_ct_step(v, step) |
#define | mdata_vector_ct(v) |
Number of items of MDATA_VECTOR::item_sz bytes actively stored in this vector. | |
#define | mdata_vector_sz(v) |
Number of bytes of heap memory occupied by this vector. | |
#define | mdata_vector_fill(v, ct_new, sz) |
Allocate and mark the new slots as active. | |
#define | mdata_vector_is_locked(v) |
#define | mdata_vector_insert_sort(v, i, t, field) |
#define | mdata_vector_sort(v, t, field) |
#define | _mdata_vector_item_ptr(v, idx) |
#define | mdata_vector_set_flag(v, flag) |
#define | mdata_vector_get_flag(v, flag) |
Functions | |
ssize_t | mdata_vector_insert (struct MDATA_VECTOR *v, const void *item, ssize_t idx, size_t item_sz) |
MERROR_RETVAL | mdata_vector_copy (struct MDATA_VECTOR *v_dest, struct MDATA_VECTOR *v_src) |
MERROR_RETVAL | mdata_vector_alloc (struct MDATA_VECTOR *v, size_t item_sz, size_t item_ct_init) |
void | mdata_vector_free (struct MDATA_VECTOR *v) |
ssize_t | mdata_vector_append (struct MDATA_VECTOR *v, const void *item, size_t item_sz) |
Append an item to the specified vector. | |
MERROR_RETVAL | mdata_vector_remove (struct MDATA_VECTOR *v, size_t idx) |
Remove item at the given index, shifting subsequent items up by 1. | |
void * | mdata_vector_get_void (const struct MDATA_VECTOR *v, size_t idx) |
Get a generic pointer to an item in the MDATA_VECTOR. | |
Structure for storing a linear and compact array of values.
#define _mdata_vector_item_ptr | ( | v, | |
idx ) |
|
Number of items of MDATA_VECTOR::item_sz bytes actively stored in this vector.
|
Allocate and mark the new slots as active.
|
Flag for MDATA_VECTOR::flags indicating that vector may uses reference counting for locking.
Such a mobile may be locked multiple times, but then must be unlocked an equal number of times to unlock.
#define mdata_vector_get | ( | v, | |
idx, | |||
type ) |
#define mdata_vector_get_flag | ( | v, | |
flag ) |
#define mdata_vector_get_last | ( | v, | |
type ) |
#define mdata_vector_is_locked | ( | v | ) |
|
Lock the vector. This should be done when items from the vector are actively being referenced, so the system is not allowed to move the vector's data allocation block.
#define mdata_vector_remove_last | ( | v | ) |
#define mdata_vector_set_ct_step | ( | v, | |
step ) |
#define mdata_vector_set_flag | ( | v, | |
flag ) |
|
Number of bytes of heap memory occupied by this vector.
|
Unlock the vector so items may be added and removed.
MERROR_RETVAL mdata_vector_alloc | ( | struct MDATA_VECTOR * | v, |
size_t | item_sz, | ||
size_t | item_ct_init ) |
|
Append an item to the specified vector.
v | The vector to append to. |
item | The address of an item to copy to the newly-created vector slow, or NULL to not copy anything. |
item_sz | Size (in bytes) of the item to append. If the item is sized differently from the first item appended, MERROR_OVERFLOW will be returned and the item will not be appended. |
|
Get a generic pointer to an item in the MDATA_VECTOR.
v | Vector to request the item from. Should be locked! |
idx | Index of item to retrieve. |
|
Remove item at the given index, shifting subsequent items up by 1.