Program Listing for File darray.h
↰ Return to documentation for file (rcsw/ds/darray.h
)
#pragma once
/*******************************************************************************
* Includes
******************************************************************************/
#include "rcsw/ds/ds.h"
#include "rcsw/ds/iter.h"
#include "rcsw/algorithm/sort.h"
#include "rcsw/common/fpc.h"
/*******************************************************************************
* Structure Definitions
******************************************************************************/
struct darray_params {
int (*cmpe)(const void *const e1, const void *const e2);
void (*printe)(const void *e);
dptr_t *elements;
size_t elt_size;
int max_elts;
uint32_t flags;
size_t init_size;
};
struct darray {
uint8_t *elements;
struct ds_iterator iter;
size_t current;
size_t capacity;
size_t elt_size;
bool_t sorted;
int max_elts;
uint32_t flags;
int (*cmpe)(const void *const e1, const void *const e2);
void (*printe)(const void *e);
};
/*******************************************************************************
* API Functions
******************************************************************************/
BEGIN_C_DECLS
static inline bool_t darray_isfull(const struct darray* const arr) {
RCSW_FPC_NV(false, NULL != arr);
return (arr->current == (size_t)arr->max_elts);
}
static inline bool_t darray_isempty(const struct darray* const arr) {
RCSW_FPC_NV(false, NULL != arr);
return arr->current == 0;
}
static inline size_t darray_size(const struct darray* const arr) {
RCSW_FPC_NV(0, NULL != arr);
return arr->current;
}
static inline size_t darray_capacity(const struct darray* const arr) {
RCSW_FPC_NV(0, NULL != arr);
return arr->capacity;
}
static inline status_t darray_set_size(struct darray* const arr,
size_t n_elts) {
RCSW_FPC_NV(ERROR, NULL != arr, n_elts <= arr->capacity);
arr->current = n_elts;
return OK;
}
static inline size_t darray_element_space(size_t max_elts, size_t elt_size) {
return ds_elt_space_simple(max_elts, elt_size);
}
RCSW_API struct darray *darray_init(struct darray *arr_in,
const struct darray_params * params) RCSW_WUR;
RCSW_API void darray_destroy(struct darray *arr);
RCSW_API status_t darray_clear(struct darray * arr);
RCSW_API status_t darray_data_clear(struct darray * arr);
RCSW_API status_t darray_insert(struct darray * arr, const void * e,
size_t index);
RCSW_API status_t darray_remove(struct darray * arr, void * e, size_t index);
RCSW_API status_t darray_idx_serve(const struct darray * arr, void * e,
size_t index);
RCSW_API int darray_idx_query(const struct darray * arr, const void * e);
RCSW_API void *darray_data_get(const struct darray * arr, size_t index);
RCSW_API status_t darray_data_set(const struct darray* arr, size_t index,
const void* e);
RCSW_API status_t darray_resize(struct darray * arr, size_t size);
RCSW_API status_t darray_data_copy(const struct darray* arr1,
const struct darray* arr2);
RCSW_API status_t darray_sort(struct darray * arr, enum exec_type type);
RCSW_API status_t darray_map(struct darray *arr, void (*f)(void *e));
RCSW_API status_t darray_inject(const struct darray * arr,
void (*f)(void *e, void *res),
void *result);
RCSW_API struct darray *darray_filter(struct darray * arr,
bool_t (*pred)(const void * e),
uint32_t flags,
void* elements);
RCSW_API struct darray *darray_copy(const struct darray * arr,
uint32_t flags,
void* elements);
RCSW_API void darray_print(const struct darray * arr);
END_C_DECLS